# \badness

#### Summary

Each time TEX constructs a box (e.g., explicitly via an `\hbox`

or `\vbox`

) it sets,
or calculates, that box’s “badness”: a numeric value which can be thought of as a
way to measure, or classify, how “well” the content of a box fits inside that box. The
badness value for the most-recently constructed box is saved in a read-only register (a
memory location) which can be accessed by the command `\badness`

: for example by
`\the\badness`

. Note that TEX also creates boxes during other typesetting
activities (e.g. linebreaking) but here we’ll focus on explicit box-construction
commands.

#### Explanation and examples

When TEX is asked to create a box using the following box-construction commands:

`\hbox`

`\vbox`

`\vtop`

you can choose to set the size of the box and ask TEX to try to fit your content
into it; for example `\hbox to 20pt{<stuff>}`

will ask TEX to try to fit your
`<stuff>`

into a box that is 20pt wide. TEX will do its best to make `<stuff>`

fit by
stretching or shrinking any available glue.

Alternatively, if you *don’t* fix the size of a box, by writing `\hbox{<stuff>}`

, TEX
will simply construct an `\hbox`

that is sufficiently wide to accommodate `<stuff>`

and
in that case TEX will assign that box a badness value of 0.

When TEX decides to calculate the badness of a box it compares the actual size
of your content with the appropriate dimension of the box in which it has to fit: is
your content too wide to fit the specified `\hbox`

or too high to fit the designated
`\vbox`

or `\vtop`

? As part of the badness calculation TEX also takes into
account the *total* amount of each type of glue within the box—i.e., how
much total stretch or shrink is available to help produce a box of the desired
size.

In practise, when TEX needs to calculates a box’s badness value it uses (an approximation to) the following formula:

\[\mathrm{badness}=100\left ({t \over s}\right )^3\]

where \(t\) is the desired “excess width” to be accommodated and \(s\) is the amount of glue available for stretching or shrinking.

The value of badness usually falls between 0 and 10000 but a special value is reserved for boxes that, even after allowing for the shrinking of glue, are simply not big enough to hold the content: those boxes are classified as “overfull” and TEX assigns them a “special” badness value of 1000000.

OK, so much for discussion/theory we’ll now look at some examples. We’ll create
5 boxes and use 5 `\count`

registers to hold the `\badness`

value of the box that TEX
has just created. We later use those `\count`

registers to output the `\badness`

value of
the relevant box.

```
\newcount\aval\newcount\bval\newcount\cval\newcount\dval\newcount\eval
\setbox100=\hbox{Hello \TeX}\aval=\the\badness %We do not set the box size
\setbox101=\hbox to25mm{Hello \TeX\hskip0pt plus5pt}\bval=\the\badness
\setbox102=\hbox to50mm{Hello \TeX}\cval=\the\badness
\setbox103=\hbox to50mm{Hello \TeX\hfill}\dval=\the\badness
\setbox104=\hbox to5mm{Overleaf}\eval=\the\badness
\setlength{\fboxsep}{0pt}% put a tight border around each box
\noindent Here are the results:\vskip5mm
\noindent box 100 (\fbox{\copy100}) has a \verb|\badness| value of \number\aval\par
\noindent box 101 (\fbox{\copy101}) has a \verb|\badness| value of \number\bval\par
\noindent box 102 (\fbox{\copy102}) has a \verb|\badness| value of \number\cval\par
\noindent box 103 (\fbox{\copy103}) has a \verb|\badness| value of \number\dval\par
\noindent box 104 (\fbox{\copy104}) has a \verb|\badness| value of \number\eval\par
```

The following graphic shows the output:

- box 100:
`\hbox{Hello \TeX}`

. This has`\badness`

0 because TEX was not asked to fit the content to a specific size. - box 101:
`\hbox to25mm{Hello \TeX\hskip0pt plus5pt}`

. This box has two glues: an interword space after the word “Hello” and 5pt coming from the`\hskip`

glue. However, the desired box is 25mm wide which results in a lot of space to fill with not much glue to do so. That combination of excess space and available glue results in the`\badness`

value of 6396. - box 102:
`\hbox to50mm{Hello \TeX}`

. This box has just one glue item: an interword space after the word “Hello” and has a lot of excess space to fill. That combination of excess space and small amount of glue results in a very large`\badness`

value—so high that TEX “clips” it to the maximum value of 10000. In addition, the interword space is stretched considerably to fill up the box, resulting in a huge gap appearing between “Hello” and “TEX” - box 103:
`\hbox to50mm{Hello \TeX\hfill}`

. This box is similar to box 102 but it has two glues: the interword space after the word “Hello” but it has a second very flexible glue provided by`\hfill`

–a so-called “ininitely flexible” glue. Consequently,`\hfill`

can stretch as far as required and expands to absorb all the excess space. Because of the “ininitely flexible” glue the resulting`\badness`

is 0. - box 104:
`\hbox to5mm{Overleaf}`

This box overlaps the text following it has a`\badness`

value is 1000000. The very large badness value (and overlapping text) is due to the text “Overleaf” being too big to fit in an`\hbox`

that is only 5mm wide—and, in addition, there are no available glues capable of absorbing the excess width. TEX classifies box 104 as an “overfull” box and sets`\badness`

to the special value of 1000000.

#### Related commands

TEX provides a number of commands related to reporting and displaying the badness of boxes:

## Overleaf guides

- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides

## LaTeX Basics

- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors

## Mathematics

- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning Equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts

## Figures and tables

- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package

## References and Citations

- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles

## Languages

- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish

## Document structure

- Sections and chapters
- Table of contents
- Cross referencing sections and equations
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks

## Formatting

- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes

## Fonts

## Presentations

## Commands

## Field specific

- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typing exams in LaTeX
- Knitr
- Attribute Value Matrices

## Class files

- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class
- Tips