我正在Python中編寫一些數學代碼並使用Sphinx生成文檔。我知道Sphinx可以在Python docstrings中處理LaTeX代碼;見http://sphinx.pocoo.org/latest/ext/math.html#module-sphinx.ext.mathbase。我如何創建LaTeX宏,如\newcommand{\cG}{\mathcal{G}}
,以在Python文檔中使用?在Sphinx中創建LaTeX數學宏
9
A
回答
3
啊哈,我發現,獅身人面像pngmath擴建工程的解決方案。這是Sage(開源數學軟件)使用的技巧;靈感來自http://www.sagemath.org/doc/reference/sage/misc/latex_macros.html。
要自己乳膠宏添加到獅身人面像文檔:
1)請一個文件,說「latex_macros.sty」,包含您的宏(每行一個),並把它在,比方說,同樣的目錄作爲您的Sphinx conf.py文件;
2)將以下代碼添加到您的獅身人面像conf.py文件:
# Additional stuff for the LaTeX preamble.
latex_elements['preamble'] = '\usepackage{amsmath}\n\usepackage{amssymb}\n'
#####################################################
# 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 + '\n'
# used when building html version
pngmath_latex_preamble += macro + '\n'
#####################################################
1
如果您使用的pngmath擴展,你可以把在序言將其插入conf.py腳本這樣的:
pngmath_latex_preamble = r"\newcommand{\cG}{\mathcal{G}}"
5
如果使用MathJax,這裏有一個可能的解決方案。我仍在尋找更好的解決方案,但如果您需要快速入門,它可能會有所幫助。
創建於
html_static_path
配置選項(一般爲_static
)指定的目錄下的文件,說mathconf.js
。這將包含MathJax的JS配置。例如(從MathJax documentation):MathJax.Hub.Config({ TeX: { Macros: { RR: '{\\bf R}', bold: ['{\\bf #1}', 1] } } });
您可以添加上面的語法如下多個命令。顯示的內容定義宏
\RR
和\bold{#1}
,最後一個接受一個參數。在
_templates
目錄中添加一個layout.html
文件。這個想法是擴展當前的主題,所以它搜索以前的MathJax配置文件。因此,內容是:{% extends "!layout.html" %} {% set script_files = script_files + ["_static/mathconf.js"] %}
注意,在這種情況下,是的
_static
目錄,因爲在這種情況下,它指的是在哪裏構建後搜索。 Sphinx將文件從html_static_path
移到build目錄下的_static
目錄。
相關問題
- 1. LaTex宏使LaTex在數學中更加人性化?
- 2. 在Latex中創建環境
- 3. LaTex目錄中的數學
- 4. 如何用LaTeX數學樣式創建網頁或程序?
- 5. Excel宏創建學校報告
- 6. 宏創建宏?
- 7. LaTeX數學大括號
- 8. 創建在MATLAB或數學
- 9. 對齊Latex中的數學方程
- 10. LaTeX數學表達式在knitr kable(Sweave)
- 11. 在intellij中創建宏
- 12. 如何在pandoc中使用latex宏?
- 13. sphinx:包括.tex文件通過raw :: latex
- 14. 創建Django sphinx單頁html?
- 15. 在數學中創建分佈
- 16. 如何在reStructuredText/Sphinx中創建浮動數字?
- 17. LaTeX:無法創建文檔
- 18. D3數學函數創建
- 19. Matlab:創建數學函數
- 20. 在Latex中創建一個帶標籤的數字線
- 21. Elisp宏清理LaTeX代碼
- 22. iOS創建宏
- 23. 創建Excel宏
- 24. React自動渲染數學Latex
- 25. LaTeX的數學模式和MBOX模式
- 26. 創建PHP數學運算
- 27. 如何在Beamer中編寫數學模型LaTex
- 28. IPython LaTeX數學不使用nbconvert在HTML中呈現
- 29. 在sas中創建一個宏
- 30. 如何在Excel項目中創建宏
並沒有爲我(獅身人面像= 1.3.1)可能是工作,因爲我無法正確設置腳本類型'<腳本類型=「文本/ X-mathjax-配置」> SRC =「_靜/mathconf.js「>'(請參閱 http://docs.mathjax.org/en/latest/configuration.html#using-in-line-configuration-options)。 – user511 2018-02-28 11:36:56