Discretionary break 2026-11-05
A discretionary break describes an optional line breaking choice whose printed material may depend on whether the break is selected. In TeX,
\discretionary{pre}{post}{none} supplies material before a chosen break, after it, or in the unbroken case.[ref]TeX source code by Donald E. Knuth. disc_node: pre_break, post_break and replacement material
For a purely mechanical example,
ab\discretionary{-}{X}{Y}cd can produce abYcd without the break, or ab- followed on the next line by Xcd when it is selected. The arbitrary strings make all three branches visible. A common hyphenation case simply inserts a hyphen before the break and supplies no material afterward.Each alternative has its own geometry. A typesetting box used only in the pre-break branch must contribute its width when that branch is tested. The natural line width, typesetting glue and typesetting penalty calculation must therefore use the selected representation. Treating the choice merely as an invisible marker could miss the width of the inserted hyphen.
Knuth-Plass line-breaking algorithm 2026-11-05
The Knuth-Plass line-breaking algorithm chooses paragraph breaks using dynamic programming over a representation of the material as typesetting boxes, typesetting glue and typesetting penalties. Boxes supply unbreakable widths; glue supplies normal spacing together with stretch and shrink allowances; penalties express preferences about permitted breaks and can account for a hyphen added when a break is taken.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1119–1122, summary and formulation
Text justification makes the glue geometry useful. In an illustrative line, suppose box widths total 24 and two glues each have normal width 3 and stretch allowance 2. To fill width 32, the line adjustment ratio isEach glue then becomes , giving . This example demonstrates proportional stretching; it is one ingredient of paragraph optimization.
The dynamic programming state retains information needed to score later choices. In particular, a line-breaking fitness class records a spacing category, allowing an abrupt change between neighbouring lines to affect the cost. Break position alone would discard that relevant history. The original active nodes include line number and fitness class, with the best accumulated demerits stored as their value.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1158–1159, active nodes, line numbers and fitness classes
The line breaking with squared slack cost example isolates break selection with fixed word spacing. Here, adjustable typesetting glue and typesetting penalties participate in the paragraph optimization. Donald E. Knuth and Michael F. Plass's 1981 paper documents the method and its development in the TeX project.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1175–1176, authors' historical account
LaTeX 2026-11-05
LaTeX is a document preparation system built on TeX technology. It lets an author specify structure such as sections and references while reusable definitions control presentation. Its facilities support mathematical typesetting, figures, bibliographies and cross-references.[ref]
An introduction to LaTeX by the LaTeX Project. Introduction and LaTeX Features: document structure and scientific publishing
For example, a minimal mathematical article can contain
\documentclass{article}\begin{document}$x^2+1$\end{document}. The source describes the document class and content; the selected LaTeX definitions and computer fonts help determine the resulting geometry. The same separation lets one change a document's design while retaining its logical section structure.Leslie Lamport developed the system; his LaTeX: A Document Preparation System by Leslie Lamport is listed in his bibliography as an Addison-Wesley publication from 1986.[ref]
LaTeX: A Document Preparation System by Leslie Lamport. Author’s bibliography, entry 69: title and 1986 publication
A TeX format makes the system's definitions available to a compatible TeX implementation. Line-breaking fitness class 2026-11-05
A line-breaking fitness class is a coarse description of how tightly or loosely a line is spaced. The Knuth-Plass line-breaking algorithm distinguishes tight, normal, loose and very loose lines. A transition between sufficiently different classes adds typesetting demerits, even when each line's own spacing is individually acceptable.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. p.1155: four fitness classes and penalties for contrasting adjacent lines
For example, imagine one feasible line has line adjustment ratio and the next has . One compresses its spaces substantially, while the other expands them. That contrast can be more conspicuous than two lines with similar spacing. A paragraph objective can express this using an added termwhere indexes the classes. The indicator function adds the charge only for a sufficiently large class change.
Consequently, the dynamic programming state needs the previous fitness information. Suppose two routes to the same break cost 10 and 12, but the cheaper route's class would add a transition charge of 5 to the next line while the other adds none. Their relevant totals become 15 and 12: discarding the second route solely because would be premature. The principle of optimality applies to states that retain the information the future cost needs.
TeX computes its categories using integer typesetting badness thresholds and handles special glue cases explicitly. Its implementation should therefore be consulted for exact boundary behaviour rather than inferring it from rounded decimal adjustment ratios.[ref]
TeX source code by Donald E. Knuth. try_break: fit_class, badness thresholds 12 and 99, and adj_demerits
Mathematical delimiter 2026-11-05
A mathematical delimiter is a symbol used to enclose or separate parts of a mathematical expression, such as parentheses, brackets or vertical bars. Its visible size should suit the enclosed material. Mathematical typesetting can select a larger mathematical glyph variant or construct a mathematical glyph assembly when a default glyph is too small.[ref]
MATH - The Mathematical Typesetting Table by Microsoft. MathVariants and MathGlyphConstruction: ready-made variants and assemblies for growing shapes
For example, compare the grouping inThe parentheses enclose the complete typeset fraction, so its height and depth inform their layout. The superscript applies to the grouped expression. In TeX,
\left( and \right) request paired size-sensitive delimiters around the enclosed material. The stored parenthesis characters can therefore yield different glyphs in different formula contexts. Mathematical typesetting 2026-11-05
Mathematical typesetting arranges symbolic expressions in two dimensions. It must coordinate computer fonts, glyph positioning, typesetting boxes and text baselines while preserving the expression's visible structure. A typeset fraction positions its components above and below a bar; superscripts, subscripts, square roots and mathematical delimiters impose other geometric relationships.[ref]
MATH - The Mathematical Typesetting Table by Microsoft. Overview: hierarchical formulas, recursive layout and component boxes
For example,contains a superscript inside the upper component and a square root inside the lower component. Their dimensions help determine the height of the complete typeset fraction. A larger expression may then require larger surrounding mathematical delimiters. Laying out the smallest parts first makes this a recursive geometric construction.
An OpenType MATH table supplies font-specific information such as placement constants and suitable glyph variants. The table supplies data for layout; different implementations can use those data in different algorithms. TeX and LaTeX provide established authoring systems for expressing such mathematical structure.[ref]
MATH - The Mathematical Typesetting Table by Microsoft. Overview and MATH table structures: font data rather than a complete layout algorithm
Mathematical typesetting style 2026-11-05
A mathematical typesetting style selects layout conventions appropriate to a formula's context, including compact inline material and more spacious displayed material. In MathML,
math-style distinguishes normal and compact, while math-depth participates in nested size selection.[ref]Compare two presentations of the same expression:Both represent the same quotient, but reserve different vertical space. In TeX,
\displaystyle and \textstyle request these contexts. The choice matters when fitting a typeset fraction into a line without making neighbouring text baselines unnecessarily far apart.For a hypothetical computer font with first- and second-level script scales 80 and 60 percent, a base font size of 20 units gives script sizes 16 and 12. The second value is relative to the base, so it is not . Actual percentages come from the computer font's mathematical font constants.[ref]
MathML Core by World Wide Web Consortium. §4.5: ScriptPercentScaleDown and ScriptScriptPercentScaleDown
Michael F. Plass 2026-11-05
Michael F. Plass is a computer scientist whose work connects typography with mathematical optimization. With Donald E. Knuth, he coauthored the 1981 paper that describes the Knuth-Plass line-breaking algorithm: choosing breaks for an entire paragraph with dynamic programming, allowing later text to influence earlier choices. The original byline places both authors in Stanford University's Computer Science Department.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. Page1119: original byline, affiliation and summary
The authors' historical account credits Michael F. Plass with introducing feasible breakpoints into the developing algorithm in summer 1977, reducing the active possibilities considered. They report its implementation in the first complete version of TeX in March 1978. These dates describe the development of the method, rather than the later publication date.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. Page1176: feasible-breakpoint refinement and implementation chronology
An illustrative spacing calculation shows one ingredient of the model. Suppose fixed boxes total 24 width units and two spaces each have normal width 3 and stretchability 2. Their natural total width is 30. For a target width of 32, the adjustment ratio is ; each space becomes , giving . This original numerical example shows proportional stretching, before the paragraph-wide choice of breaks.
The full method also represents break preferences with penalties and accounts for relevant relationships between successive lines. Line breaking with squared slack cost is a useful simpler model for understanding global choices, while the published Knuth-Plass line-breaking algorithm handles adjustable spacing and additional preferences.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. Pages1121–1122: boxes, glue and penalties; pages1158–1159: active-node state
Plain TeX 2026-11-05
Plain TeX is Donald E. Knuth's foundational collection of TeX macros, parameters and conventions, described in The TeXbook by Donald E. Knuth. It makes a usable document interface from the lower-level facilities of TeX.[ref]
Plain TeX in the Comprehensive TeX Archive Network. Official package description: format-building files and relation to The TeXbook
For example,
$x^2+1$\bye requests an inline mathematical expression and ends the document. The \bye macro handles paragraph completion and final output before ending the run.[ref] The example uses the format's existing definitions together with TeX primitives and mathematical typesetting rules.Plain TeX is useful when studying how relatively small definitions control layout. LaTeX provides a different TeX format with more document-level structure. Choosing a format determines which definitions an input file can expect to find already loaded.
Subscript 2026-11-05
A subscript is a component placed below the usual baseline of a base expression, commonly at a smaller size. It can label a term of a sequence, as in , or identify a matrix entry, as in . Its position does not by itself determine the mathematical meaning of the label.
In TeX,
x_i attaches a single-token subscript, while x_{i+1} groups a compound subscript. In MathML, msub supplies a base and subscript as separate children. Their layout uses baseline shifts and clearances rather than putting both components on the ordinary text baseline.[ref]MathML Core by World Wide Web Consortium. Subscripts and superscripts: msub child layout and shift calculations
For example, keeps together as one attached component. A mathematical typesetting style controls the treatment of the smaller expression. An OpenType MATH table can supply the font-specific placement data. This is why adding an underscore as an ordinary printed glyph would not reproduce the layout.
Superscript 2026-11-05
A superscript is a component raised relative to a base expression, commonly also reduced in size. An exponent in is one use. The superscript in can instead denote a derivative when that convention has been specified. The typographic position supports several meanings.
In TeX,
x^2 supplies one token as the superscript and x^{n+1} groups a longer expression. In MathML, msup lays out the base and superscript separately, with vertical placement and gap constraints.[ref]MathML Core by World Wide Web Consortium. Subscripts and superscripts: msup layout
For example, the base and raised expression inhave different local baselines. A mathematical typesetting style determines how the raised expression is presented. When subscripts and superscripts are both attached, their mutual clearance also matters; independently moving each one without considering the other could cause a collision. An OpenType MATH table provides font-specific data used for these choices.
TeX character code 2026-11-05
A TeX character code is the numerical component identifying a character in TeX's character model. An ordinary character TeX token combines that code with a TeX category code. Classic TeX uses an eight-bit character-code range, 0–255.[ref]
TeX format 2026-11-05
A TeX format is a prepared collection of definitions and initialization state used with TeX. A TeX format file, conventionally ending in
.fmt, stores internal structures so they can be loaded efficiently instead of reconstructed from the original initialization input.[ref]Plain TeX supplies one such foundation; LaTeX supplies another, with document-level conventions and facilities. The same mathematical input
$x^2$ can be embedded in either system, but an authoring command defined by one format need not be available in the other.Keeping the layers separate helps diagnose a failed document. The TeX implementation provides TeX primitives; the format makes further TeX macros and defaults available; a document invokes those definitions. Loading a different format can change the meaning or availability of commands without changing their spelling in the input file.
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]
TeX source code by Donald E. Knuth. Input stacks: mid_line, skip_blanks and new_line; get_next whitespace cases
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]TeX source code by Donald E. Knuth. Cases where character is ignored; Handle situations involving spaces, braces, changes of state
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.
TeX parameter token 2026-11-05
A TeX parameter token marks an argument position in a TeX macro definition. With ordinary category assignments,
#1 through #9 name the available positions. During TeX expansion, the supplied argument tokens replace the corresponding placeholders.[ref]For an original example,
\def\twice#1{#1:#1} followed by \twice{ab} expands to ab:ab. The braces delimit one argument containing two character tokens; they are not copied into the replacement at each placeholder. Calling \twice7 instead gives 7:7. Thus #1 identifies an argument slot rather than instructing TeX to print the digit 1.The definition's replacement list can be inspected before execution. Its placeholders remain distinct from ordinary digit tokens, even when an actual argument happens to be a digit. This separation makes token substitution useful for reusable notation.
TeX primitive 2026-11-05
A TeX primitive is an operation supplied by TeX itself, such as defining a TeX macro, changing a register or constructing a typesetting box. A TeX control sequence can name a primitive or a macro. The distinction concerns the current meaning of the command, rather than the appearance of its name.[ref]
For example,
\hbox constructs a horizontal typesetting box. The assignment \let\mkbox=\hbox gives another name to its current meaning. Defining a macro with \def\label{sample} creates a replacement list instead. Some primitives participate in TeX expansion, while others perform operations during later processing; primitive does not mean unexpandable. This distinction helps explain why a command can appear in an expansion trace without immediately drawing a glyph. TeX token 2026-11-05
A TeX token is an internal syntactic unit used by TeX. Ordinary character tokens pair a TeX character code with a TeX category code; TeX control sequence tokens identify commands. Macro processing also uses TeX parameter tokens.[ref]
For example, an
a read with category 11 and an a read with category 12 are different character tokens, even though both can select the same printed glyph in ordinary text. Changing a category assignment later does not retokenize a previously stored TeX macro replacement list. A stored control-sequence token can, however, acquire a different current meaning through redefinition.The TeX input processor performs the relevant lexical analysis. The later TeX expansion stage operates on the resulting tokens. This separation explains why changing the spelling of input and changing the meaning of an existing command are different operations.
Text paragraph 2026-11-05
A text paragraph is a group of text treated as one unit for paragraph layout. Its line breaking may change when the available typesetting line width or computer font changes, while its underlying paragraph boundary remains the same. A line in the source file therefore need not be a line of displayed output.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §3: white-space processing, wrapping and preserved versus collapsed segment breaks
For example, a sequence of four typesetting boxes may occupy two lines in a narrow container and one line in a wider container. Reflow changes the grouping of boxes without requiring a new paragraph. In TeX,
\par ends the current paragraph; in HTML, a p element marks a paragraph. Those mechanisms let the layout system work with a semantic group instead of relying on the writer to insert each visible line break.The Knuth-Plass line-breaking algorithm uses this grouping to compare costs across the whole paragraph. Its typesetting demerits can depend on both individual lines and changes between neighbouring lines, which cannot be evaluated by inspecting each source line in isolation.
Typesetting badness 2026-11-05
Typesetting badness scores the spacing strain needed to fit a line. For ordinary finite stretch or permitted finite shrink, a useful smooth guide iswhere is the line adjustment ratio. Doubling the required ratio multiplies this guide by eight, so it strongly penalizes large adjustments. The convex function on nonnegative ratios rewards more evenly distributed spacing strain.
TeX computes an integer approximation with saturation rather than evaluating that real-valued expression exactly. With stretch coefficient in the routine's internal units, excess widths give ratios and routine outputs . In particular, the first differs from the smooth guide value 12.5.[ref]
TeX source code by Donald E. Knuth. badness(t,s): fixed-point approximation, rounding constants and inf_bad; chosen input values evaluated directly
Cubic spacing cost and integer typesetting badness
. Original calculation comparing the smooth guide with TeX's badness routine at chosen finite stretch coefficients. The right panel enlarges the integer steps near r=0.5. All plotted ratios describe stretching. Details.The sentinel 10000 represents saturated badness in the routine. Excessive shrinking is tested separately in paragraph breaking; higher-order stretch has its own treatment. A paragraph's typesetting demerits also include typesetting penalties and possible neighbour-dependent charges, so choosing solely by badness can miss the best layout.
Typesetting box 2026-11-05
A typesetting box is a piece of material treated as one unbreakable item at a given stage of line breaking. The simple paragraph model assigns it a width. A word already assembled from glyphs, or a small diagram placed within text, can be represented by such an item.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1123–1125: boxes as rigid-width items
For example, three boxes of widths 8, 6 and 10 separated by two spaces of width 3 occupy . Keeping the boxes fixed while changing only the spaces is the model used by typesetting glue. If hyphenation makes an internal split available, the word must instead be represented with that discretionary break; a single indivisible box would hide the choice.
A box's width describes layout advance, which need not equal the exact ink extent of its glyphs. A more complete TeX box also has height and depth relative to a text baseline. These measurements allow boxes to be combined while maintaining baseline geometry.[ref] The CSS box model uses its own rules for content, padding, borders and margins; interpreting every CSS box as an indivisible paragraph item would lose those distinctions.
