Repository navigation
Keep formulas in one line - #428
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-blockto all elements with the classkatex. 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 havedisplay: 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)
After (1)
The formula$Hom(1,0) = \{p\}$ does not break anymore:
Before (2)
After (2)
Two formulas do not break anymore.
Before (3)
After (3)
Two formulas do not break anymore.
Before (4)
This shows what happens on smaller viewports.
After (4)
The display formula, that is longer than the whole line, only breaks after the equality sign:
Before (5)
This shows what happens on smaller viewports.
After (5)
The inline formula, that is longer than the whole line, goes to its own line, and only breaks after the equality sign:
Before (6)
After (6)
The period is not isolated anymore: