What in LaTeX is the difference between badness and penalty?
Are badness and penalty the same?
In what range are the values for both, badness and penalty?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.Sign up to join this community
As mentioned in the comments both items are part of the implementation of TeX. In the box-penalty-glue model for TeX, penalty is listed as a core concept and badness has to do with boxes.
Badness and penalties are two different concepts but they share the same scale, i.e., their values are comparable when they contribute to the demerits calculation. Demerits are used to rank different line break sets for a paragraph, for example. As one comment states, in this calculation squared badness and penalty values are used. Badness is always positive (up to 10000 or artificial), penalties are in the range -10000 to 10000 and they keep their sign when they are used in the demerits formula.
Badness is something that TeX calculates based on the amount of
needed stretch- or shrinkability compared to the available stretch- or
shrinkability. This is valid for horizontal (paragraph) or vertical
(page) calculations. The user cannot influence this computation
directly; only an upper limit can be specified with
the first and
\tolerance for the following passes which TeX
executes to find the line breaks in a paragraph. Plain TeX uses the
values 100 and 200 but some commands in LaTeX, like
\tolerance. (There are more parameters for badness like
\vbadness that are lower limits for warning messages about overfull boxes.)
Penalty is something that either TeX adds to a break based on
parameters that the user can manipulate or the user enters it directly
into the input source. For example, two parameters in paragraphs are
\hyphenpenalty (break at an hyphen that TeX inserts) and
\exhyphenpenalty (break at a hyphen that occurs in the input); there
are many more, for example, in math mode. For page breaks there is,
for example, the
\brokenpenalty that is applied if the last line on
the page ends with a hyphen. Again there are many more.
A user can enter a penalty using the command
\penalty. A break at glue
has no parameter-driven penalty, its penalty is 0. So the user must
specify a value via
\penalty if the break at this glue shall be
treated differently. Often the tilde is used between words to prevent a break at
glue as it contains a penalty of 10000 (no break allowed). On the
other hand TeX is allowed to break at a penalty less than 10000 even
if there is no glue or a hyphen.
One parameter, the
\linepenalty, has a special meaning: It is added to
the badness of a line in a paragraph; so it has not directly to do with
a break. (It helps in many cases to keep the number of lines in a