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.
$$
) is still "active".