How to have emojis in sphinx latexpdf xelatex generated for:
- content ? OK
- titles ? KO
- code ? KO
Below a sphinx to illustrate emoji in latexpdf:
$ sphinx-quickstart --no-batchfile --no-sep -p test_emoj -l en -a me -v 1.0 -q
$ cd test_emoj; tree
├── _build
├── conf.py
├── index.rst
├── Makefile
├── NotoColorEmoji.ttf
├── _static
└── _templates
add some content:
$ vim index.rst
$ cat index.rst
=========
test_emoj
=========
Hello space
==============
Space and hammer .
.. code::
✔ app 8 layers [⣿⣿⣿] Pulled
$
Set latex_engine and article xelatex:
echo "latex_engine ='xelatex'" >> conf.py
echo "latex_theme='howto'" >> conf.py
HTML emoji are ok
$ make html
...
$
latexpdf with xelatex engine have no emoji:
$ make latexpdf
...
$ evince _build/latex/test_emoj.pdf
with setmainfont get get some emoji (B&W and only in content):
$ echo 'latex_elements = {"preamble": r"\setmainfont{Symbola}"}' >> conf.py
$ make latexpdf
...
$ evince _build/latex/test_emoj.pdf
The corresponding latex code expose that font for section does not know about emoji, neither font define for sphinxVerbatim::
$ vim _build/latex/test_emoj.tex
...
\section{Hello space }
\label{\detokenize{index:hello-space}}
\sphinxAtStartPar
Space , hammer and ⣿
\begin{sphinxVerbatim}[commandchars=\\\{\}]
\(\pmb{\checkmark}\) app 8 layers [⣿⣿⣿] Pulled
\end{sphinxVerbatim}
...
The latex log file expose that in code:: latex look for emoji in FreeMono.otf and in title latex look for emoji in FreeSansBold.otf:
$ grep '^Missi' _build/latex/test_emoj.log
Missing character: There is no (U+1F680) in font [FreeSansBold.otf]/OT:script
Missing character: There is no ⣿ (U+28FF) in font [FreeMono.otf]/OT:script=latn
Missing character: There is no ⣿ (U+28FF) in font [FreeMono.otf]/OT:script=latn
Missing character: There is no ⣿ (U+28FF) in font [FreeMono.otf]/OT:script=latn
$
To see which one of my fonts has the ⣿.
$ java -jar /usr/share/texlive/texmf-dist/scripts/albatross/albatross.jar --detailed ⣿
On my unbuntu 22.04 the below fonts have the ⣿ character:
/usr/share/fonts/truetype/ancient-scripts/Symbola_hint.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSans-BoldOblique.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed-Bold.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSansCondensed.ttf
/usr/share/fonts/truetype/dejavu/DejaVuSerif
/usr/share/fonts/truetype/noto/NotoSansSymbols2-Regular.ttf
Beyond the
"Have emoji working in sphinx latexpdf xelatex generated content, titles and code"
question, I wonder why:
how
\setmainfontcan have bothSymbolaandFreeSerifvalues in tex file, I expect to have only one mainfont, idealy to defineSymbolaas a fall back font in case characters are not found in theFreeSerif"mainfont":$ grep setmainfont _build/latex/test_emoj.tex \setmainfont{FreeSerif}[ \setmainfont{Symbola} $is there a way to have color emoji ?
Note: Sphinx doc to configure latex, here so#497403 they talk about Noto Color Emoji but nothing on having emojis in title and code.


