# How to force LaTeX only commands?

Recently, I learned that for a long time I have been doing all of my mathematics in LaTeX incorrectly!

I was using the $ TeX commands instead of the $$ and $$ LaTeX commands! I immediately went back and fixed my error, but it got me wondering, is there a way to make the LaTeX compiler and TexStudio (Or another editor) not use the TeX commands in order to preserve proper typesetting? Furthermore, would it possible to write a macro to automatically make the $ signs into the respective $$ and $$? I've tried


I'd go even further than @egreg does in his comment and state that not only is using $ to start and end inline math mode not wrong, it has certain advantages over $$ and $$. Consider the following MWE: \documentclass{article} \begin{document} \tableofcontents \section{$$1+1=2$$} \end{document}  If you compile it twice, you'll get the following, not particularly enlightening error message: > LaTeX Error: Bad math environment delimiter.  The reason one gets this error message is that $$ and $$ are not "robust" (in the TeX/LaTeX sense of the word), which trips up the LaTeX code that generates the table of contents. To avoid getting this error message, you could type \section{\protect$$1+1=2\protect$$}  but I dare-say that you'll soon decide it's preferable to write \section{$1+1=2$}  Addendum: It may be instructive to examine how $$ and $$ are defined in the LaTeX kernel (see, e.g, the file latex.ltx): \def$${\relax\ifmmode\@badmath\else\fi} \def$${\relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}


where \@badmath is defined as

\gdef\@badmath{\@latex@error{Bad math environment delimiter}\@eha}


Thus, $$ and $$ both eventually invoke $, with some error checking thrown in: $$ throws an error if it's encountered while already in math mode, and $$ generates an error if it's encountered while not in so-called "inner" math mode. In practice, unless the macros $$ and $$ are made robust in the LaTeX sense of the word (e.g., by loading the package fixltx2e), using them may lead to other error messages -- see the example above -- that are just as confusing as those that tend to arise when $ is used incorrectly.

• $$ is also fixed if you \usepackage{fixltx2e} (which is a good idea in any case) – David Carlisle Dec 3 '13 at 21:57 • – clemens Dec 3 '13 at 22:16 • @mrc - See the answers to the posting Are ( and ) preferable to dollar signs for math mode?. Joseph Wright suggests that if it's necessary to hook into some external code, using \( and $$ is preferable to $. On the other hand, other comments note that use of $ makes the source code more easily legible to humans. – Mico Dec 3 '13 at 22:21
• No \$ is correct input, the intended advantage of $$ is you get better error diagnostics if they are mis-matched, but having them fragile rather spoils that as it introduces more errors than it improves:-) – David Carlisle Dec 3 '13 at 22:30 • @Manuel yes. KOMA-Script does not make any changes to \( and $$ nor does it load fixltx2e. (It does other things from fixltx2e like defining \textsubscript`, though) – clemens Dec 3 '13 at 22:55