Skip to content

Keep formulas in one line - #428

Merged
ScriptRaccoon merged 3 commits into
mainfrom
formulas-one-line
Oct 22, 2026
Merged

ScriptRaccoon merged 3 commits into
mainfrom
formulas-one-line

Conversation

@ScriptRaccoon

@ScriptRaccoon ScriptRaccoon commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

This PR fixes #135 by preventing line breaks inside formulas whenever possible. The implementation was done by Claude Code. The changes are best understood by the screenshots below.

The basic idea is to add display: inline-block to all elements with the class katex. As a result, a formula that does not fit into the current line moves to the next line as a whole. This only affects inline formulas, since KaTeX's own rule .katex-display > .katex { display: block } has a higher specificity.

This already fixes most of the line breaks. On smaller viewports, however, many formulas do not fit into a single line, and KaTeX still allows a line break after every binary operator (such as $+$ or $*$). To fix this, line breaks now happen only after relation symbols (such as $=$ or $\subseteq$), unless the part between two relations does not fit into a line by itself. To achieve this, the parts of a formula between two relations are now wrapped in elements with the class formula-group, which also have display: inline-block.

Another line break issue has been fixed as well: punctuation directly after a formula, as in $x$., could start a new line. It is now "glued" to the formula by moving it into the last unbreakable part of the formula, so it can no longer end up alone at the start of the next line.

Screenshots

Before (1)

1_before

After (1)

The formula $Hom(1,0) = \{p\}$ does not break anymore:

1_after

Before (2)

2_before

After (2)

Two formulas do not break anymore.

2_after

Before (3)

3_before

After (3)

Two formulas do not break anymore.

3_after

Before (4)

This shows what happens on smaller viewports.

4_before

After (4)

The display formula, that is longer than the whole line, only breaks after the equality sign:

4_after

Before (5)

This shows what happens on smaller viewports.

6_before

After (5)

The inline formula, that is longer than the whole line, goes to its own line, and only breaks after the equality sign:

6_after

Before (6)

5_before

After (6)

The period is not isolated anymore:

5_after

@ScriptRaccoon ScriptRaccoon added the feature features of the application visible to users as well as features for maintainers label Oct 22, 2026
@ScriptRaccoon
ScriptRaccoon merged commit ddabd52 into main Oct 22, 2026
4 checks passed
@ScriptRaccoon
ScriptRaccoon deleted the formulas-one-line branch October 22, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature features of the application visible to users as well as features for maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix word breaks in katex formulas

1 participant