在使用 `make latexpdf` 的 sphinx 中创建一个角色(字体颜色)

create a role (font color) in sphinx that works with `make latexpdf`

我习惯写 Rest 文档,从来没有用过 LaTex。

我想做的是创建一些 字体颜色角色 ,我可以添加内联文本(例如 :red:this text is red),在 html 并在 latexpdf 编译中。

我发现了一个类似的问题here,但我无法重现它。

我认为 magic 将完成更改 conf.py 文件,但我不知道如何。

此外,在latexpdf编译的过程中,在_build/latex目录下,有一个sphinx.sty文件,里面包含了很多自定义最终pdf文件的东西。

如果我想更改最终 pdf 文件的某些参数,是否需要编辑此文件,将其放在某个地方并告诉 sphinx 获取此样式文件?

抱歉所有这些东西,但我有点困惑..

谢谢!

只需添加:

  1. 一个 'source/_templates/layout.html' 文件

    {% extends "!layout.html" %}
    
    {% block extrahead %}
    <link rel="stylesheet" type="text/css" 
         href="{{ pathto('_static/custom.css', 1) }}" /> 
    
    {% endblock %}
    
  2. 一个 'source/_static/custom.css' 文件

    @import url("default.css");
    
    .red {
      color: red;
    }
    

您现在可以在您的第一个文件中使用 :red: 角色。不要忘记 html 或 css 版本后的反勾和干净的目标:

A :red:`red`text

$> make clean html

全局树:

test-sphinx
├── Makefile
├── build
└── source
    ├── _static
    │   └── custom.css
    ├── _templates
    │   └── layout.html
    ├── conf.py
    └── index.rst

一个index.rst例子:

TS test!
========

.. role:: red

This is :red:`just` a test …

希望对您有所帮助,

安托万