readthedocs / sphinx_rtd_theme

Sphinx theme from Read the Docs
https://sphinx-rtd-theme.readthedocs.io/
MIT License
4.67k stars 1.72k forks source link

how to modify code fonts #1295

Open jacob-keller opened 2 years ago

jacob-keller commented 2 years ago

Problem

I use the ReadTheDocs theme for a couple of projects. I would like to be able to change the monospace font used for code. The default font list includes several Mac OS only fonts (SFMono-Regular, Menlo, Monaco). On my systems, it ends up selecting Consolas, but I'd like to be able to modify the theme to use a different font.

Reproducible Project

.. code:: shell

   $ echo Things

Expected Results

The theme source code uses $code-font-family, and I would like to replace this with my own set of fonts to select from. Specifically I want to change monospace code blocks to include another font of my choosing.

I am not sure how to achieve this using a custom css or javascript, and there is no theme variable i can set to support this.

Environment Info

TheTripleV commented 1 year ago

In wpilibsuite/frc-docs, we faced a similar issue. We wanted to replace the ReadTheDocs theme text fonts (Roboto Slab and Lato) with native system fonts. We run post-processing on all html/css files to do this after building html.

The source for that is https://github.com/wpilibsuite/frc-docs/blob/main/source/_extensions/post_process_tasks/systemfonts.py It should be modifiable to swap out code fonts instead of text fonts.

Note: We took this approach because we didn't want to add a dependency on npm to our docs by extending this repo.