# What is the difference between badness and penalty?

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?

• I tagged the question with tex-core because these concepts aren't defined in LaTeX (the format package), but in TeX (the program). Feel free to revert if you don't agree. Jan 29, 2019 at 18:58
• Jan 29, 2019 at 19:02
• Both badness (roughly: take the actual stretch or shrink, divide by max stretch or shrink, and cube it, but for shrink beyond the max use ~infinity) and penalties are squared and go into the calculation of the paragraph's total demerits, which is what is minimized. See "TeX by Topic" section 19.1 or answers on this site like this or this or this. Jan 29, 2019 at 22:40
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Apr 4, 2019 at 15:17

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 \pretolerance for 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 \sloppy, changes the \tolerance. (There are more parameters for badness like \hbadness and \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 called \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 paragraph small.)