414

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

4
  • 52
    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). Commented Oct 8, 2011 at 19:13
  • 4
    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. Commented Dec 3, 2013 at 22:47
  • 2
    @user2987828 A cleaner way to do that, as you know, would be \text from amsmath.
    – Davislor
    Commented Jun 4, 2020 at 4:16
  • Restating tex.stackexchange.com/questions/510/… , any reason to use \begin{math}…\end{math}?
    – user282514
    Commented Mar 3, 2023 at 1:26

13 Answers 13

294

\( ... \) 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.

24
  • 98
    @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. Commented Jan 16, 2012 at 13:01
  • 7
    @FrankMittelbach I have been thinking about this issues, along with others, and suspect a more acceptable approach all round will be to actively deal with $$, either using an active-$ approach or using \everydisplay to trap 'unauthorised' use of $$ (i.e. keep $ but deal with $$).
    – Joseph Wright
    Commented Jan 16, 2012 at 14:50
  • 60
    @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'
    Commented Feb 3, 2012 at 15:46
  • 37
    "$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.
    – Nasser
    Commented May 4, 2013 at 5:46
  • 7
    @Amar $ ... $ is officially-supported LaTeX2e syntax and I do not see that changing. However, we will implement this in a different way to the present set up, not leaving $ as the primitive 'switch to math mode' token. On $$ ... $$, I don't see the advantage over \[ ... \] but that is to be determined.
    – Joseph Wright
    Commented May 30, 2015 at 15:58
88

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.

3
  • 15
    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!! :)) Commented Aug 23, 2010 at 12:34
  • 37
    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. Commented Jan 16, 2012 at 18:07
  • 7
    @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
    Commented May 30, 2015 at 14:48
55

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 \(...\).

enter image description here

The first line is with correction, the second without.

2
  • 2
    @mbork: Hmm, I'm not really happy with mathtools in that respect - see the comments to this answer. Commented Jun 9, 2012 at 18:44
  • 13
    Just for the sake of completeness, could you please post the LaTeX code which you used to typeset this?
    – user292998
    Commented Jun 5, 2023 at 14:29
48

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.

1
  • 2
    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.
    – rbrignall
    Commented Sep 22, 2021 at 13:34
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 $.

2
  • 6
    Fancy verbatim can be configured easily to accept $ as a trigger for math mode. Commented 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
    Commented Apr 11, 2018 at 16:00
26

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.

4
  • 7
    You could use $ #1$ to keep the plain TeX notation without the odd error message. Commented Jul 14, 2012 at 19:54
  • 2
    What do you mean by the final emphasized sentence?
    – egreg
    Commented 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. ... Commented Jul 23, 2012 at 7:02
  • 1
    ... 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. Commented Jul 23, 2012 at 7:04
15

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.

0
10

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.

The manual's example

2
  • 10
    Looks like a bug to me, if a LaTeX package is not compatible with LaTeX syntax. There was no fix since 2003. Commented Mar 10, 2019 at 9:56
  • 2
    This can be circumvented in practice; cf. the answers to tex.stackexchange.com/questions/426019/… .
    – user224332
    Commented Sep 12, 2022 at 12:26
10

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).
9
  • 1
    Where's the love for \begin{math}\end{math}? 🤪
    – Don Hosek
    Commented Sep 22, 2021 at 14:54
  • 2
    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 $.
    – Clément
    Commented Sep 22, 2021 at 16:33
  • 3
    +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. Commented Sep 22, 2021 at 21:06
  • 5
    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. Commented Sep 22, 2021 at 21:08
  • 3
    @MarkMeckes at least you made an informed decision to stick with dollars. I learnt (good) stuff about \(...\) from the other answers, and it's easy to switch (automatically) if needed.
    – rbrignall
    Commented Sep 22, 2021 at 21:12
4

Here are some mitigating factors for the disadvantages of \(...\).

  • Slower to type & frequently used: This isn't an uncommon problem in TeX. For instance, \mathbb{R} for the real numbers, or every environment's \begin{}...\end{}. You can consider these problems on a case-by-case basis: perhaps you'd define the macro \bbR for \mathbb{R}, use $...$ instead of \(...\), and grow a stomach for writing environments. Alternatively, you can find an editor that can fix all these problems at once, e.g. via a snippet engine.

  • Harder to read than $...$: If your formula has a lot of parentheses and slashes, then it is harder to read:

    • \(f(x) = (x^2+1)/5\)
    • $f(x) = (x^2+1)/5$

    Changing the spacing can help:

    • \( f(x)=(x^2+1)/5 \)

    You can even go so far as to write

    \(
        f(x) = (x^2+1)/5      
    \)
    

    This amount of spacing might appear excessive, but as the complexity of the expression increases, separating it from the surrounding text becomes more and more desirable. This applies equally to $...$. Again, if you're acquainted with a good editor, you can minimize the amount of typing you actually have to do.

3

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.

1
1

The error reporting, the number of keystrokes, and the hooks into \(…\) have already been mentioned in other answers, so let us speak about highlighting. The default highlighting in emacs works somewhat differently for $…$ and \(…\) in the scope of \emph{…}:

highlighting

The difference in highlighting is not only a question of taste (similar to the question of whether you like a BMW or a Mercedes more) but also important due to https://tex.stackexchange.com/a/59195. Apart from these details, there's not too much of a difference for a human typesetter. Personally, I switched from $…$ to \(…\) a few years ago and probably make less errors since then (though I got more proficient, I tend to think that the increased quality is also due to this switching).

3
  • Would the downvoter (it/she/he) please care to explain why, in its/her/his opinion, the question would not qualify as an answer?
    – user292998
    Commented Jun 5, 2023 at 17:04
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 5, 2023 at 17:18
  • @Community and at whoever flagged: My answer consists of sentences. If you claim that my answer is unclear to you, there should be the earliest sentence that is unclear to you; which one is it? If you flagged my answer for low quality, there should be the earliest sentence that seems low quality to you; which one is it?
    – user292998
    Commented Jun 5, 2023 at 23:24
0

I prefer \(…\) to $…$ because emacs does a better job on highlighting the former than the latter. In particular, the visual feedback is so good that I don't remember latex complaining about errors due to unpaired \(…\). Ever.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .