9

We're implementing a system that generates TeX files from text entered into HTML forms, and a general question arose.

Quoting Donald Knuth's TeXbook:

A control sequence of the other kind, like \', is called a control symbol: it consists of the escape character followed by a single nonletter.

A colleague is sure she remembers that sometimes \" should be enclosed in braces with its following character, e.g. {\"A} to get our German Ä.

I answered with the quote by Knuth, saying that we need not worry about it, since any nutty LaTeX macros that our users may throw at our files (aside from straight redefinition like \def\"{foobar}) cannot override core TeX language, and therefore we should be safe with \".

Am I right?

  • 4
    Sorry, but you are wrong. TeX is capable of changing its own syntax completely, see xii.tex for instance. Hence \def\"{foobar} will override any previous definition of \" in the current group. – Henri Menke Oct 4 '16 at 9:41
  • 2
    However, \"A does not have to be enclosed in braces to obtain Ä. By proper LaTeX convention you should brace the argument though, i.e. \"{A}. I think you should use UTF-8 and input Ä directly. – Henri Menke Oct 4 '16 at 9:46
  • 6
    Welcome! Your colleague is right: when preparing a BibTeX file, a name such as “Müller” should be input as M{\"u}ller. However, this is a special convention only for .bib files. In LaTeX documents you type M\"{u}ller or, more simply M\"uller. – egreg Oct 4 '16 at 9:50
  • 2
    off-topic ... when placing braces around an accented letter, either as \"{a} or {\"a}, it affects (i.e. disables) kerning with adjacent letters. so if it can be avoided, that's usually a good idea. (but in the case of bibtex, it can't.) – barbara beeton Oct 4 '16 at 13:17
  • 2
    @barbarabeeton true for {\"a} not so for \"{a} which is the official latex syntax, but equivalent to \"a just on general macro argument parsing rules. – David Carlisle Oct 4 '16 at 15:12
16

Firstly \" is not a tex primitive, it is a macro defined in plain tex and also a macro with a different definition defined in latex, so it isn't that latex changes this macro it just has a different definition. (Plain TeX accents only have to work with the original 7-bit encoding of computer modern, but latex ones need to adapt to the currently specified font encoding).

The {\"a} syntax that you refer to is however unrelated to either definition, it is a convention required by bibtex to treat the construct as a single letter for sorting purposes.

But in general any macro package can redefine any tex command.

After

\let\def=\undefined

for example the tex primitive \def would no longer be available unless you saved it with an earlier

\let\saveddef=\def

or if you are using pdftex or similar extended engines that have a \primitive (or \pdfprimitive) command such that \primitive\def expands to the tex primitive even if the csname token \def has been redefined to be something else (or, as above, defined to be nothing)

  • Thanks, that sheds some light onto the inner workings of TeX/LaTeX for me! – curious_weather Oct 4 '16 at 10:15
  • Nit: I didn't know about \primitive, so I checked the pdfTeX manual. There, it appears to be named \pdfprimitive. – Harald Hanche-Olsen Oct 4 '16 at 12:31
  • 1
    @HaraldHanche-Olsen ahh I'm getting too modern in my old age (it's called \primitive in xetex and luatex) – David Carlisle Oct 4 '16 at 12:34
  • 1
    Well, it is a more sensible name, after all. The pdf prefix seems rather senseless, I think. (I haven't jumped on the xetex/luatex bandwagon yet, in my old age.) – Harald Hanche-Olsen Oct 4 '16 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.