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 1:22
  • 1
    @cfr but I see no example on David's answer showing the problem with spacing using $$...$$. – Gonzalo Medina Oct 13 '15 at 1: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 1:30
9

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}
  • 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 3: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 3: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 3: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 3:56
  • 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 7: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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.