Adding a javascript script tag some place so that it works for every file in sphinx documentation

后端 未结 5 1059
野的像风
野的像风 2020-12-24 14:59

I am using Sphinx to write some notes. I am using the Mathjax extension for Math in the notes. The default size of the math is little larger than I would like. On the Mathja

5条回答
  •  心在旅途
    2020-12-24 15:28

    If you want to avoid altering templates, you can just call Sphinx's add_js_file() from the setup() function in your Sphinx project's conf.py:

    # conf.py
    
    # ... other settings ...
    
    def setup(app):
        # (create a setup() function if you don't already have one;
        # or add to the existing setup() ...)
        app.add_js_file("mathjax-config.js")
    

    Create the file "mathjax-config.js" in your _static source directory. (Check the conf.py html_static_path setting to verify the static directories, or define one if needed.) Sphinx will copy it into the output directory during the build.

    There's also an add_css_file() method for css files. And both of them can take either relative paths to your static source dirs, or full urls to external resources.

    Before Sphinx v1.8, these functions were called add_javascript() and add_stylesheet().

    And in Sphinx v3.0 or later, there's an even simpler approach that avoids the need for an extra JS file.

提交回复
热议问题