8

I discovered that if I use some Unicode characters inside .rst files, I will loose them when I convert the documentation to pdf using Sphinx.

Example chars: "șț".

When I run make latexpdf I get a document without these Unicode characters.

migrated from stackoverflow.com Jun 7 '11 at 13:58

This question came from our site for professional and enthusiast programmers.

  • An option (which I used) is to run xelatex on file produced by Sphinx, though you have to adjust preamble in the config file. – eudoxos Jul 30 '11 at 18:24
6

Currently You can use xelatex manually for that. Add

latex_elements = {
    'inputenc': '',
    'utf8extra': '',
    'preamble': '''

\usepackage{fontspec}
\setsansfont{Arial}
\setromanfont{Arial}
\setmonofont{DejaVu Sans Mono}
''',
}

to conf.py, make latex code, and run the xelatex manually:

sphinx-build -b latex -d _build/doctrees . _build/xetex && cd _build/xetex; xelatex *.tex
  • 1
    You might want to use r''' ''' around the preamble. Or Double the \\'s to properly escape them. – S.Lott Dec 5 '15 at 14:26
  • 2
    for passers-by: answer of @czam points out latex_engine configuration variable which did not exist at time of @Adobe answering, so now make latexpdf will use xelatex out of the box with latex_engine = 'xelatex'. – user4686 Jun 8 '18 at 16:30
5

I don't know about Sphinx, but the problem seems to be in the fact that the option utf8 to inputenc doesn't know about the comma below used in Romanian.

You can solve the problem by using the utf8x option or adding to the preamble for LaTeX compilation the following incantation

\makeatletter
\ProvideTextCommandDefault\textcommabelow[1]
  {\hmode@bgroup\ooalign{\null#1\crcr\hidewidth\raise-.31ex
   \hbox{\check@mathfonts\fontsize\ssf@size\z@
   \math@fontsfalse\selectfont,}\hidewidth}\egroup}
\makeatother
\usepackage{newunicodechar}
\newunicodechar{Ș}{\textcommabelow S}
\newunicodechar{ș}{\textcommabelow s}
\newunicodechar{Ț}{\textcommabelow T}
\newunicodechar{ț}{\textcommabelow t}

The code between \makeatletter and \makeatother is from uni-global.def of the ucs package.

Additional comments

Note that you need nothing special since the 2015 release of LaTeX has added support of all Romanian letters within \usepackage[utf8]{inputenc}, so utf8x is not needed any more, nor the explicit definitions with \newunicodechar.

2

Also consider using XeLaTeX, it can be configured as LaTeX engine in conf.py.

From the Sphinx documentation:

# inside conf.py
latex_engine = 'xelatex'
  • 1
    sorry that you got downvoted, downvoting seems to become a plague of tex.sx these days (I wish I could downvote the downvoter, because downvoting this was pretty stupid, I have to say) – user4686 Jun 8 '18 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.