我在尝试使用Sphinx文档包和html输出时自定义LaTeX内联公式的颜色。
我有一个名为func.rst
的文件,其中包含以下行:
Let :math:`x_{1}` be a binary variable.
在我使用Sphinx创建的文档中成功呈现到LaTeX中。
('sphinx.ext.imgmath'
中extensions
列出了conf.py
我的目标是让x_{1}
为红色。
在公式中添加颜色:
Let :math:`\color{red}x_{1}` be a binary variable.
同时也定义
latex_elements['preamble'] = '\usepackage{xcolor}'
在conf.py
文件中。
尝试使用以下方式全局定义所有数学输出:
latex_elements['preamble'] = r'''
\usepackage{xcolor}
\everymath{\color{red}}
\everydisplay{\color{red}}
'''
毋庸置疑,两者(以及许多不太有希望的想法)都失败了。
答案 0 :(得分:1)
由于您似乎将数学呈现为PNG图像(或SVG)的html,因此要配置的当前配置值不是latex_elements
,而是imgmath_latex_preamble
。
我测试过,它有效。
答案 1 :(得分:0)
为了完整起见,我在这里添加了完整的解决方案。 (谢谢jfbu!)
在conf.py
我定义了extensions = ['sphinx.ext.imgmath', <some_more_unrelated_stuff>]
同样在conf.py
我定义了
imgmath_latex_preamble=r'\usepackage{xcolor}'
(编辑:在我之前写的内容中,没有必要另外定义imgmath_latex="/usr/local/texlive/2017/bin/x86_64-darwin/latex"
再次感谢jfbu)
在我有乳胶表达的.rst
文件中,我有
Let :math:`\color{red}x_{1}` be a binary variable.
在终端我运行
make clean html
(&#34;干净&#34;是狮身人面像最好的朋友)
它的工作! wohoo!的