First-line indentation 2026-11-05
First-line indentation shifts the beginning of the first formatted line of a text paragraph relative to its normal starting edge. In a left-to-right layout, a positive indent reserves space on the left; the corresponding starting edge is on the right in a right-to-left layout. In CSS, text-indent controls this placement.[ref]
In a simple left-to-right column of width with indentation , the first line begins at and has available typesetting line width . Later lines can begin at and use all 40 units. A negative indent instead places the start at , extending into the margin if no other layout constraint intervenes.
This changes the first line's geometry without adding printable glyphs. Replacing the indent by several stored spaces would couple the result to word spacing, white-space processing and the chosen computer font. A line breaking model can represent the change explicitly through its sequence of typesetting line widths.
Hyphenation 2026-11-05
Hyphenation permits a word to be divided at an appropriate internal position during line breaking, usually displaying a hyphen when that division is taken. A hyphenation opportunity is a permitted choice, rather than an instruction to break every occurrence. The choice can help a narrow text paragraph fit without excessive word spacing.
A soft hyphen, Unicode U+00AD, marks such an optional position: in a suitable context, ex followed by a soft hyphen and ample can display as example on one line or as ex- followed by ample on the next. The soft hyphen normally remains invisible when no split is taken. An always-visible hyphen already present in the word has different display behaviour.[ref]
In CSS, hyphens: manual uses explicit opportunities; hyphens: auto also permits opportunities supplied by a resource for the text's known language. The hyphenation resource and the line breaking algorithm answer different questions: where a split is linguistically allowed, and which allowed split best fits the layout. A discretionary break can also account for material inserted or replaced at the chosen split.[ref]
Non-breaking space 2026-11-05
A non-breaking space is a separating character intended to keep adjacent text together during ordinary line breaking. The common Unicode character is U+00A0 NO-BREAK SPACE. It has line-break class GL; the surrounding rules determine which boundaries are prohibited.[ref]
For an example, 25\u00a0µm is a visible spelling of an escape notation for a number, U+00A0, and a micrometre symbol. The actual text 25 µm keeps the number and unit together at that separator. Ordinary 25 µm instead uses U+0020 SPACE and can provide a wrap opportunity there. Neither choice fixes the physical width of the gap in every computer font.
The rule is local. In the sequence A\u0020\u00a0B, a break after the ordinary space can still be allowed, leaving the non-breaking space on the following line. Thus inserting U+00A0 does not make an entire text paragraph unbreakable.[ref]
TeX 2026-11-05
TeX is Donald E. Knuth's programmable system for typography, particularly mathematical typesetting. A document supplies text and instructions; TeX macros and TeX primitives build material whose dimensions determine the eventual page layout. Computer fonts supply glyphs and font metrics, while line breaking selects how a text paragraph is divided. The Knuth-Plass line-breaking algorithm is one of the system's central layout methods.[ref]
A TeX format supplies a prepared collection of definitions. Plain TeX and LaTeX provide different document interfaces built on TeX technology. For example, in Plain TeX the input $\sqrt{2}$\bye requests a square root expression, , and ends the document. The computer font, glyph positioning and mathematical typesetting rules determine the printed geometry; the source characters alone are not a picture of the result.
The TeXbook by Donald E. Knuth is the system's user and reference manual. TeX source code by Donald E. Knuth exposes the implementation as a documented computer program, making the paragraph algorithm and its numerical conventions inspectable.[ref]
TeX input state 2026-11-05
A TeX input state is the N, S or M state used by the TeX input processor while reading character input: new line, skipping blanks or middle of line. It helps determine whether a space or end-of-line character becomes a TeX token.[ref]
Assume ordinary TeX category codes. In N, leading spaces are ignored. An ordinary letter emits its character token and enters M. The first space in M emits one space token and enters S; further spaces in S are ignored. An end-of-line character emits a space from M, emits \par from N and emits nothing from S. The next line starts in N.[ref]
For an original trace, take a line containing two leading spaces, A, three spaces and B, followed by a space-only line. The first two spaces disappear in N. A enters M; one space survives and the next two disappear in S; B returns to M. The first line end supplies another space. The blank line then supplies \par. The resulting sequence is A, space, B, space, \par.
Thus source whitespace is processed before word spacing and text paragraph layout. This state records part of scanning, not whether TeX is currently building a text line or a mathematical formula; TeX control sequences, comments and changed TeX category codes have further scanning rules.
Typesetting demerit 2026-11-05
A typesetting demerit is a contribution to the paragraph cost minimized by the Knuth-Plass line-breaking algorithm. It combines spacing quality with break preferences and, when applicable, costs involving neighbouring lines. Thus typesetting badness is one input to the cost rather than the entire objective.[ref]
Consider the ordinary finite-penalty case in TeX, away from its integer saturation and recovery cases. Let be the TeX line penalty, the typesetting badness and the typesetting penalty, with and . The base contribution is
Charges for incompatible line-breaking fitness classes or consecutive hyphenated lines can then be added.
For an illustrative choice , and , the base is . Changing only to gives . If an adjacency charge of 100 applies, those become 1025 and 975. These are chosen example parameters, not asserted defaults.
Dynamic programming compares accumulated costs while retaining the dynamic programming state needed by future charges. The lowest-cost break considered alone need not produce the lowest-cost complete text paragraph.
Typesetting line width 2026-11-05
The typesetting line width is the horizontal measure that a layout assigns to a particular line. It supplies a target for text justification and a fitting constraint for line breaking. Write it as when it can depend on line number . The Knuth-Plass line-breaking algorithm permits a sequence of target widths, rather than requiring the entire text paragraph to be rectangular.[ref]
For example, suppose a text column is 40 units wide and first-line indentation reserves 10 units on its first line. Then
With a fixed gap of width 2, three typesetting boxes of widths 12, 10 and 8 use units. They exceed the first line's available width, although they fit a later line in the fixed-space model. When typesetting glue can shrink, feasibility must also account for that permitted shrinkage.
Width and line height measure different directions. Changing the font size can alter both the widths of the typesetting boxes and their vertical metrics, so preserving the same column width does not preserve the same breaks.
Typesetting penalty 2026-11-05
A typesetting penalty expresses how desirable a candidate break is. In the Knuth-Plass line-breaking algorithm's paragraph representation, a penalty item can also have a width that is included only if that break is taken. This lets the model account for a hyphen introduced by hyphenation without printing it in the unbroken word.[ref]
For example, suppose the material before an optional break uses 29 units and taking the break introduces a hyphen of width 2. At a typesetting line width of 30, the broken line needs units before any permitted adjustment of typesetting glue. Testing only the pre-hyphen width would wrongly declare it a fit. A finite penalty can discourage a break while still leaving it available when other choices are worse.
In TeX, values prohibit a penalty break and force it. Intermediate positive values discourage and negative values encourage it. These are control conventions of the implementation, not physical lengths.[ref]
The penalty value is an input to the typesetting demerit calculation. It is not the entire paragraph cost: typesetting badness, line-breaking fitness classes and consecutive hyphenated breaks can contribute too. Comparing two penalties alone therefore cannot choose the best text paragraph layout.