Reputation: 13487
There's a ifconfig
sphinx extension -- and it allows for conditional inclusion of content. I'm looking for a way to conditionally include extensions. My best try is just to give a list of extensions with a -D
option to sphinx-build
:
sphinx-build -b singlehtml -d _build/doctrees -D html_theme=empty -D "extensions=['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.numfig', 'sphinx.ext.ifconfig', 'cloud_sptheme.ext.table_styling', 'sphinx.ext.htmlmath']" . _build/wkA
but it doesn't work.
The problem is to conditionally include sphinx.ext.htmlmath
or sphinxcontrib.mathml
.
Upvotes: 5
Views: 509
Reputation: 546
Use -t <tag>
http://sphinx-doc.org/invocation.html#cmdoption-sphinx-build-t
e.g. Invoke sphinx like this (See -t use_htmlmath
):
sphinx-build -b singlehtml -d _build/doctrees \
-D html_theme=empty -t use_htmlmath . _build/wkA
Have this code in conf.py
if tags.has('use_htmlmath'):
# use supplied =t use_htmlmath
extensions.append('sphinx.ext.htmlmath')
else:
#fall back
extensions.append('sphinxcontrib-mathml')
Upvotes: 5
Reputation: 36234
conf.py
is a python module and extensions
is a list, so you can simply append an extension to extensions
based on a condition:
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
my_condition = 1
if my_condition == 1:
extensions.append('sphinx.ext.htmlmath')
elif my_condition == 2:
extensions.append('sphinxcontrib-mathml')
elif my_condition == 3:
extensions.append('sphinx.ext.mathjax')
else:
print "Didn't found a suitable extension"
However you have to know your condition before the build process starts.
Upvotes: 1