Creating LaTeX math macros within Sphinx(在 Sphinx 中创建 LaTeX 数学宏)
问题描述
我正在用 Python 编写一些数学代码并使用 Sphinx 来生成文档.我知道 Sphinx 可以处理 Python 文档字符串中的 LaTeX 代码;见 https://www.sphinx-doc.org/en/master/usage/extensions/math.html#module-sphinx.ext.mathbase.如何创建 LaTeX 宏,例如
ewcommand{cG}{mathcal{G}}
,以便在 Python 文档字符串中使用?
I'm writing some mathematical code in Python and using Sphinx to produce the documentation. I know that Sphinx can handle LaTeX code in Python docstrings; see https://www.sphinx-doc.org/en/master/usage/extensions/math.html#module-sphinx.ext.mathbase. How can I create LaTeX macros, such as
ewcommand{cG}{mathcal{G}}
, to use in the Python docstrings?
推荐答案
啊哈,我找到了一个适用于 Sphinx pngmath 扩展的解决方案.这是 Sage(开源数学软件)使用的技巧;灵感来自 http://www.sagemath.org/doc/reference/sage/misc/latex_macros.html.
Aha, i found a solution that works with the Sphinx pngmath extension. It's the trick that Sage (open source mathematics software) uses; inspiration from http://www.sagemath.org/doc/reference/sage/misc/latex_macros.html.
要将您自己的 Latex 宏添加到 Sphinx 文档:
To add your own Latex macros to a Sphinx document:
1) 创建一个文件,例如latex_macros.sty",其中包含您的宏(每行一个),然后将其放在与您的 Sphinx conf.py 文件相同的目录中;
1) Make a file, say 'latex_macros.sty', containing your macros (one per line), and put it in, say, the same directory as your Sphinx conf.py file;
2) 将以下代码添加到您的 Sphinx conf.py 文件中:
2) Add the following code to your Sphinx conf.py file:
# Additional stuff for the LaTeX preamble.
latex_elements['preamble'] = 'usepackage{amsmath}
usepackage{amssymb}
'
#####################################################
# add LaTeX macros
f = file('latex_macros.sty')
try:
pngmath_latex_preamble # check whether this is already defined
except NameError:
pngmath_latex_preamble = ""
for macro in f:
# used when building latex and pdf versions
latex_elements['preamble'] += macro + '
'
# used when building html version
pngmath_latex_preamble += macro + '
'
#####################################################
这篇关于在 Sphinx 中创建 LaTeX 数学宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Sphinx 中创建 LaTeX 数学宏


- 分析异常:路径不存在:dbfs:/databricks/python/lib/python3.7/site-packages/sampleFolder/data; 2022-01-01
- 如何在 python3 中将 OrderedDict 转换为常规字典 2022-01-01
- pytorch 中的自适应池是如何工作的? 2022-07-12
- python check_output 失败,退出状态为 1,但 Popen 适用于相同的命令 2022-01-01
- 使用Heroku上托管的Selenium登录Instagram时,找不到元素';用户名'; 2022-01-01
- 如何将一个类的函数分成多个文件? 2022-01-01
- 如何在 Python 的元组列表中对每个元组中的第一个值求和? 2022-01-01
- python-m http.server 443--使用SSL? 2022-01-01
- 沿轴计算直方图 2022-01-01
- padding='same' 转换为 PyTorch padding=# 2022-01-01