0

I'm building an extension for sphinx to include fontawesome icons inside documentation. It would be great if it could work in the LaTeX build as well. My initial work was relying on the "fontawesome5" package, but as we are now moving toward fa6 I would like to rely on the web font downloaded with from NPM.

context:

  • builder is LaTeX (can be changed in the conf.py but that will lead to many errors in RDT)
  • I have all the fonts in .ttf format
  • I have the unicode of all my glyphs

I saw in https://tex.stackexchange.com/a/627541/261930 the following command which is exactly what I need:

\newfontfamily{\fa}{Font Awesome 6 Free-Solid-900.ttf}

but It never works on my RDT environment (crash + no access to the logs). Can this really work? Uf yes, what should I install to make it work on my local machine ? (I can then tune the RDT env accordingly)

1
  • 1
    which compiler are you using? you need to configure your LaTeX builder to use XeLaTeX or LuaLaTeX instead of pdflatex, since they support loading fonts from .ttf files.
    – scd
    Feb 27, 2023 at 15:36

1 Answer 1

0

thanks for the headstart àscd, I finally managed to make it work:

first step as you mentioned move to XeLaTex compiler:

# conf.py
latex_engine = "xelatex"

Then use the fontspec package:

# conf.py

setup(app):
    # [...]
    app.add_latex_package("fontspec")

and finally add the command to preamble:

# conf.py

latex_elements["preamble"] += dedent(
    r"""
    \newfontfamily{\solid}{fa-solid-900.ttf}
    \newfontfamily{\regular}{fa-regular-400.ttf}
    \newfontfamily{\brands}{fa-brands-400.ttf}
    """
)

I can now use the following command in my Sphinx built latex output.

{\solid\symbol{"F07B}}

If people don't want to struggle as I did, I wrote 2 sphinx extention:

They support html and latex build

3
  • Under latex_engine='xelatex', the fontspec package is automatically loaded. I also don't think you need the dedent(). Those extra spaces at start of lines are of no importance for LaTeX. I would be interested to know how you inject the \solid mark-up. Do you post-process the tex file
    – user691586
    Mar 31, 2023 at 19:46
  • I use dedent to have a human readable preamble (the one generated by sphinx is already super packed). I don't quite understand the question about \solid. I use in the background a dedicated role that interprets icons and inject them in any build (epub, html, latex). Apr 3, 2023 at 11:17
  • Thanks for explaining! I see now...
    – user691586
    Apr 3, 2023 at 19:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .