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
[RFC] LaTeX: provide suitable default font configuration for XeLaTeX/LuaLaTeX #5251
Comments
Erratum: I have been confused about Latin Modern because of this
which led me believe it supported Cyrillic. This appears not be the case, and the Mac Book Font applications says:
Although "Latin" Modern is quite clear name I thought it supported Cyrillic due to some state of confusion caused by the Confirmation from an 2013 answer at tex.sx. See also the Latin Modern font page Thus currently this reduces my 2 proposals to only Computer Modern Unicode... |
Libertinushttps://ctan.org/pkg/libertinus diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py
index 40a69f1c1..a8c8a8218 100644
--- a/sphinx/writers/latex.py
+++ b/sphinx/writers/latex.py
@@ -160,7 +160,9 @@ ADDITIONAL_SETTINGS = {
'polyglossia': '\\usepackage{polyglossia}',
'babel': '',
'fontenc': '\\usepackage{fontspec}',
- 'fontpkg': '',
+ 'fontpkg': ('\\setmainfont{Libertinus Serif}\n'
+ '\\setsansfont[Scale=MatchLowercase]{Libertinus Sans}\n'
+ '\\setmonofont[Scale=MatchLowercase]{Libertinus Mono}'),
'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0'
'{\\leavevmode\\nobreak\\ }'),
'fvset': '\\fvset{fontsize=auto}',
@@ -170,7 +172,9 @@ ADDITIONAL_SETTINGS = {
'polyglossia': '\\usepackage{polyglossia}',
'babel': '',
'fontenc': '\\usepackage{fontspec}',
- 'fontpkg': '',
+ 'fontpkg': ('\\setmainfont{Libertinus Serif}\n'
+ '\\setsansfont[Scale=MatchLowercase]{Libertinus Sans}\n'
+ '\\setmonofont[Scale=MatchLowercase]{Libertinus Mono}'),
'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0'
'{\\leavevmode\\nobreak\\ }'),
'fvset': '\\fvset{fontsize=auto}', It has much wider glyph coverage than Latin Modern family. In particular it supports Cyrillic, Greek and Hebrew.
Besides, it has an accompanying OpenMath font which can be set-up with It has narrow glyphs a bit like Times font used by Sphinx with PDFLaTeX. This helps for code-blocks (long lines) and indices. It comes with TeX distributions such as TeXLive. Requires perhaps recent ones as there it was actively maintained in recent years. (edit) additional remarks:
|
I don't have strong opinion for this. But I think font is a part of design. So it would be nice if it will be provided as LaTeX-theming in future. |
0. do not escape Unicode Greek letters via LaTeX math mark-up: pass them through un-modified to LaTeX document, 1. if "fontenc" receives extra option LGR, then pdflatex will support Unicode Greek letters (not in math), and with extra option T2A it will support (most) Unicode Cyrillic letters. 2. for pdflatex with LGR, this will use "textalpha" LaTeX package and "substitutefont" package to set up some automatic font substitution to work around the unavailability of Greek with "times" package (which is default font package chosen by Sphinx for pdflatex), same with T2A and "substitutefont" for Cyrillic. 3. for xelatex/lualatex, set up Computer Modern Unicode as default font, as it supports Cyrillic and Greek scripts, 4. for platex, don't do anything special as the engine already has its default font supporting Cyrillic and Greek (even in math mode!) Closes: sphinx-doc#5251 Fixes: sphinx-doc#5248 Fixes: sphinx-doc#5247
We must take into account that our reference TeX installation on Ubuntu/Xenial via Debian texlive packages. Requirements:
Latin Modern supports only Latin, Computer Modern Unicode is not available as separate package from OpenType fonts available separately, providing Cyrillic and Greek support, and coming in Serif, Sans Serif and Monospace include:
I am probably missing some but this is what I extract from A reasonable approach could be to go for Linux Libertine, and later to switch to Libertinus which is interesting in XeLaTeX/LuaLaTeX due to acccompanying math font (if at later version |
But Linus Libertine Mono does not support Cyrillic. And Libertinus Mono does not either (at my locale TL2018). This seems to leave FreeFont and DejaVu. DejaVu is very readable on screen, very clear, FreeMono takes less place (perhaps a bit like the intent was in legacy Sphinx into using "times"), is more "aristocratic". DejaVu Serif Book FreeSerif Normal Incidentally FreeSerif has the ℇ (EULER CONSTANT U+2107) which is lacking from DejaVu Serif, but this is anecdotical I guess. I have not tested but my expectation is that the standard TeX math fonts fit better with FreeFont than with DejaVu, because they have very thin hairlines. Here is an extract of Sphinx own documentation with xelatex and FreeFont: and here with DejaVu (due to a pagebreak I could not take same snapshot). There is more equilibrium between default sizes of Serif and Mono. But With FreeFont 390 pages, with DejaVu 410 pages. But DejaVu might benefit from a bit of extra linespread ( Very close file sizes. Extract of the index (with 2.0.0+, uses monospace font for entries, and normal italic for extras) FreeFont: DejaVu: |
Although LaTeX from recent years with xelatex or lualatex uses by default Latin Modern, issue #5247 shows Sphinx should make a better default configuration of font package. Currently it makes no font choice at all.
I don't know what could be good choice. Here are two proposals:
Attention: on many systems XeLaTeX requires
\setmainfont
with filenames when the font are in the texlive repertories. I used font names below, and it worked at my locale because I have there symlinks to places XeLaTeX look at for fonts.Computer Modern Unicode
Pros: comes with any reasonable TeX installation. Provides coverage of Latin, Greek and Cyrillic scripts. It is mentioned as canonical choice in babel-russian documentation.
In future, the support of Greek could be interesting to stop Sphinx escaping Greek letters to LateX macros, which do not work in PDF bookmarks. (#5248)
Latin Modern
edit: in retrospect I should not have included this (it is already default choice of recent enough)LaTeX with XeLaTeX/LuaLaTeX) as it does not provide Cyrillic support. I was temporarily thinking loading it as below would provide Cyrillic, but this was based on confused state of mind.
Pros: comes with any reasonable TeX installation. Covers Latin and
Cyrillic(no!). Perhaps covers more European languages than Computer Modern Unicode (not sure), but these languages may not be supported by Sphinx anyhow.Cons: does not support Greek. This is not really a problem currently with Sphinx as Unicode Greek letters (without diacritics) are escaped by Sphinx to LaTeX math macro. But as mentioned above, this causes problem in PDF bookmarks (#5248)
edit
Cons:
it does NOT support Cyrillic. (Sorry for initial confusion).
also, the exact names for LM fonts have changed at least twice the in the last ten years, I do dearly hope this is stabilized now.
remarks
Whether CMU or LM, this will hardly change looks of current PDF built with Sphinx using xelatex/lualatex, the fonts look very much alike.
I am asking for people to make suggestions for alternatives or better comparison between the two choices.
Mac OS X users with xetex have the problem that XeTeX does not find the OpenType fonts in the TeXLive repertories, but only the systemwide or user fonts. Thus, one either needs to load the fonts by filenames which is cumbersome as it requires also specifying for bold and italic, besides there is the problem of taking into account the pointsize, or one can use the trick to add symlinks, but this needs special documentation: in my
~/Library/Fonts
I have symlinksThis relies on
/Library/TeX/Root
which itself is a symlink to current TeXLive install. Most Mac users use MacTeX installation, and I think it creates this/Library/TeX/Root
symlink (I used MacTeX some years ago but now install directly TeXLive; MacTeX is 99,9% same as TeXLive). But the two extra symlinks above in~/Library/Fonts
are my own trick to let XeTeX find the fonts in TeXLive tree by name.notice that the above fonts closely related to Knuth original TeX fonts are different from the times+helvetica+courier default choice made by Sphinx for pdflatex. But for some time now, Sphinx with xelatex/lualatex has let LaTeX itself decides of font and this means it uses Latin Modern. Switching to Computer Modern Unicode will keep very similar looks to document and would fix LaTeX: PDF does not build with default font config and xelatex/lualatex for Russian language #5247.
Environment info
Relates #5247, #5248
The text was updated successfully, but these errors were encountered: