Documentation
¶
Index ¶
Constants ¶
const InfPenalty = 10000.0
InfPenalty is the "infinite" penalty: +InfPenalty forbids a break, −InfPenalty forces one (the end of a paragraph is a forced break).
const MaxBadRatio = 1e4
MaxBadRatio is the worst finite badness ratio the optimiser will consider: a line that is underfull with no stretch at all. Callers pass it as the tolerance for a last-resort pass that must return SOMETHING rather than fail. MaxBadRatio caps the adjustment ratio of a short line that has no stretch (the worst finite badness): the line is very bad but still finite, so an emergency pass with a large tolerance can accept it instead of collapsing the whole paragraph onto one line.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct {
Kind ItemKind
Width float64
Height, Depth float64 // box only (glyph metrics)
R rune // box only (the glyph, 0 if none)
Stretch, Shrink float64 // glue only
Penalty float64 // penalty only
Flagged bool // penalty only (e.g. a hyphen) — consecutive flags are penalised
}
Item is one element of a horizontal list.
type Line ¶
type Line struct {
Start, End int // item index range [Start, End) actually set on the line
Ratio float64 // glue adjustment ratio r (−1 fully shrunk … +tolerance stretched)
}
Line describes one output line of a broken paragraph.
func KnuthPlass ¶
KnuthPlass breaks items into lines of the given width, minimising total cost (linePenalty is charged once per line, which discourages breaking a paragraph into many short ones). It returns the chosen lines in order and ok=false if no sequence of feasible breaks exists within tolerance.
type Params ¶ added in v1.1.0
type Params struct {
Tolerance float64 // \tolerance: the worst BADNESS a line may have (100·ratio³)
LinePenalty float64 // \linepenalty: charged once per line, so fewer lines cost less
AdjDemerits float64 // \adjdemerits: adjacent lines two fitness classes apart
DoubleHyph float64 // \doublehyphendemerits: two hyphenated lines in a row
FinalHyph float64 // \finalhyphendemerits: a hyphen on the last line but one
// FinalPass turns on TeX's last resort: artificial_demerits.
//
// ⛔⛔ WITHOUT IT AN OVERFULL SINGLE LINE BEATS TWO INFEASIBLE SHORT ONES, and TeX
// chooses the other way. tex.web §16769-16771: the deactivation at an impossible
// line is guarded by "and |goto deactivate| UNLESS there is a reason to consider
// lines of text from |r| to |cur_p|", and the reason is
//
// if final_pass and (minimum_demerits=awful_bad) and
// (link(r)=last_active) and (prev_r=active) then
// artificial_demerits:=true {set demerits zero, this break is forced}
// else if b>threshold then goto deactivate;
//
// — when nothing feasible has been recorded at this breakpoint and r is the ONLY
// active node, the break is recorded at ZERO cost. Zero is what makes it win:
// badness past inf_bad costs 1e8 per line, so two hopeless lines (2e8) otherwise
// lose to one overfull line (1e8).
//
// Measured in go-tex/engine: two unbreakable 35pt words with a 3pt rigid space on
// a 40pt measure. Neither line can be set — each is 5pt short with nothing to
// stretch — and the reference puts them on TWO lines. Without this flag the
// breaker returned ONE line 33pt over the margin, because it cost half as much.
//
// It is the caller's business because the PASSES are: \pretolerance, then
// \tolerance, then the emergency pass. Only the last one may fall back, and only
// the caller knows which pass it is running.
FinalPass bool
}
Params carries the costs TeX charges besides the line's own badness. The zero value is not useful; DefaultParams holds the values every LaTeX document runs with (latex.ltx:498-514).
func DefaultParams ¶ added in v1.1.0
DefaultParams are LaTeX's own settings (latex.ltx:498-514): \tolerance=200, \linepenalty=10, \adjdemerits=10000, \doublehyphendemerits=10000, \finalhyphendemerits=5000.