I was wondering over the TeX programming language syntax. Is there a known reason why Knuth chose the backslash notation we all love and fear? It seams to me that most other contemporary languages (C, Prolog, Smalltalk, SQL) use syntaxes more alike as well as more easily read- and writeable, i.e. there was already common lexical scanning techniques around to use, not to end up with a cryptic notation. Is the reason commonly known?

Cheers

  • 7
    One obvious reason is that you are typesetting general text, so keywords such as "if" appearing in the text would need to be escaped. The operative word being "escape", for which the backslash is common. – morbusg Nov 18 '15 at 11:41
  • 4
    The backslash character occurs exceedingly rarely in typographic output. Given that is shows up anyway on (US-layout) keyboards, it would seem to be a natural candidate to be designated as the "escape" character of the programming and typesetting language. – Mico Nov 18 '15 at 12:01
  • 13
    To quote the master: “TeX allows any character to be used for escapes, but the “backslash” character ‘\’ is usually adopted for this purpose, since backslashes are reasonably convenient to type and they are rarely needed in ordinary text.” from the TeXbook, Chapter 3: Controlling TeX – Henri Menke Nov 18 '15 at 12:06
  • 4
    @Mats If you want to interact with TeX via a normal programming language, take a look at LuaTeX. It offers a Lua interface to TeX's typesetting engine. (Please note, that LuaTeX is not fully compatible to Knuth TeX in all the nuisances). – Henri Menke Nov 18 '15 at 12:12
  • 5
    @HenriMenke Was "nuisances" a Freudian slip for "nuances"? 8^b – Steven B. Segletes Nov 18 '15 at 12:43
up vote 18 down vote accepted

One obvious reason is that you are typesetting general text, so keywords such as "if" appearing in the text would need to be escaped. The operative word being "escape", for which the backslash is common.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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