diff --git a/src/nbsphinx.py b/src/nbsphinx.py index ccd9e484..81f954a7 100644 --- a/src/nbsphinx.py +++ b/src/nbsphinx.py @@ -938,6 +938,7 @@ def get_transforms(self): CreateNotebookSectionAnchors, ReplaceAlertDivs, CopyLinkedFiles, + ForceEquations, ] def parse(self, inputstring, document): @@ -1796,6 +1797,21 @@ def apply(self): env.nbsphinx_files.setdefault(env.docname, []).append(file) +class ForceEquations(docutils.transforms.Transform): + """Unconditionally enable equations on notebooks. + + Except if ``nbsphinx_assume_equations`` is set to ``False``. + + """ + + default_priority = 900 # after checking for equations in MathDomain + + def apply(self): + env = self.document.settings.env + if env.config.nbsphinx_assume_equations: + env.get_domain('math').data['has_equations'][env.docname] = True + + class GetSizeFromImages( sphinx.transforms.post_transforms.images.BaseImageConverter): """Get size from images and store it as node attributes. @@ -2218,6 +2234,7 @@ def setup(app): app.add_config_value('nbsphinx_widgets_path', None, rebuild='html') app.add_config_value('nbsphinx_widgets_options', {}, rebuild='html') app.add_config_value('nbsphinx_thumbnails', {}, rebuild='html') + app.add_config_value('nbsphinx_assume_equations', True, rebuild='env') app.add_directive('nbinput', NbInput) app.add_directive('nboutput', NbOutput)