Will Robertson wrote: > On 29/01/2011, at 9:39 AM, Bruno Le Floch wrote: > >>> As this is ment for document level, I am tempted to use >>> \NewDocumentCommand. But this word is longer than the whole code of the >>> macro itself, that blows some simple code really up. On the other hand, >>> using \def would be very short but is not LaTeX3-ish. \cs_new:Nn doesn't >>> let me define something without a : at the end. Or would a \tl_new be a >>> good way? >> >> I don't know what the right way of doing things is. Two ways I can think of are >> >> \cs_new:Npn \ie {i.\,e.} >> \tl_new:Nn \ie {i.\,e.} > > > These commands are only intended to be used for actual package code. For my own (unpublished because it's insignificant) package for doing this, I use \DeclareRobustCommand since I wrote it before I was using xparse. > > But \NewDocumentCommand is probably the way to go, although it seems over the top: (after all, consider the name -- it's for creating "document commands") > > 1. You want the "newness" checking so you don't clash with some other possible definition of \ie > > 2. For this type of macro it's often desirable to have "protected" commands, so that the \ie is kept as a macro inside LaTeX2e-termed "moving arguments" such as section headings and captions. > > But a better way to do this sort of thing would be to write something like > > \NewDocumentCommand \NewShorthand { mm } {% > \NewDocumentCommand #1 {} {#2}% > } > > so you can then write > > \NewShorthand \ie {i.e.} That is not much shorter, but it is a start … > I actually think this idea of a "document shorthand" such as this, being a macro with no arguments (or perhaps with a very simple macro replacement rule -- say anything expandable that doesn't rely on counters or position in the document) should be a somewhat formal construct that we define. In fact, I think it should use a different syntax than the regular "gobble space" undelimited macro, such as the equivalent of > > \def\ie/{i.e.} > > which would be used in-text as "blah blah blah (\ie/, yar yar yar)" or "blah \ie/ yar" -- in other words, spaces are preserved after the macro. The reasoning being that (and I think I've said this before) even experienced LaTeX authors make mistakes with things like writing "The \LaTeX Companion" or whatever, and eliminating this source of error would be -- I think -- a usability improvement for people that want to use it. > > Perhaps a trailing semicolon would be a better idea; I'm not really sure what the best syntax here would be. (There is a package somewhere on CTAN that defines shorthands using @ symbols (so you'd write, like, "@ie@"), but that syntax might be a bit extreme for me.) What about adding something like \xspace automatically? Maybe with a *-version that does not? > But perhaps that's all being a bit prescriptionist, and just because I like to write like that doesn't mean we should force everyone to. DocumentCommand is still available for everyone who does not want a short version … > But besides the interface improvement with avoiding the spaces behaviour, such a "shorthand" system could also be used in post-processing to convert a document with author shorthands into an "expanded" document that doesn't require the macros. cheers Arno