5

I can put display math in the middle of a paragraph of text using \[...\], but I would like the math to use font size small. If I wrap the display block in {\small...} the second half of the paragraph, beginning with the word "centuries", starts with a small amount of unwanted whitespace. This goes away if I remove the {\small...}. enter image description here

\documentclass{article}

\begin{document}
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
{\small\[
A / B + C = D
\]}
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
\end{document}

I guess I'm going about this in the wrong way. Help?

Roly
  • 4,221
  • 4
  • 26
  • 56
  • 2
    You need to add a % (comment) character immediately after \]}. – Mico Feb 24 '16 at 11:34
  • That seems to work - thanks! Out of interest, what's going on here? (Moving \small inside the \[...\] also seems to fix it.) – Roly Feb 24 '16 at 11:38
  • 1
    Whitespace is removed after control words (backslash plus one or more alphabetical characters), but not after control symbols (backslash plus a single non-alphabetical character}. Line breaks are treated as whitespace. Thus, from TeX's point of view, \]} forms a control symbol plus }, which ends a group. Thus, the following whitespace character is not discarded. Get rid of it either by providing a comment character or by providing a suitable control word, say, \noindent. – Mico Feb 24 '16 at 11:43
  • 1
    @Roly Not really: moving \small inside \[ produces a warning that shouldn't be disregarded. – egreg Feb 24 '16 at 11:46
  • 1
    The space is unrelated to \small it is just the space after } (try with just the braces and no font change.) – David Carlisle Feb 24 '16 at 11:49
  • @egreg Ok, I didn't notice the warning. – Roly Feb 24 '16 at 11:57

1 Answers1

6

You get two spurious spaces: one at the start of the line, which is more evident, but also tighter vertical space above the display than below, because you're using the above skip pertaining to \small, but the below skip pertaining to \normalsize.

You can emulate the standard behavior:

\documentclass{article}

\begin{document}

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
{\par\penalty\predisplaypenalty\small\[
A / B + C = D
\]\par}\penalty\postdisplaypenalty\noindent
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.

\end{document}

enter image description here

You could define a vardisplaymath environment:

\makeatletter
\newenvironment{vardisplaymath}[1][\small]
 {\par\penalty\predisplaypenalty\begingroup#1\begin{displaymath}}
 {\end{displaymath}\par\endgroup\penalty\postdisplaypenalty
  \@endparenv}
\makeatletter

Full example:

\documentclass{article}

\makeatletter
\newenvironment{vardisplaymath}[1][\small]
 {\par\penalty\predisplaypenalty\begingroup#1\begin{displaymath}}
 {\end{displaymath}\par\endgroup\penalty\postdisplaypenalty
  \@endparenv}
\makeatletter

\begin{document}

Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text ever
since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five
\begin{vardisplaymath}
A / B + C = D
\end{vardisplaymath}
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.
\begin{vardisplaymath}[\footnotesize]
A / B + C = D
\end{vardisplaymath}
centuries, but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with the release
of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions
of Lorem Ipsum.

\end{document}

enter image description here

This could be adjusted to always get the parameters from \normalsize.

Thanks to Tobi for suggesting an improvement.

A simpler approach that doesn't require plunging into details such as \penalty\postdisplaypenalty (needed in order to avoid page breaks after the display) and keeping the above and below skips from \normalsize is

\newsavebox{\vardisplaymathbox}
\newenvironment{vardisplaymath}[1][\small]
  {\begin{displaymath}\begin{lrbox}{\vardisplaymathbox}
   #1$\displaystyle}
  {$\end{lrbox}\usebox{\vardisplaymathbox}\end{displaymath}%
   \ignorespacesafterend}

The result with this definition is

enter image description here

egreg
  • 1,121,712
  • Removing the instructions \penalty\predisplaypenalty and \penalty\postdisplaypenalty doesn't seem to generate a visible effect. Could you explain that they maybe guard against? – Mico Feb 24 '16 at 11:39
  • @Mico Without \penalty\postdisplaypenalty you might get a page break after the display. – egreg Feb 24 '16 at 11:43
  • Your new environment vardisplaymath would’t work, if the following text actually is a new paragraph, would it? Since the \noindent prevents the indention in this case too. – Tobi Feb 24 '16 at 11:48
  • @Tobi Yes, that's true. :( – egreg Feb 24 '16 at 11:51
  • Thanks for the detailed answer. Unfortunately your first vardisplaymath macro doesn't work for me - it produces too much space above the math, so that the math is no longer vertically centred between the two halves of the paragraph. I'll experiment some more. – Roly Feb 24 '16 at 12:19
  • in your first sentence, "uneven spaces at the top and at the bottom" might better be phrased as "uneven baselines ..." or "tighter baselines above than below"; when in see "uneven spaces", i usually assume they're all in the same direction, either horizontal or vertical. otherwise, a nice approach. – barbara beeton Feb 24 '16 at 14:06
  • Replacing \noindent by \@endparenv (and adding \makeatletter/other of course) fixes this issue :-) – Tobi Feb 24 '16 at 16:47
  • @Tobi That's a good idea indeed! – egreg Feb 24 '16 at 17:10
  • @Mico I was incorrect in pointing to \postdisplaypenalty: it was \predisplaypenalty the main thing. – egreg Feb 24 '16 at 17:17
  • @egreg - Many thanks for pointing out this issue. It's very helpful. – Mico Feb 24 '16 at 17:24
  • Ok I've tried the second version (with the improvements suggested by @Tobi) and it seem to avoid the problem with the uneven vertical spacing that the first definition has for me. (Perhaps this is related to keeping the above and below skips from \normalsize.) However, the improved version is a little hidden - would you mind editing the answer so that the improved version appears first, in the example code? Thanks! – Roly Feb 25 '16 at 09:26
  • Separate comment: the method described here for altering the above and below skips doesn't seem to work with your \vardisplaymath macro. I.e. if I use the \g@addto@macro \small trick to set the skips they don't get picked up. Any suggestions? – Roly Feb 25 '16 at 09:39
  • @egreg To clarify, your "main" answer doesn't work for me (see here for how the spacing above and below are not consistent), whereas the refinement suggested by Tobi does. If you agree that the improvement (as you call it) is indeed an improvement, would you consider editing your answer to make it the "main" suggestion? I think that would be more helpful to others. Thanks. – Roly Feb 27 '16 at 08:58
  • @egreg Please also see my comment above re. altering the above and below skips via \g@addto@macro \small. (I forgot to add your user id to my last couple of comments, so I guess you didn't spot them. Sorry.) – Roly Feb 27 '16 at 09:00