【问题标题】:create a role (font color) in sphinx that works with `make latexpdf`在 sphinx 中创建一个与“make latexpdf”一起使用的角色(字体颜色)
【发布时间】:2015-11-09 01:45:14
【问题描述】:

我习惯写 Rest 文档,但我从不使用 LaTex。

我想做的是创建一些字体颜色角色,我可以添加内嵌文本(例如:red:this text is red),这些文本既适用于 html 也适用于 latexpdf 编译。 p>

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

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

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

如果我想更改最终 pdf 文件的某些参数,我是否要编辑这个文件,把它放在某个地方并告诉 sphinx 采用这个样式文件?

对不起,我有点困惑..

谢谢!

【问题讨论】:

    标签: latex python-sphinx restructuredtext


    【解决方案1】:

    只需添加:

    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;
      }
      

    您现在可以在您的 rst 文件中使用 :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 …
    

    希望对您有所帮助,

    安东尼

    【讨论】:

    • 嗨 Antoine.. 我尝试了你的建议,但没有奏效。我只是将代码粘贴到 _static 文件夹中的文件 (custom.css) 中,并使用 :red:text 在第一个文件中调用了该角色。我错过了什么吗?
    • 非常抱歉,Matteo:我应该用我的笔记阅读我的记事本......我编辑了我之前的答案并这次测试了它!
    • 您好 Antoine,感谢您的努力,但无论如何都没有用。我将您的代码复制并粘贴到您所说的文件夹中,但在最终草稿中我看不到红色文本。顺便说一句,一旦我们开始工作,这个角色也适用于 pdf 输出(使用 latexpdf 构建)?再次感谢!
    • 糟糕......我刚刚又试了一次,它在那里工作。但是,关于 latexpdf,这是另一个故事,我现在没有答案。
    • 是的,非常糟糕..我一次又一次地尝试,但没有任何改变...我还要编辑conf.py文件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 2021-05-05
    相关资源
    最近更新 更多