更改 sphinx 文档中的默认字体

Change default font in sphinx documentation

我想更改 sphinx 文档中的默认字体。我正在使用 sphinx_bootstrap_theme 'journal'

我该怎么做?

创建您自己的“_templates”目录和“layout.html”文件(假设您从 "source" 目录构建):

$ mkdir source/_templates
$ touch source/_templates/layout.html

配置您的 "conf.py":

templates_path = ['_templates']
html_static_path = ['_static']

覆盖文件“source/_templates/layout.html”:

{# Import the theme's layout. #}
{% extends "!layout.html" %}

{# Custom CSS overrides #}
{% set bootswatch_css_custom = ['_static/my-styles.css'] %}

_static/my-styles.css中:

body{
    font-family:"Arial", Helvetica, sans-serif;
}

This link 应该更有用

我找到了一种更简单的方法来做同样的事情。

  1. 在 _static 文件夹下创建一个 CSS 文件。例如,_static/css-style.css
  2. 在conf.py
  3. 中添加CSS文件的名称
## conf.py

html_css_files = [
    'css/css-style.css',
]

在_static/css-style.css:

body{
    font-family:"Arial", Helvetica, sans-serif;
}

参考: https://docs.readthedocs.io/en/stable/guides/adding-custom-css.html