Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(math): Math font size must follow the document font size #2149

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/math/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ function package.declareSettings (_)
})
SILE.settings:declare({
parameter = "math.font.size",
type = "integer",
default = 10,
type = "number or integer",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider whether we ought to allow relative values here such that formulas would track changes to the document font size in a relative way.

default = SILE.settings:get("font.size"),
})
SILE.settings:registerHook ("font.size", function (size)
-- Follow document font size changes
SILE.settings:set("math.font.size", size)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do allow a relative value (e.g. 1.2em) then this would need to adjust to compute the difference (or just not change it at all, but we would have to review if we are using :absolute() where necessary) not just hard code a value.

Even if not, we probably want to figure out how to remove this hook if the user resets font.size after having set math.font.size at any point.

Copy link
Member Author

@Omikhleia Omikhleia Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW there's a whole lot of issues hiding behind math.font.size eventually.

Consider legit MathML <mpadded width="3em" lspace="0.7em">...</mpadded> = the unit is evaluated with respect to font.size but math.font.size might have been the intent... The MathML spec is not very precise here (it's even unclear whether the scale-down should be taken into account.) (N.B. Basic mpadded support is in-progress in #2151)

My guts feelings (after I hit the problem under a different angle in mpadded) is that math.font.size should always be in a font relative unit, and affect font.size inside the math equation.
Or should be wholly dimissed - after all we don't really do such things for verbatim/monospace fonts either, and the question of scaling appropriately different fonts is more general (= on which basis? em-size ? ex-height ? capital-height? etc.) - CSS has some good pointers here, for once.

end)
-- Whether to show debug boxes around mboxes
SILE.settings:declare({
parameter = "math.debug.boxes",
Expand Down
5 changes: 5 additions & 0 deletions tests/feat-math-display-numbered.sil
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
\use[module=packages.lorem]
\use[module=packages.math]
\font[size=11pt]
% Side effect of #2145: the math font size now follow the current document
% font size, so whould now be 11pt.
% The previous behavior was an hard-coded 10 pt.
% Restore it here, so the test passes unchanged.
\set[parameter=math.font.size, value=10]
% Test numbered display math for all options
% and in all alignments

Expand Down
5 changes: 5 additions & 0 deletions tests/feat-math-display-unnumbered.sil
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
% and in all alignments

\begin{blockquote}
% Side effect of #2145: the math font size now follow the current document
% font size, so whould now be some ratio of 11pt (due to the blockquote)
% The previous behavior was an hard-coded 10 pt.
% Restore it here, so the test passes unchanged.
\set[parameter=math.font.size, value=10]
Begin justified
\math[mode=display]{e^{i\pi} = -1}
End justified.
Expand Down
Loading