# Are $$and$$ preferable to dollar signs for math mode?

Along the lines of Why is $...$ preferable to $$...$$?, what reasons are there (if any) to favor $$...$$ over $...$?

• for whatever it's worth, i remember hearing knuth say that if he were creating tex all over again, he wouldn't use a "toggle" approach for math mode, but would use a clean begin/end notation. i'm pretty sure that this question was asked in a q&a session, all of which are republished in his book Digital Typography (the ones held before that book was published, of course). Oct 8, 2011 at 19:13
• I once used  to temporarily exit math mode inside a mathematical environment. Don't remember when, and a regexp to find this in my files would be very difficult to imagine. Dec 3, 2013 at 22:47
• It should be more symmetric!!! I am in favor of $$...)\, so it would be symmetric. Or even \(...)/... not only symmetric, but very emoji like!!! Nov 23, 2019 at 12:28 • @user2987828 A cleaner way to do that, as you know, would be \text from amsmath. Jun 4, 2020 at 4:16 ## 10 Answers \( ...$$ is LaTeX syntax. $...$ is TeX syntax.

plainTeX only allows $. In LaTeX you can use both, but $$...$$ will give less obscure error messages when there is a mistake inside it. Both are shortcuts to start inline math environments. • $$...$$ shouldn't render differently from$ ... $, although you are right about the checking. The fact that it's possible to 'hook into' $$...$$ (but not$ ... $) means that I'd favour the LaTeX syntax. Jul 28, 2010 at 19:52 • I'd note with my 'LaTeX3' hat on that there is a strong chance we'll favour \ ( ... \ ) to the point of not supporting $ ... $ for LaTeX3. So in the long term it might be best to get used to \ ( ... \ ). Aug 17, 2010 at 20:35 • @Joseph obviously our 2 'LaTeX3' hats have something different under the bonnet then ;-). I'm a strong advocate for providing $...$ as syntax for in-line math. There aren't really any disadvantages in that and the syntax is simply far more readable, e.g., $$a$$ to $a$. Displaymath is a different story and there are good reasons for not supporting the plain TeX syntax there. Jan 16, 2012 at 13:01 • @FrankMittelbach I 100% agree with you. $a$ is better-to-read, not speaking about $f(x)=(x+1)/2$and$g(x)=(x-1)^{1+x}$are$(n+1)$-free compared to $$f(x)=(x+1)/2$$ and $$g(x)=(x-1)^{1+x}$$$ are $$(n+1)$$-free. Too many (s and {s is simply too many. Dollar is well-recognizable in the code and to be honest, I have never got into the problem of not-knowing whether I'm in or out of $...$.
– yo'
Feb 3, 2012 at 15:46
• "$math$" is much much easier to write and also read. I do not understand how anyone can think that forcing us to use "$$math$$" will make Latex "better" for the end users. With "$$....$$" one also can get them mixed up. Please keep the option to use "$math$". Latex is hard enough without adding more ((( ))) to it. May 4, 2013 at 5:46

