8

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

Mats
  • 553
  • 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
  • doh! Of course. I feel like an idiot now. Put it i an answer, @morbusg and I'll accept it. – Mats Nov 18 '15 at 12:07
  • @Henri and there's the reference. – Mats Nov 18 '15 at 12:09
  • 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
  • @StevenB.Segletes You got me ;) Things like these happen to me quite often. I should really practice vocabulary. – Henri Menke Nov 18 '15 at 12:58
  • 1
    @HenriMenke The beauty of Freudian slips is that they reveal a lot of truth, as well a laugh. – Steven B. Segletes Nov 18 '15 at 13:01
  • 2
    @HenriMenke -- your "nuisances" has made my day. thanks. – barbara beeton Nov 18 '15 at 14:52
  • Closely related (maybe even duplicate) question: https://tex.stackexchange.com/questions/42301/why-doesnt-tex-latex-have-reasonable-defaults-in-certain-cases – ShreevatsaR Jun 19 '17 at 22:31

1 Answers1

18

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
  • 25,490
  • 4
  • 81
  • 162