'Can the XeLaTeX builder be used with Sphinx?
Although the end-problem that this would solve is a TeX one (installing a new font for PDF output), this particular solution that I'm looking for is a Sphinx issue. Sphinx uses standard LaTeX when making PDFs, which is fine so far, but I need to install a new font and have tried and failed. I understand this is a far easier process using XeLateX, so would like to know if there is an extension or some way to configure Sphinx to make it use the XeLaTeX builder instead.
Solution 1:[1]
I think this boils down to getting in some LaTeX instructions before sphinx starts its work.
At the start of your index.rst
, you can add a "raw" entry that's passed verbatim to latex:
.. raw:: latex
\setyournicefontorwhatever(beautiful.ttf)
Does that help to get the correct font in? I'm using raw latex entries myself to remove the section numbers from part of my documentation (\setcounter{secnumdepth}{-1}
in a similar "raw" entry).
Also, the Sphinx documentation on build options has some things you can try. The most promising looks to be the documentclass
item in the latex_documents
setting.
Solution 2:[2]
It is possible to allow sphinx to use the xelatex builder by modifying the make file to use xelatex, or simply build the doc in two commands....make latex, then xelatex yourdoc.tex. However it is important to disable a number of packages including: fontenc, inputenc, and babel as these eithier dont work at all or may cause issues in future. I think there may be alternative packages in leiu of babel if you wish. Also xelatex already allows for some (but not all) characters that inputenc[utf8] would normally account for.
Disabling these can be done in you conf.py file, this doc shows a good example of how to do this under "Option for Latex":
Solution 3:[3]
I add the following to conf.py when using xelatex:
latex_elements = {
# Additional stuff for the LaTeX preamble.
'preamble': ''' \usepackage{fontspec} \setmainfont{Times New Roman}
''',
'inputenc': '',
'fncychap': '',
'utf8extra': '',
'times': '',
'babel': '\usepackage{polyglossia}',
'cmap': '',
'fontenc': '',
'releasename': '', }
You have to turn off a lot of the default latex packages because xelatex uses other packages or have the functionality built-in.
Solution 4:[4]
As of recent Sphinx versions (tested with Sphinx 4.2.0), yes! Simply add this to your conf.py
file:
latex_engine = 'xelatex'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Pearse |
Solution 3 | kaleissin |
Solution 4 | Apteryx |