18

The use of \[...\] vs. $$...$$ is discussed in Why is \[ ... \] preferable to $$ ... $$? and What are the differences between $$, \[, align, equation and displaymath?.

It seems like \[...\] has benefits in some uncommon uses cases (leqno and \qedhere), but the main reason to use it is, according to most answerers, spacing issues.

However, in the answers I only see examples of how \[...\] leads to worse spacing without amsmath.

Could someone provide a minimal example of an incorrect spacing produced by $$...$$, which is fixed by switching to \[...\] and amsmath?

If you wish, you can start by modifying the following M(non-)WE (which, as it is, shows no difference between the two variants, at least on my machine with Texlive 2015). The rules are \smashed, so they should take up no space, and they are there only to show that the spacing above and below the equation is exactly the same (idea taken from jfbu's answers to the two above-cited questions).

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Wrong spacing:\hrulefill\par
$$
\vartheta=2\pi\smash{\rule[-4ex]{.4pt}{9.5ex}}
$$
\hrulefill\par

Correct spacing:\hrulefill\par
\[
\vartheta=2\pi\smash{\rule[-4ex]{.4pt}{9.5ex}}
\]
\hrulefill\par
\end{document}
  • Doesn't David's answer there cover it? That \[ \] does better than $$ $$ without amsmath but that \[ \] plus amsmath is better still? Is there disagreement about which variation has better spacing or...? – cfr Oct 13 '15 at 01:22
  • 1
    @cfr but I see no example on David's answer showing the problem with spacing using $$...$$. – Gonzalo Medina Oct 13 '15 at 01:25
  • @cfr Exactly like Gonzalo said. The only MWE is in jfbu's answer, but it simply shows the bug in \[...\] without amsmath. – Federico Poloni Oct 13 '15 at 01:30

2 Answers2

10

I think using \hrulefill (or \hrule) creates a misleading impression here, as it places its output below the baselines -- not where one would usually expect to find text. (Aside: When was the last time you saw a real document that had displayed equations bounded above and below by \hrules?) I'd rather use lines of dummy text above and below the equations to assess the vertical spacing issues associated with various ways of creating displayed equations.

Below is a slightly modified version of the MWE I posted in my answer to one of the two postings you provided a link to. Both displayed equations have a blank line above them, forcing them to start in TeX's "vertical mode". How do the two methods handle this sub-optimal situation? The first displayed equation is generated with \[ ... \], and it is well centered. In contrast, the second displayed equation, which is generated with $$ ... $$, is not centered properly.

I hope this example addresses your request,

Could someone provide a minimal example of an incorrect spacing produced by $$...$$, which is fixed by switching to \[...\]

enter image description here

\documentclass{article}
\setlength\textwidth{1in} % use a very narrow measure for this example
\begin{document}
\noindent
some words some

\[ u=vwxz\]
some words some 

$$u=vwxz$$
some words some
\end{document}
Mico
  • 506,678
  • Thanks for your example. What I find confusing, though, is that if one adds \usepackage{amsmath}, then both versions look like the second one. So this means that amsmath actually makes \[...\] behave worse? Or maybe there is some reason why the second kind of spacing (uneven) is considered better? – Federico Poloni Oct 13 '15 at 03:26
  • 2
    @FedericoPoloni - The amsmath package redefines \[ and \] to behave like \begin{equation*} and \end{equation*}, respectively. Importantly, the \nointerlineskip instruction that's provided in the LaTeX kernel definition of \[ is not included in the amsmath definition of \begin{equation*}. (I have truly no idea why it was omitted.) The wisdom of the often-found exhortation not to have displayed equations start a paragraph manifests itself once again when one uses the amsmath package. – Mico Oct 13 '15 at 03:35
  • @Mico -- I think your comment here is the key to the answer of the technical part of this question. (The aesthetic question may have a different answer, if it is answerable at all.) – jon Oct 13 '15 at 03:51
  • @jon - I meant to challenge the notion, expressed by the OP, that "... I only see examples of how \[...\] leads to worse spacing without amsmath." I hope my answer, which deliberately did not load the amsmath package, provides such a challenge. – Mico Oct 13 '15 at 03:56
  • I appreciate a lot your answer, but I must say this leaves me even more confused as to what the best practice is (apart from "never start paragraphs with an equation"). – Federico Poloni Oct 13 '15 at 04:34
  • @FedericoPoloni - For LaTeX documents, I see some upsides and no downsides in using \[ ...]instead of$$ ... $$` for unnumbered, single-line equations. – Mico Oct 13 '15 at 05:58
  • @Mico If I am not missing anything, jvbu's answer in one of the linked question shows a spacing issue using \[...\] without amsmath. Your answer shows a spacing issue when using $$...$$, as well as \[...\] with amsmath. So it seems like each alternative has some downsides. – Federico Poloni Oct 13 '15 at 06:23
  • @FedericoPoloni - On jfbu's answer: egreg pointed out in a comment that it's not correct to create consecutive displayed equations the way jfbu does. Any tool can be abused -- is the subsequent disappointing performance the tool's fault, or should the user be blamed for the abusive behavior? (I strongly tend toward the latter view.) Hence, I don't think it can be said that jfbu established a meaningful weakness of \[ ... \]-without-amsmath (relative to the plain-TeX $$ ... $$ method). – Mico Oct 13 '15 at 06:37
  • @Mico I understand, this view makes sense, thanks. So using \[...\] is indeed the best practice, but using amsmath reintroduces the wrong spacing behaviour. – Federico Poloni Oct 13 '15 at 07:20
  • 3
    @FedericoPoloni - AFAICT, the incorrect spacing of \[...\] with amsmath loaded occurs only if the displayed equation starts a paragraph. As David Carlisle has noted in the meantime in an answer of his own, best practice is definitely not to start a paragraph with a displayed equation, under any circumstance. – Mico Oct 13 '15 at 07:30
10

The main reason for using \[ is not for spacing issues. It is for better error checking and support for fleqn.

The behaviour of \[ v amsmath-\[ v $$ at the start of a paragraph is really a minor things as in no cases should a math display ever start a paragraph and although there are minor differences in error recovery the spacing in all cases varies from poor to awful, so should never occur in a real document.

David Carlisle
  • 757,742