Pregunta

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.

¿Fue útil?

Solución

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.

Otros consejos

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":

https://github.com/jterrace/sphinxtr/blob/master/conf.py

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top