问题
I am trying to customize the color of the LaTeX inline formula when using Sphinx documentation package, and html output.
The details:
I have a file called func.rst, which includes the following line:
Let :math:`x_{1}` be a binary variable.
which is rendered successfully into LaTeX in the documentation I created with Sphinx.
(I have 'sphinx.ext.imgmath' listed in extensions in conf.py)
My goal is to have x_{1} colored in red.
Things I tried:
Adding the color inside the formula:
Let :math:`\color{red}x_{1}` be a binary variable.while also defining
latex_elements['preamble'] = '\usepackage{xcolor}'in the
conf.pyfile.Trying to define all math output globally with:
latex_elements['preamble'] = r''' \usepackage{xcolor} \everymath{\color{red}} \everydisplay{\color{red}} '''
Needless to say, both (and many more less promising ideas) failed.
回答1:
Copying over my answer on cross-posted question at tex.sx:
As you seem to be targeting html with math rendered as PNGs images (or SVGs), the current config value to configure isn't latex_elements, but imgmath_latex_preamble.
I tested since and it works.
回答2:
For completeness sake, I am adding here the full solution. (THANKS jfbu!)
In
conf.pyI definedextensions = ['sphinx.ext.imgmath', <some_more_unrelated_stuff>]Also in
conf.pyI definedimgmath_latex_preamble=r'\usepackage{xcolor}'(EDIT: in ooposed to what I previously wrote,there is no need to define in addition
imgmath_latex="/usr/local/texlive/2017/bin/x86_64-darwin/latex"thanks jfbu again)In the
.rstfile where I have the latex expression, I haveLet :math:`\color{red}x_{1}` be a binary variable.In the terminal I run
make clean html("make clean" is the sphinx's best friend)
And its working! wohoo!
来源:https://stackoverflow.com/questions/50440108/custom-color-for-latex-output-in-sphinx-documentation-package