7

Is it possible to "lock", or protect, the spacing of a math formula displayed in-text, so that latex will not stretch and squeeze the formula?

I would not like to do this globally for all formulas, but I have one formula ($(-+++)$) that appears repeatedly. Is it possible force latex to always display it with the same spacing?

Update: I now realise that the problem in rendering $(-+++)$ was not due to stretching/squeezing in a paragraph, but due to the special role of + and - in latex formulas. The first - and + are presumably treated as delimiters between terms in a formula, and the latter two two are rendered differently with a shorter spacing. The solution $({-}{+}{+}{+})$ given by cgnieder solves this spacing problem, and gives equal spaces between all +:s and -:s. How to remove such spaces has been asked before: Removing spaces between "words" in math mode.

user14857
  • 73
  • 4
  • Welcome to TeX.SE! Please provide an example of a formula whose (horizontal?) spacing you're looking to protect. Some of the methods available to preserve the basic spacing settings work differently depending on the "math atoms" (letters, commas, equal signs, plus signs, symbols, etc) present in the formula. – Mico Aug 24 '13 at 11:43
  • 2
    \mbox{$...$} would prevent stretching or shrinking (but also line-breaking...) – cgnieder Aug 24 '13 at 11:49
  • I have updated the question. Yes. I am referring to horizontal spacing. – user14857 Aug 24 '13 at 11:49
  • @cgnieder: Both $(-+++)$ and \mbox{$(-+++)$} will have different spacings between the different plus signs. – user14857 Aug 24 '13 at 11:54
  • @user14857 No, they don't: \documentclass{article}\begin{document}$(-+++)$\par\mbox{$(-+++)$}\end{document} – cgnieder Aug 24 '13 at 11:57
  • They look exactly alike. Or are you asking why the spacings in $(-+++)$ aren't the same everywhere? That's got nothing to do with stretching but with + having a different function depending what comes before it (relation, ...) – cgnieder Aug 24 '13 at 12:00
  • Maybe you want $({-}{+}{+}{+})$? – cgnieder Aug 24 '13 at 12:01
  • Thank you! Yes. $({-}{+}{+}{+})$ is exactly what I was looking for. I misunderstood the problem :-) Indeed: $(-+++)$ is rendered as "(-" big space "+" bigspace "+" shortspace "+)". This is not related to streching/squeezing in a paragraph. – user14857 Aug 24 '13 at 12:06
  • I think this question sounds slightly different than the one it is marked duplicated of. For a latex newbie like me, I cannot relate the answer in http://tex.stackexchange.com/questions/851/removing-spaces-between-words-in-math-mode to my problem, although the solution to both questions are the same. – chanp Jun 30 '15 at 19:51

1 Answers1

3

Spacing in (sub)formulae may be frozen by using {...}. In the following example

\( x+y = z \)

is used in the first paragraph, and stretches (or shrinks) as appropriate, whereas in the second paragrah

\( {x+y = z} \)

gets fixed spacing.

Sample output

\documentclass{article}

\begin{document}

Here is an example formula \( x+y = z \) which we repeat at several
times during the paragraph.  Notice that the spacing changes on
different uses \( x+y = z \) depending on how much the line is
stretch.  This is useful as it helps with even spacing of the whole
paragraph despite the presence of formulae \( x+y = z \).  Stretchable
spacing in the mathematics \( x+y = z \) is often to be preferred.

Using braces \verb!{}! around the forumla \( {x+y = z} \) freezes the
spacing.  It also prevents line breaks occuring in the middle of the
formula \( {x+y = z} \).  This prevention of line breaks can also be
used in subformals, but we are demonstrating that in the case of \(
{x+y = z} \).  I expect to see that the spacing in this paragraph is
not as good as the previous because of the lack of flexibility
associated to the formula \( {x+y = z} \).

\end{document}

You'll find this behaviour described in the TeXbook, p. 173

Andrew Swann
  • 95,762