# No space after inline math

how do I prevent (at least nearly) any space after an inline math environment?

abc def $\Delta$ ghi


The space between the delta and ghi shouldn't be larger than the space between abc and def.

There is just one word space after c after f and after the math, in each case coming from the space in the source.:

• it may just look bigger because of the shape of the delta. – barbara beeton Sep 15 '13 at 20:38

The spaces can be debugged with \showlists or putting the text in a box with \showbox:

...
\showlists
% or
\sbox0{...}
\showbox0


Then TeX prints the current contributions to the vertical list or the box contents to the .log file. The amount of the data is controlled by the parameters \showboxbreadth and \showboxdepth that should be increased, because the default is negative for both of them to suppress the output. \tracingonline=1 also writes the .log messages to the console.

\showboxbreadth=\maxdimen
\showboxdepth=\maxdimen
\tracingonline=1

\documentclass{article}
\begin{document}
\sbox0{abc def $\Delta$ ghi}
\showbox0
\usebox0
\end{document}


LaTeX stops at \showbox to print the box contents to the console/.log file:

> \box0=
\hbox(6.94444+1.94444)x60.00012
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\kern0.27779
.\OT1/cmr/m/n/10 c
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 d
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 f
.\glue 3.33333 plus 1.66666 minus 1.11111
.\mathon
.\OT1/cmr/m/n/10 ^^A
.\mathoff
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 g
.\OT1/cmr/m/n/10 h
.\OT1/cmr/m/n/10 i

! OK.
l.8 \showbox0


As you can see, the three spaces between abc, def, Δ and ghi are exact the same (interword space):

.\glue 3.33333 plus 1.66666 minus 1.11111


Inline math can have space around the formula if \mathsurround is set. Its default is zero. Example:

\documentclass{article}
\setlength{\mathsurround}{1ex}
\begin{document}
sbox0{abc def $\Delta$ ghi}
\showbox0
\usebox0
\end{document}


Box contents with \mathsurround=1ex:

> \box0=
\hbox(6.94444+1.94444)x68.6112
.\OT1/cmr/m/n/10 a
.\OT1/cmr/m/n/10 b
.\kern0.27779
.\OT1/cmr/m/n/10 c
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 d
.\OT1/cmr/m/n/10 e
.\OT1/cmr/m/n/10 f
.\glue 3.33333 plus 1.66666 minus 1.11111
.\mathon, surrounded 4.30554
.\OT1/cmr/m/n/10 ^^A
.\mathoff, surrounded 4.30554
.\glue 3.33333 plus 1.66666 minus 1.11111
.\OT1/cmr/m/n/10 g
.\OT1/cmr/m/n/10 h
.\OT1/cmr/m/n/10 i

! OK.
l.9 \showbox0


But there can be other visual effects. TeX only sees the char bounding boxes. It does not know, where the glyph is acutally placed. This can be made visible by using a tight \fbox:

\documentclass{article}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{.2pt}

\begin{document}
\fbox{abc} \fbox{def} \fbox{$\Delta$} \fbox{ghi}
\end{document}


Observations:

• As you can see, a part of the f is written outside to the right of its bounding box (this is allowed, not a bug). Thus the space between def and Δ might look a little smaller.

• On the other side of Δ the letter g has a positive side bearing to the left. Side bearings mean a little space to the left and right of the symbol inside the character bounding box. Also the upper right part of Δ and the upper part of g are empty. Thus the space looks huge in comparison to the space between f and Δ.

• +1 nice answer. I hope you don't steal my tick though:-) – David Carlisle Sep 15 '13 at 22:13