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

LaTeX: new 'fontpkgmath' key of latex_elements, use unicode-math #12753

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jfbu
Copy link
Contributor

@jfbu jfbu commented Aug 9, 2024

Feature or Bugfix

all three of

Relates

I have for a very long time being perhaps too much procrastinating usage of unicode-math with Unicode engines. Work on SymPy project forced me to invest some more time into this and obtain a correct way to use it. Alas, one should not think using it as per what you will find on LaTeX discussion groups is actually the good way for Sphinx, in particular because we must make sure that HTML+MathJax renders the same for the same input.

@jfbu jfbu added this to the 8.x milestone Aug 9, 2024
CHANGES.rst Outdated Show resolved Hide resolved
Comment on lines +19 to +20
texlive-unicode-math [platform:rpm]
texlive-xits [platform:rpm]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it seems all are "subpackages" of texlive which we require earlier in this bindep.txt for Fedora, see also here, so I am not sure we really need this and/or any of the other lines.

As per Ubuntu, unicode-math is part of texlive-latex-recommended, and XITS Math of texlive-fonts-extras which we both require already.

sphinx/builders/latex/constants.py Outdated Show resolved Hide resolved
sphinx/builders/latex/constants.py Show resolved Hide resolved
@jfbu
Copy link
Contributor Author

jfbu commented Aug 9, 2024

I had prepared some screenshots which I almost forgot to post:

Currently with xelatex engine (and very similar with pdflatex engine, except that the bold Gamma 𝚪 in last displayed equation would show and not a boxed question mark)

Capture d’écran 2024-08-09 à 11 36 10

With this PR and xelatex engine

Capture d’écran 2024-08-09 à 11 43 20

EDIT: the "bad match of math with text" in upper screenshot is most visible on letters such as \delta, and would be more obvious if massive usage of lowercase Greek was done. In fact the Knuth math fonts Latin and Greek especially are much thinner than Times-like text font, and they don't have compatible metrics.

Copy link
Contributor Author

@jfbu jfbu left a comment

Choose a reason for hiding this comment

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

Due to reasons of stix2 being basically unmaintained and having some bugs, it may be more reasonable to only provide some advice on how to possibly use it but not make it the default for Sphinx with 'pdflatex'. Users of Sphinx making intensive use of math mode will be advised to use 'xelatex' rather. Which raises other issues because it is known there are some problems with math mode with 'xelatex' and also 'xelatex' does not look to be actively maintained nowadays;

CHANGES.rst Outdated Show resolved Hide resolved
doc/latex.rst Outdated Show resolved Hide resolved
doc/latex.rst Outdated Show resolved Hide resolved
Comment on lines +90 to +97
% Make subscripts a bit larger for legibility
\def\defaultscriptratio{.8}
\def\defaultscriptscriptratio{.6}
\DeclareMathSizes{9}{9}{7}{5}
\DeclareMathSizes{\@xpt}{\@xpt}{8}{6}
\DeclareMathSizes{\@xipt}{\@xipt}{8.76}{6.57}
\DeclareMathSizes{\@xiipt}{\@xiipt}{9.6}{7.2}
\DeclareMathSizes{\@xivpt}{\@xivpt}{11.52}{8.64}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This brings legibility benefits. When time will come at Sphinx 9 for using stix2 in place of amssymb for pdflatex engine, these settings will be re-used probably identically and are then completely necessary to work around some obvious rendering problems with stix2 such as stipub/stix_type1#4.

doc/latex.rst Outdated

- ``r'\usepackage{unicode-math}'`` for ``'xelatex'`` and ``'lualatex'``
with extras to set the math font to XITS Math (which is an excellent
match to FreeSerif text font). It also makes mark-up such as
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually in my testing XITS Math digits and upright Latin letters are quasi-identical with those of FreeSerif (I can not discern any difference visually).

Capture d’écran 2024-08-10 à 09 05 23

(character boxes widths may differ slighly for example for letter f and kerning differs due to XITS Math being a math font not a text font).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, upright XITS Math is used only in operator names, and having exactly identical glyphs with text is not extremely important, what is important is that the weight of the XITS Math glyphs for example for Greek is much better fitted to text.

Compare with this PR:
Capture d’écran 2024-08-10 à 09 18 21

and without this PR:
Capture d’écran 2024-08-10 à 09 18 01

@jfbu
Copy link
Contributor Author

jfbu commented Aug 21, 2024

An alternative to XITS Math (which is now frozen and will not change, and was a fork of STIX fixing a number of problems) might be with STIX Two Math. But it has seemingly no bold weight variant. So one has to use additional declarations with fontspec using FakeBold feature (page 31 of its 2024/05/11 v2.9e manual). No idea if this is acceptable. There might be in the TeX literature some article describing status of these packages. Unfortunately in LaTeX world documentation is rarely up-to-date, and internet has tons of completely outdated things. Even the recently released LaTeX Companion 3rd edition by core LaTeX maintainers is very very classical, documenting packages from 30 to 10 years ago and not much among those from last 10 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant