frontend: centre the display formula, and let one be set left or right
Display formulas were sitting against the left margin with only their number at
the right, and the cause was a rule I had written myself: the paragraph's
stylesheet set `text-align: left` on `.katex`, which is the very element KaTeX
centres a display formula in. A well-meant attempt to keep a formula from being
justified apart had quietly overridden the centring, and it applied to every
formula in every paper — measured on a paragraph of known width, the formula's
midpoint sat 607px left of centre.
The override is gone; the rule carries only a font size now, and a comment says
why nothing about alignment belongs there.
`paper_sentence.formula_align` then adds the choice the writer asked for: a
display formula can be `center` (the default, and what a paper wants almost
always), `left` or `right`. It is per sentence rather than a template-field
setting — one paragraph legitimately mixes a centred equation with a
right-aligned continuation, and a field describes a heading, not a formula — and
the paragraph editor offers it only on rows that contain display maths, since
only those have a line of their own. The equation number is untouched: `\tag{1}`
prints against the right margin in all three cases, as every numbered style
does.
Measured in the browser on a 1276px paragraph: centred puts the formula 596px
from each edge, left puts it at 0, right puts it at 1225, and the tag is at the
right in every case. 56 paper checks (2 new: the round trip and the refusal of
an alignment the renderer does not know), 61 reference checks, 99 MCP checks,
`vue-tsc` and the build all pass.
This commit is contained in:
+14
-3
@@ -701,11 +701,22 @@ Four delimiters are recognised, because a writer's habit decides which they use:
|
||||
`$$…$$` and `\[…\]` for display, `$…$` and `\(…\)` for inline. An unmatched
|
||||
`$` is left alone rather than swallowing the rest of the paragraph.
|
||||
|
||||
Two rules are worth knowing when reading the renderer:
|
||||
Three rules are worth knowing when reading the renderer:
|
||||
|
||||
- **A display formula is a block.** It takes its own line whether or not the
|
||||
sentence asked for a break, because that is what "display" means — so the
|
||||
formulas in a paper sit centred on their own lines with no extra flagging.
|
||||
sentence asked for a break, because that is what "display" means.
|
||||
- **It is centred, and its number is at the right margin.** `\tag{1}` prints the
|
||||
number against the right edge of the block while the formula stays centred —
|
||||
the layout every numbered style uses. `paper_sentence.formula_align` moves the
|
||||
*formula* (`left` / `center` / `right`), never the number, and it is a
|
||||
per-sentence field rather than a template-field setting: one paragraph
|
||||
legitimately mixes a centred equation with a right-aligned continuation, and a
|
||||
field describes a heading, not a formula.
|
||||
- **A `text-align` on `.katex` is a trap.** KaTeX centres a display formula in
|
||||
that very element, so a well-meant `text-align: left` in the paragraph's
|
||||
stylesheet overrides it and every formula in the paper sits against the left
|
||||
margin with only its number at the right. That is exactly what happened here;
|
||||
the rule now carries only a font size.
|
||||
- **KaTeX never throws.** `throwOnError: false` renders a formula it cannot read
|
||||
as its own source in red, so one typo shows itself instead of blanking the
|
||||
paragraph the writer is looking at. Text segments are escaped before they go
|
||||
|
||||
Reference in New Issue
Block a user