Open LuisBL opened 7 months ago
I posted on SO the corresponding question: https://stackoverflow.com/questions/78214882/have-emoji-working-in-sphinx-latexpdf-xelatex-generated-content-titles-and-code
Just wondering, but does a plain LaTeX file with such emojis would do what you want? (like, what would the minimum LaTeX file which would work (independently of Sphinx))
Just wondering, but does a plain LaTeX file with such emojis would do what you want? (like, what would the minimum LaTeX file which would work (independently of Sphinx))
I'm not Latex good enough, the minimal whould be to have B&W emoji in both \section and \begin{Verbatim} I guess.
A cascading mechanism is probably the droid we are looking for ;) Like if you don't find the emoji in FreeSansBold.otf try to take it from Symbola
Our solution for (color) emoji in the PDF output was to use LuaLaTeX and to define TwemojiMozilla as the fallback font.
You can see the result there: https://club1.fr/docs/en/club1-en-latest.pdf
The idea mainly came from this article: https://www.overleaf.com/learn/latex/Articles/An_overview_of_technologies_supporting_the_use_of_colour_emoji_fonts_in_LaTeX
Maybe the method of https://github.com/numpy/numpy/pull/23172 would work here. Something such as
(check the file extension for Symbola, assuming it is otf here)
latex_elements['preamble'] = r"""
\newfontfamily\FontForEmojis{Symbola}[Extension=.otf]
\catcode`🚀\active\protected\def🚀{{\FontForEmojis\string🚀}}
\catcode`🔨\active\protected\def🔨{{\FontForEmojis\string🔨}}
"""
You have to do it for all used characters. A latex code doing a loop is possible.
I am not fontspec
-able. So no idea about your question with \setmainfont
. All I know is that LaTeX maintainers are philosophically against LaTeX having a "cascading" fall-back scheme to finding characters in a font. Also because 30 years ago it would have been prohibitively costly. One has to go through methods like the above. edit: or use LuaLaTeX as explained by @n-peugnet
Edit: in the above perhaps NotoColorEmoji
rather and ttf
for the extension.
Sorry for noise here. On reading more closely the very instructive overleaf link provided by @n-peugnet, especially XeTeX and OpenType color fonts, I realized that the method I indicated would not work with xelatex
and NotoColorEmoji
. It does work for lualatex
as the following pure latex code snippet examplifies, but then the "fallback" mechanism of @n-peugnet comment is much better.
\documentclass{article}
% compile with lualatex on a recent TeXLive based installation (at least 2020)
\usepackage{fontspec}
\newfontfamily\FontForEmojis{NotoColorEmoji}[Renderer=Harfbuzz, Extension=.ttf]
\catcode`🚀\active\protected\def🚀{{\FontForEmojis\string🚀}}
\catcode`🔨\active\protected\def🔨{{\FontForEmojis\string🔨}}
\begin{document}
Test 🚀🔨
\end{document}
To keep this issue related to xelatex, I created a new one focus on LuaLaTeX: https://github.com/sphinx-doc/sphinx/issues/12332, with all insight got from @n-peugnet and @jfbu.
B&W success using this set-up:
latex_engine = 'xelatex'
latex_theme = 'howto'
latex_elements = {
"preamble": r"""
\setmainfont{Latin Modern Roman}[SmallCapsFont={* Caps}]
\setsansfont{Latin Modern Sans}
\setmonofont{DejaVu Sans Mono}[Scale=0.8]
\newfontfamily\FontOne{Symbola}
\newfontfamily\FontTwo{DejaVuSans}[Extension=.ttf]
\catcode`🚀\active\protected\def🚀{{\FontOne\string🚀}}
\catcode`🔨\active\protected\def🔨{{\FontOne\string🔨}}
\catcode`⣿\active\protected\def⣿{{\FontTwo\string⣿}}
""",
}
output:
I changed the type of this ticket to question because it does not seem to be related to a bug in Sphinx LaTeX support, except if one considers support for color emojis should be built-in, on which topic I don't have myself any strong opinion!
Describe the bug
with
latex_elements = {"preamble": r"\setmainfont{Symbola}"}
we have beautiful B&W emoji in xelatex generated PDF content but not on titles and not on code.How to Reproduce
Below a sphinx to illustrate emoji in latexpdf:
add some content:
Set latex_engine and article xelatex:
HTML emoji are ok
latexpdf with
xelatex
engine have no emoji:with
setmainfont
get get some emoji (B&W and only in content):The corresponding latex code expose that font for
section
does not know about emoji, neither font define forsphinxVerbatim
::The latex log file expose that in
code::
latex look for emoji inFreeMono.otf
and in title latex look for emoji inFreeSansBold.otf
:To see which one of my fonts has the
⣿
.On my unbuntu 22.04 the below fonts have the ⣿ character:
Beyond the
question, I wonder why
\setmainfont
can have bothSymbola
andFreeSerif
values in tex file, I expect to have only one mainfont, idealy to defineSymbola
as a fall back font in case characters are not found in theFreeSerif
"mainfont":Environment Information
Sphinx extensions
Additional context
No response