405

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

Mark Meckes
  • 17,791
  • 49
    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). – barbara beeton Oct 08 '11 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. – user2987828 Dec 03 '13 at 22:47
  • 2
    @user2987828 A cleaner way to do that, as you know, would be \text from amsmath. – Davislor Jun 04 '20 at 04:16
  • Restating https://tex.stackexchange.com/questions/510/are-and-preferable-to-dollar-signs-for-math-mode#comment1539402_616297 , any reason to use \begin{math}…\end{math}? –  Mar 03 '23 at 01:26

13 Answers13

290

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

Juan A. Navarro
  • 62,139
  • 32
  • 140
  • 169
Dima
  • 12,427
  • 8
  • 40
  • 53
  • 3
    @Joseph: IMHO, that's the real reason for using ( and ) and I think should be put as an actual answer rather than a comment. – Andrew Stacey Jul 29 '10 at 08:36
  • @Andrew Stacey: Right I'm playing around with it now, and it seems that i must have been a package (or my custom code) which was hooking into the \ ( ... \ ) cause I can't reproduce it now. As far as I remember it was to do with inline fraction presentation: vertical vs horizontal. – Dima Jul 29 '10 at 09:14
  • 1
    Also see answer from Will Robertson referencing captions and headings (didn't know that). – Dima Jul 29 '10 at 09:17
  • 1
    @Jasper: This is all a long way off, and my personal view may not match up with those of all of the team, let alone anyone else. (I doubt $$ ... $$ is going to be supported, as there are some technical issues with how TeX does this.) – Joseph Wright Apr 27 '11 at 06:05
  • 1
    @Joseph: I agree 100% with Jasper on the single $. Another thing: You can "hook into" $ via \everymath, can't you? – Hendrik Vogt Jul 19 '11 at 19:16
  • 5
    @Hendrik: That very much depends on what you want to achieve (see the reasons for not using $$ syntax, where \everydisplay cannot help you out). Speaking purely personally, I find $ ... $ harder to read than \( ... \). – Joseph Wright Jul 19 '11 at 19:19
  • 3
    @Joseph: Well, the "harder to read" thing seems to be personal taste. But in what way does it depend on what I want to achieve? And why can't \everydisplay help me out for $$? – Hendrik Vogt Jul 19 '11 at 19:24
  • @Hendrik: Using one of the registers can only help if what you need to do can happen once the switch to math mode takes place. Some potential issues are discussed in another question. – Joseph Wright Jul 19 '11 at 19:30
  • 96
    @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. – Frank Mittelbach Jan 16 '12 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 Jan 16 '12 at 14:50
  • 2
    @Joseph agreed. – Frank Mittelbach Jan 16 '12 at 18:15
  • 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' Feb 03 '12 at 15:46
  • 2
    @tohecz To rephrase and add another detail: In an environment with many 's and various versions of parentheses, \(...\) can be hard to visually parse. In such contexts and especially if you know what you're doing you might as well forgo the minor benefits of the \(...\) and stick with $...$. Otherwise, the syntax is an inconvenience, but given the situation, I prefer progress to legibility, and there's nothing else we can do, in a way. – Lover of Structure Jun 13 '12 at 21:23
  • 35
    "$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 May 04 '13 at 05:46
  • 1
    @JosephWright May be I'm a bit late to the party (this question is from 2010 :D)… but I think the best would be to provide the necessary \math:w … \math_end: or \math:n { … } and then $…$ or \(…\) would be only “front ends” and it would be easier to decide at a later stage. – Manuel Jul 29 '14 at 15:14
  • 1
    @Manuel Oh, certainly. May still require an active char approach, but as yet undecided. – Joseph Wright Jul 29 '14 at 15:16
  • @JosephWright I know I am VERY late to comment, nonetheless ... it may sound outright dumb, but if a team is/ was making decisions regarding what & how best to include/ support it in LaTeX3, wouldn't it (have been?) be prudent to grab the best of both viewpoints and support $ or $$ registers with best possible robust definitions which were newly constructed/ modified considering the "good, bad & the ugly" of both types of syntaxes? In simple words, why not use $ / $$ for face and best consolidated approach from $..$ / $$..$$ as well as \(..\) /[..]` for the brain? – Amar May 30 '15 at 14:34
  • .... I say this because, even I find $ easy to find & read than \( – Amar May 30 '15 at 14:36
  • 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 May 30 '15 at 15:58
  • @JosephWright Thanks! I read http://tex.stackexchange.com/q/503/78565 after posting this comment and it helped me understand the advantages/ disadvantages between the two syntax a little better. – Amar May 30 '15 at 16:23
  • 2
    It is not true that plainTeX only allows $. PlainTeX alows everything what is in plainTeX defined. – wipet Jan 06 '21 at 20:11
  • should wi have space after \( and space before \)? – alper May 17 '22 at 11:41
  • As for hooks into \(…\), you probably mean https://tex.stackexchange.com/a/59195 . –  Jun 05 '23 at 14:33
86

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 Stacey
  • 153,724
  • 43
  • 389
  • 751
  • 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!! :)) – Geoffrey Jones Aug 23 '10 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. – Frank Mittelbach Jan 16 '12 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 May 30 '15 at 14:48
