Sphinx文档包中LaTeX输出的自定义颜色

时间:2018-05-20 22:53:43

标签: colors latex python-sphinx

我在尝试使用Sphinx文档包和html输出时自定义LaTeX内联公式的颜色。

详情:

我有一个名为func.rst的文件,其中包含以下行:

Let :math:`x_{1}` be a binary variable.

在我使用Sphinx创建的文档中成功呈现到LaTeX中。

'sphinx.ext.imgmath'extensions列出了conf.py

我的目标是让x_{1}为红色。

我尝试过的事情:

  1. 在公式中添加颜色:

    Let :math:`\color{red}x_{1}` be a binary variable.
    

    同时也定义

    latex_elements['preamble'] = '\usepackage{xcolor}'
    

    conf.py文件中。

  2. 尝试使用以下方式全局定义所有数学输出:

    latex_elements['preamble'] = r'''
    \usepackage{xcolor}
    \everymath{\color{red}}
    \everydisplay{\color{red}}
    '''
    
  3. 毋庸置疑,两者(以及许多不太有希望的想法)都失败了。

2 个答案:

答案 0 :(得分:1)

answer上的交叉发布问题上复制tex.sx

由于您似乎将数学呈现为PNG图像(或SVG)的html,因此要配置的当前配置值不是latex_elements,而是imgmath_latex_preamble

我测试过,它有效。

答案 1 :(得分:0)

为了完整起见,我在这里添加了完整的解决方案。 (谢谢jfbu!)

  1. conf.py我定义了extensions = ['sphinx.ext.imgmath', <some_more_unrelated_stuff>]

  2. 同样在conf.py我定义了

    imgmath_latex_preamble=r'\usepackage{xcolor}'
    

    (编辑:在我之前写的内容中,没有必要另外定义imgmath_latex="/usr/local/texlive/2017/bin/x86_64-darwin/latex"再次感谢jfbu)

  3. 在我有乳胶表达的.rst文件中,我有

    Let :math:`\color{red}x_{1}` be a binary variable.
    
  4. 在终端我运行

    make clean html
    

    (&#34;干净&#34;是狮身人面像最好的朋友)

  5. 它的工作! wohoo!

相关问题