4

As mentioned in the post below, $$...$$ should not be used in LaTeX:

Why is \[ ... \] preferable to $$ ... $$?

If $$...$$ is not to be used and \[...\] has to be used, why is $$...$$ still made available? Why cannot $$...$$ be mapped to \[...\]?

5
  • 7
    TeX is a macro expansion language, macros expand to primitives, you can not remove the primitives. You mention C, the same is true of C macros, you can define macros but you can not remove the things they expand to. Dec 2, 2014 at 22:11
  • Because LaTeX is built (as a set of macros??) atop TeX, so that the underlying TeX (which includes $$) is still "active". Dec 2, 2014 at 22:11
  • 1
    Hi! This is well explained in answer by David there: tex.stackexchange.com/a/69854/11002
    – yo'
    Dec 2, 2014 at 22:12
  • 1
    Two related questions: first and second.
    – Manuel
    Dec 2, 2014 at 22:13
  • 8
    I have edited this question to make it less inflammatory and to reduce the chances that it will die a swift death on the grounds that the only possible answers will be opinion-based. As a technical question, the issue of why-not-map seems a reasonable one deserving a reasonable answer (or a duplication link, if appropriate).
    – cfr
    Dec 2, 2014 at 22:20

2 Answers 2

15

In INITEX, $ has no predefined meaning. One of the first lines in plain.tex is

\catcode`$=3

that assigns the character its commonly used function of “math shift”. Any character could be assigned this meaning, but Knuth started with it and LaTeX followed suit.

In the considerations below, $ will mean “a character with category code 3”.

How does $ work? There are several cases to consider.

  • If TeX is in vertical mode, it starts horizontal mode and rereads the $ token.

  • If TeX is in restricted horizontal mode, it discards the $ and enters inline math mode.

  • If TeX is in (unrestricted) horizontal mode, it looks at the next token without expanding it; call it t. If t is $ then TeX enters display math mode and discards both found $ tokens. If t is not $, then TeX enters inline math mode, discards the $ token and rereads t.

  • If TeX is in display math mode, it looks for the next token without expanding it; call it t. If t is $, TeX ends display math mode (and does a whole lot of things). If t is not $, then TeX issues an error message and inserts $, which causes ending display math mode (assuming the user hits return or \errorstopmode is not in effect). Token t is reread. In both cases, horizontal mode is resumed without inserting \indent and \parskip glue.

  • If TeX is in inline math mode, it ends it (doing a whole lot of things) and resumes horizontal mode (restricted or unrestricted).

Note: there are some subtleties regarding \eqno and \leqno but are not relevant for the big picture.

You can see that $$ is somewhat hardwired in the language: it is not a primitive such as \halign or \par that we can give new meanings to at will (knowing what we're doing, of course).

When LaTeX was born, the macros \(, \), \[ and \] were provided for starting/closing inline math mode and display math mode. However, since the format was based on Plain TeX and many people were already accustomed to using $ for entering in and exiting from math mode, Leslie Lamport decided not to disable it, which would be possible by the simple instruction

\catcode`$=12

after having defined all the macros that use math mode. Why not disabling it? Because porting code from Plain TeX would have been easier. However, there's no mention of $$...$$ in the manual and for good reasons: this construction doesn't behave correctly when the fleqn option is used; math displays built with $$...$$ will be centered anyway. Not so for those built with \[...\] or the equivalent displaymath environment.

Making $$...$$ illegal would mean making illegal also $...$ for inline math mode. Not an option now, it might have been possible when LaTeX was created. Doing it now would break thousands of older documents.

Why cannot $$...$$ be mapped to \[...\]? Because of the reasons above. It could be done by making $ into an active character as my answer to Defining `$$$ $$$` to align shows. However, this breaks several other legal constructs, so it's not an option either.

There is no fanatism in advising users not to employ $$...$$; if people wants to, they're given free will and they can refrain from listening to experts. They'll probably shoot on their own foot, but it's their problem.

I'll continue to advise users not to use $$...$$. Do you want to listen to this advice? Fine. Don't you? Fine again, but if your document breaks, you're on your own.

12

The correct answer to why is $$...$$ still made available is: Because LaTeX is old. This is actually not the only thing that is deprecated; you have \bf, \it and friends, eqnarray and eqnarray*, a bunch of packages, $$...$$, etc.

Why is LaTeX not "cleaned up"? Well, first, you want at least some extent of backward compatibility. Second, you get people using the bad code; what should happen then?

Should LaTeX crash with an error: "Hey dude, you better use 2014 syntax than a 1992 one, I'm not going to support this old crap"? (Not a good idea indeed, given the amount of people who use LaTeX and are not quite good at any programming, happy that it does something which looks reasonable to them.)

Should a warning appear? (Notice that many warnings appear, and if people read them, we would have so much less work answering questions here. And especially for $$, since it's a TeX primitive and LaTeX layer has only a little control over it, it can't even issue a warning.)

So the only option left is: You keep the deprecated syntax.

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.