LaTeX: new 'fontpkgmath' key of latex_elements, use unicode-math
Feature or Bugfix
all three of
- Feature: improve the looks of math in PDF, with xelatex and lualatex, and as a side-effect from using unicode-math with them, math can be copied from PDF as Unicode characters,
- Bugfix: fixes #12714
- Refactoring: move
\usepackage{amssymb}a bit later in preamble. Do not use if for Unicode engines.
Relates
- #2290, #2348. The problems there made necessary to use
amssymbbut to load it earlier than the contents oflatex_elements['fontpkg']which could for example useunicode-math. This potential conflict is solved in another way by this PR.
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.
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)
With this PR and xelatex engine
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.
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.