Anyone who's ever tried writing a simple perl (or whatever) script to quickly parse a LaTeX document and do something in maths mode but not in text mode will agree that $$..$$ is the only way to go! Trying to get the pattern matching right against $a^2 + b^2$$c^2 + d^2 is a nightmare. (Before anyone asks, yes I have, and it's called mathgrep. The pain and agony of writing that convinced me more than anything else of the value of making everything a configurable macro so it can be easily changed later.) Another reason: looking at the code, $$ and $$ actually checks that TeX is in the right mode before starting. So hello $$world \(can$$ we\) have some tea? will produce an error, whereas hello world can we have some tea? will not. • Andrew, I must be the exception that proves the rule. I heavily pre-process almost all my LaTeX input through sed which, as you probably know, uses $$ and $$ for \1, \2, \3... group back-substitution. Just the mere thought of writing and maintaining sed regexp's the "LaTeX-preferred" way sends waves of shudders down my spine!! :)) Aug 23, 2010 at 12:34 • From a purely progrmatic point of view I agree that ...is slightly less preferable because, as you pointed out, there is no way to automatically identify start and end tokens. However, from a practical point of inputting manuscripts and reading them I still maintain that the plain TeX syntax is superior and in my opinion outweights that disadvantage in this case. Jan 16, 2012 at 18:07 • @GeoffreyJones said it! How can LaTeX decisions be made based on which external program users may or may not use for purposes that may or may not be directly related to LaTeX? Don't you think then the reasoning becomes more and more counterintuitive as well as counterproductive? – Amar May 30, 2015 at 14:48 • The link math.ntnu.no/~stacey/HowDidIDoThat/LaTeX/mathgrep.html is dead. Oct 27, 2016 at 21:27 Interestingly, nobody mentioned that the mathtools package has a very nice feature of adding italic correction in some places at the boundary between text and math mode (see its documentation for details, but aesthetically this really matters!), and this feature works only with $$...$$. The first line is with correction, the second without. • @mbork: Hmm, I'm not really happy with mathtools in that respect - see the comments to this answer. Jun 9, 2012 at 18:44 It is instructive to examine the exact definitions of $$ and $$ that are provided by the LaTeX kernel (contained in the file latex.ltx), version early 2016: \DeclareRobustCommand$${% \relax\ifmmode\@badmath\else\fi}% \DeclareRobustCommand$${% \relax\ifmmode\ifinner\else\@badmath\fi\else\@badmath\fi}%  The main thing to note is that $$ and $$ act as "wrappers" around the "" token: • $$ checks first if it occurs in ("inner" or "outer") math mode. If that's the case, it issues an error message, viz., "LaTeX Error: Bad math environment delimiter", as it can't be correct to initiate inline math mode if TeX is already in math mode. If it's not the case, i.e. if \( is encountered while TeX is not in math mode, a single  token is inserted and TeX's inline math mode is thereby entered. • Likewise, $$ checks first if it occurs in "inner" math mode. If that's not the case, i.e., if TeX is either in "outer" math mode or not in math mode at all, a "LaTeX Error: Bad math environment delimiter" error message is generated. If, on the other hand, TeX is in inner math mode, a single  token is generated and inline math mode is thereby terminated. Moreover, observe that both $$ and $$ are declared to be "robust". This means, inter alia, that both macros can be used inside "moving" arguments, e.g., inside the arguments of sectioning commands and \captions. (Aside: Robustness of these two macros was not the default in versions of the LaTeX kernel prior to 2015, necessitating the loading of the fixltx2e package -- which is something, I think is fair to say, few people ever did...) Do these observations imply that using $$...$$ is preferable to typing  ... ? Not necessarily! First, the LaTeX error message one gets from typing (say) \[a\) -- "! LaTeX Error: Bad math environment delimiter." -- is not necessarily more informative or helpful than the TeX error message that results from typing \[a -- "! Display math should end with$$." Second, if your inline math expressions contain a lot of opening and closing round parentheses, i.e., ( and ), the presence of $$ and $$ can be quite distracting if one needs to debug an inline equation and locate where an opening or closing parenthesis may be missing. Separately, depending on the exact layout of your keyboard, typing $$ and $$ may also entail (marginally) more effort than typing $ does. Of course, the input effort will also depend importantly on the editor that's being used.

• I like this answer the best, because actually the "benefits" of $$...$$ over $...$ are marginal, and probably depend on the user. For example, being amenable to perl script (and other regular expression checking) will be important for some, whereas the readability of the LaTeX source will be important for others. Sep 22, 2021 at 13:34

There are some good 'meta' reasons for using $$...$$ in some circumstances. Environments such as Fancy Verbatim and alltt will allow $$ and $$ to act as math mode, but $will be interpreted as a literal. Another convenience is that some editors have an easier time with pair matching $$...$$ than $.

• Fancy verbatim can be configured easily to accept $ as a trigger for math mode. Sep 7, 2010 at 12:04 • Other editors pair match and highlight$...$, but not (...), e.g., the default emacs tex mode. (Auctex supports both, though.) – user159824 Apr 11, 2018 at 16:00 There is actually a very good reason to prefer $$...$$ over $ ... $, but it's relevant only in one specific context I can think of: If you have a macro that applies an argument like this $#1$, supplying an empty argument when using the macro (which might make, depending on the command, perfect sense) would lead to an obscure error message, whereas $$#1$$ will not. An update (thanks to a comment by @BrunoLeFloch): As the above problem can be circumvented by writing $ #1$ instead, a better way of thinking about this is the following: It is better to teach people $$...$$ than $ ... $, though technically the disadvantages of using the latter are minor and can be circumvented with enough knowledge. Teaching people the former means that they need to pay attention to at least one fewer trap caused by the fact that TeX practically treats both $ and $$ as tokens. • You could use  #1 to keep the plain TeX notation without the odd error message. Jul 14, 2012 at 19:54 • What do you mean by the final emphasized sentence? Jul 23, 2012 at 6:46 • That if I teach people about $$...$$, those people (under the naive assumption that they will use only what they've been taught) will not use  ...  and thus don't make the mistake I've described in my answer's first paragraph (namely, the mistake of supplying an empty argument to a macro that uses #1). As @BrunoLeFloch has pointed out, this can be circumvented easily, but a user will do this only if he is aware of the fact that $$ in TeX is practically treated like a single token and not as a sequence of two $-tokens. ... Jul 23, 2012 at 7:02 • ... But a user who has never heard of $ ... $ (in practice a bad assumption, admittedly) won't need to know this, because he'll (theoretically) never use $ ... $. So I only need to teach him "use $$...$$" instead of "you may $ ... $ but avoid accidentally creating the character sequence $$". So, overall one fewer piece of knowledge to teach. Jul 23, 2012 at 7:04 Configuring $$ and $$ for inline math tags in MathJax is beneficial as you don't need to escape $ in your HTML contents.

Note: MathJax is a javascript library to render LaTeX commands on the browser.

For users of the package soul:

The soul manual states that its macros* accept math mode within their arguments, but only if $...$ is used; i.e. $$...$$ interestingly doesn't work there.

*The manual's example is \so{foo$x^3$bar}, which uses the spacing-out macro \so, and I've tested it with the strikeout macro \st.

• Looks like a bug to me, if a LaTeX package is not compatible with LaTeX syntax. There was no fix since 2003. Mar 10, 2019 at 9:56

Here's a new answer to an old post, in which I'd like to offer the opposite view (and then duck below the parapet): I prefer $...$ and will continue to use it; furthermore, I will teach the use of both $...$ and $$...$$ so individuals can make up their own mind. Various points below have been mentioned in comments on other answers, but no answer has yet overtly flown the flag for $...$. Here, I will do that.

The most important thing is this: you're not a bad person if you use $...$. Each to their own!

So, here are my reasons for preferring $...$ over $$...$$:

• Typing $$ involves two keystrokes, whereas  involves just one. In a typical math-rich document (e.g. mathematical research articles or teaching material), you'll find that most sentences switch in and out of math mode at least once, and typically several times. A (relatively short) paper I'm working on currently contains 1,286  symbols (i.e. 643 pieces of inline maths). • LaTeX source is harder to read when you use \(...$$. As Mico points out in their answer (https://tex.stackexchange.com/a/305471/96966), this becomes especially problematic when the maths also contains parentheses.
• While $$...$$ has better error reporting, you commit fewer errors with $...$. Furthermore, errors you commit are easier to spot. This follows as a result of both of the reasons above (number of keystrokes and readability of LaTeX source).
• If $$...$$ is ever needed (e.g. for search/replace), it's easy to switch. Your correctly-compiling LaTeX document will contain an even number of $ signs. You can systematically replace each occurrence of $...$ with $$...$$ via regular expressions (and vice-versa). • Where's the love for \begin{math}\end{math}? 🤪 Sep 22, 2021 at 14:54 • @DonHosek as a Brit, I'd have to create a macro \begin{maths}...\end{maths} 🙃 Sep 22, 2021 at 16:12 • Fair. Another point: most markdown implementation uses $ for math now (pandoc, jupyter, stackexchange, etc.), so it may be better in terms of portability / workflow / use to adopt $. Sep 22, 2021 at 16:33 • +1 for bringing in the perspective of a human simply typing a document, which is not quite the same as the perspective of someone debugging a document, or someone writing scripts to parse or modify a document. Sep 22, 2021 at 21:06 • I'll admit that, despite upvoting several of the older answers and accepting one of them, none of that ever actually got me to start using $$ instead of . Now I'll duck down behind a parapet myself. Sep 22, 2021 at 21:08 While no one has mentioned it, it's best to use \( ...$$, that is because ChkTeX for automated linting recommends using it over $ ... \$`, which is a good indicator probably.