2012-03-15 72 views

回答

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,這裏有一個可能的解決方案。我仍在尋找更好的解決方案,但如果您需要快速入門,它可能會有所幫助。

  1. 創建於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},最後一個接受一個參數。

  2. _templates目錄中添加一個layout.html文件。這個想法是擴展當前的主題,所以它搜索以前的MathJax配置文件。因此,內容是:

    {% extends "!layout.html" %} 
    {% set script_files = script_files + ["_static/mathconf.js"] %} 
    

    注意,在這種情況下,_static目錄,因爲在這種情況下,它指的是在哪裏構建後搜索。 Sphinx將文件從html_static_path移到build目錄下的_static目錄。

+0

並沒有爲我(獅身人面像= 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