Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I find out the linebreak penalty at a given point of text or a math formula? An example would be the point before and after the equals sign here: \(a + b = c\).

If I write complex formulas, I sometimes want to manually insert \penalty values, but the choice of number to get the effects I want (e.g., Do I really need \penalty10000 to prevent a linebreak after some particular \mathrel in some particular formula?) often amounts to a long process of trial-and-error. Knowing what effective \penalty value there would be at a certain point within a formula without manual intervention will help reduce the space for experimentation.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

TeX automatically adds penalties after binary operations and relation symbols, but only at the outer level of a formula (for instance, not for formulas inside a {...} group or between \left and \right; also the arguments to \mathbin and similar commands make a subformula).

The value of these penalties is stored in the parameters \binoppenalty and \relpenalty. The default values are

\binoppenalty=700
\relpenalty=500

These automatic penalties are not inserted if an explicit penalty follows a binary operation or relation symbol. To wit,the following Plain TeX input

\showboxbreadth=1000 \showboxdepth=1000

$a+b=c$\showlists

$a+b=\penalty100 c$\showlists

\bye

produces, in the log file,

### horizontal mode entered at line 4
\hbox(0.0+0.0)x20.0
\mathon
\teni a
\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
\tenrm +
\penalty 700
\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
\teni b
\glue(\thickmuskip) 2.77771 plus 2.77771
\tenrm =
\penalty 500
\glue(\thickmuskip) 2.77771 plus 2.77771
\teni c
\mathoff

for the first line, while it gives

### horizontal mode entered at line 6
\hbox(0.0+0.0)x20.0
\mathon
\teni a
\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
\tenrm +
\penalty 700
\glue(\medmuskip) 2.22217 plus 1.11108 minus 2.22217
\teni b
\glue(\thickmuskip) 2.77771 plus 2.77771
\tenrm =
\penalty 100
\glue(\thickmuskip) 2.77771 plus 2.77771
\teni c
\mathoff

for the second line.

If you add \penalty0 after = you simply make that a feasible break point; with the usual 500 a break is possible, with 10000 it is forbidden.

You can't know in advance what's a good value for getting a break. The only way to be sure to get a break after = is to add \penalty-10000. The line breaks are chosen by TeX by considering the paragraph as a whole.

Penalties that affect line breaking are only added in a few cases:

  • math formulas, as seen above;

  • after an explicit hyphen or ligature that ends with a hyphen, the parameter is \exhyphenpenalty;

  • after a discretionary item (that might have been inserted by the hyphenation process), the parameter is \hyphenpenalty;

  • at the end of the paragraph TeX adds

    \unskip\penalty10000\hskip\parfillskip\penalty-10000
    

    to finish it off.

The result of this is that there is no concept of “linebreak penalty at a point”. Penalties are just one of the factors TeX keeps into account for computing a series of line breaks, in order to get the fewer demerits.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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