51

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.

mbork
  • 13,385
46

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.

Mico
  • 506,678
  • 1
    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 Sep 22 '21 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 $.

Sean Allred
  • 27,421
  • 6
    Fancy verbatim can be configured easily to accept $ as a trigger for math mode. – Konrad Rudolph Sep 07 '10 at 12:04
  • Other editors pair match and highlight $...$, but not (...), e.g., the default emacs tex mode. (Auctex supports both, though.) –  Apr 11 '18 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.

  • 7
    You could use $ #1$ to keep the plain TeX notation without the odd error message. – Bruno Le Floch Jul 14 '12 at 19:54
  • 2
    What do you mean by the final emphasized sentence? – egreg Jul 23 '12 at 06: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. ... – Lover of Structure Jul 23 '12 at 07: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. – Lover of Structure Jul 23 '12 at 07: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.

Display Name
  • 46,933
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

Jonas Stein
  • 8,909
  • 10
    Looks like a bug to me, if a LaTeX package is not compatible with LaTeX syntax. There was no fix since 2003. – Jonas Stein Mar 10 '19 at 09:56
  • 2
    This can be circumvented in practice; cf. the answers to https://tex.stackexchange.com/questions/426019/making-soulutf8-work-with . –  Sep 12 '22 at 12:26
9

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).
rbrignall
  • 1,564
  • 1
    Where's the love for \begin{math}\end{math}? – Don Hosek Sep 22 '21 at 14:54
  • 1
    @DonHosek as a Brit, I'd have to create a macro \begin{maths}...\end{maths} – rbrignall Sep 22 '21 at 16:12
  • 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 Sep 22 '21 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. – Mark Meckes Sep 22 '21 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. – Mark Meckes Sep 22 '21 at 21:08
  • @clement yes, good point. Others, of course, use \(...\) (I have to interact with both, and I know which I prefer.) – rbrignall Sep 22 '21 at 21:09
  • 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 Sep 22 '21 at 21:12
  • 1
    Your last point becomes invalid if an actual $ sign (\$ that is) occurs in your text. It should be impossible to match the dollars correctly in a string like foo $x$ bar 20\,\$ baz $y$ foobar with a regular expression, same with embedded math mode as in foo $E_{\text{$\alpha$ radiation}}$ bar. – Lupino Mar 26 '23 at 08:37
  • 1
    Sure, but (a) I never nest math modes like that, (b) I never need \$, and (c) I never need to switch from $...$ to \(...\). I suspect the same holds, and particularly point (c), for most users of LaTeX. – rbrignall Mar 27 '23 at 08:46
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.

3

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.

llf
  • 175
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.

0

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

  • Would the downvoter (it/she/he) please care to explain why, in its/her/his opinion, the question would not qualify as an answer? –  Jun 05 '23 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 Jun 05 '23 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? –  Jun 05 '23 at 23:24