In order to make text flushed both left and right, latex adjusts the distance between words, and to a lesser extent, the distance between characters within a word. This is good, however it also adjusts the spacing within mathematical formulae. I don't like this feature - can I reduce its effect, or perhaps turn it off completely?
2 Answers
You would have to modify the length registers that allow for stretch/shrink around math operators/relations, namely \medmuskip
and \thickmuskip
. Their defaults are 4.0mu plus 2.0mu minus 4.0mu
and 5.0mu plus 5.0mu
. So adding
\setlength{\medmuskip}{1\medmuskip}% Formerly 4.0mu plus 2.0mu minus 4.0mu -> 4.0mu
\setlength{\thickmuskip}{1\thickmuskip}% Formerly 5.0mu plus 5.0mu -> 5.0mu
should work by stripping the glue. For more on math spacing around operators, see How to change default for spacing around binary relations?
Here's a small example:
\documentclass{article}
\begin{document}
Here is some text with an equation in it: $f(x)=x^2+3x_0\cdot\sin x$
and the textual content continues into the second line. No other math
content is contained within this paragraph.
%\thinmuskip=3.0mu (without glue)
\setlength{\medmuskip}{1\medmuskip}% Formerly 4.0mu plus 2.0mu minus 4.0mu -> 4.0mu
\setlength{\thickmuskip}{1\thickmuskip}% Formerly 5.0mu plus 5.0mu -> 5.0mu
Here is some text with an equation in it: $f(x)=x^2+3x_0\cdot\sin x$
and the textual content continues into the second line. No other math
content is contained within this paragraph.
\end{document}
Since \thinmuskip
is already void of glue, no further modifications is required. For a motivation of where these lengths are used, see the mathmode
documentation (section 11 Space, subsection 11.1 Math typesetting, p 28).
mu
skips are not supported by calc
, alternate calculations techniques (using plain TeX) are required to manipulate these lengths.
-
2
\setlength
should not be used, because muskips are not supported by package calc. Also there is no need for magic numbers,\medmuskip=1\medmuskip
and\thickmuskip=1\thickmuskip
will do. Commented Nov 22, 2012 at 8:29 -
1By the way, the fact that (for example)
\medmuskip=1\medmuskip
leaves the natural length of\medmuskip
the same but keeps it from stretching or shrinking is mentioned on page 100 of Lamport's LaTeX 2e manual: "Multiplying a length command by a number destroys its elasticity, producing a rigid length." I thought I'd mention this because I'm not sure how common the knowledge of this trick is.– MSCCommented Jun 4, 2014 at 19:52 -
Unfortunately, the link to the
mathmode
documentation is dead. Commented Jun 13, 2017 at 14:36 -
@polynomial_donut: Thanks; fixed! The "package" has moved location and is considered obsolete. :-|– Werner ♦Commented Jun 13, 2017 at 15:13
As an alternative to resetting the parameters it is sometimes more convenient to box the expression so it is set to natural width, either with an explicit box, or within the math, just using {}
.
Note the math only stretched on the second row in this plain tex example.
X\hbox{words here $a + b$ and here}X
X\hbox spread 1cm{words here $a + b$ and here}X
X\hbox spread 1cm{words here \hbox{$a + b$} and here}X
X\hbox spread 1cm{words here ${a + b}$ and here}X
\bye