-
Notifications
You must be signed in to change notification settings - Fork 4
Start testing for documentation building #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2bc5bf6
Fail on warnings for hatch-sphinx
rprospero 9f1c898
Include scipy at build time for docs
rprospero 09879d2
Remove absolute_temperature
rprospero 2747d0f
Fix up blockquote in units.py and si.py
rprospero 8d6ced7
Handle field warnings
rprospero 986f5fc
Escape absolute values
rprospero 5e23c09
Try to explicitly list missing references
rprospero 9856e17
Include generated modules in toc tree
rprospero ea667f7
Remove dead html static path
rprospero f7b5256
Try and get around stupid sphinx resolution of type
rprospero 76110ce
Copy sphinx math extensions from sasview
rprospero 0e02a9e
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] b729a6c
Import sys
rprospero 225388b
Add mathbase to sphinx
rprospero 2ab1f18
User dollar math in averaging.py
rprospero cb6fc1c
Update units.py correctly
rprospero cca5fda
[pre-commit.ci lite] apply automatic fixes for ruff linting errors
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # This program is public domain | ||
| # Author: Paul Kienzle | ||
| r""" | ||
| Allow $math$ markup in text and docstrings, ignoring \$. | ||
|
|
||
| The $math$ markup should be separated from the surrounding text by spaces. To | ||
| embed markup within a word, place backslash-space before and after. For | ||
| convenience, the final $ can be followed by punctuation (period, comma or | ||
| semicolon). | ||
| """ | ||
|
|
||
| import re | ||
|
|
||
| _dollar = re.compile(r"(?:^|(?<=\s|[-(]))[$]([^\n]*?)(?<![\\])[$](?:$|(?=\s|[-.,;:?\\)]))") | ||
| _notdollar = re.compile(r"\\[$]") | ||
|
|
||
| def replace_dollar(content): | ||
| content = _dollar.sub(r":math:`\1`",content) | ||
| content = _notdollar.sub("$", content) | ||
| return content | ||
|
|
||
| def rewrite_rst(app, docname, source): | ||
| source[0] = replace_dollar(source[0]) | ||
|
|
||
| def rewrite_autodoc(app, what, name, obj, options, lines): | ||
| lines[:] = [replace_dollar(L) for L in lines] | ||
|
|
||
| def setup(app): | ||
| app.connect('source-read', rewrite_rst) | ||
| app.connect('autodoc-process-docstring', rewrite_autodoc) | ||
|
|
||
|
|
||
| def test_dollar(): | ||
| assert replace_dollar("no dollar")=="no dollar" | ||
| assert replace_dollar("$only$")==":math:`only`" | ||
| assert replace_dollar("$first$ is good")==":math:`first` is good" | ||
| assert replace_dollar("so is $last$")=="so is :math:`last`" | ||
| assert replace_dollar("and $mid$ too")=="and :math:`mid` too" | ||
| assert replace_dollar("$first$, $mid$, $last$")==":math:`first`, :math:`mid`, :math:`last`" | ||
| assert replace_dollar(r"dollar\$ escape")=="dollar$ escape" | ||
| assert replace_dollar(r"dollar \$escape\$ too")=="dollar $escape$ too" | ||
| assert replace_dollar(r"emb\ $ed$\ ed")==r"emb\ :math:`ed`\ ed" | ||
| assert replace_dollar("$first$a")=="$first$a" | ||
| assert replace_dollar("a$last$")=="a$last$" | ||
| assert replace_dollar("a $mid$dle a")=="a $mid$dle a" | ||
|
|
||
| if __name__ == "__main__": | ||
| test_dollar() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| """ | ||
| sphinx.ext.mathjax | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Allow `MathJax <http://mathjax.org/>`_ to be used to display math in | ||
| Sphinx's HTML writer -- requires the MathJax JavaScript library on your | ||
| webserver/computer. | ||
|
|
||
| :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. | ||
| :license: BSD, see LICENSE for details. | ||
|
|
||
| sample lines in conf.py to use this:: | ||
|
|
||
| mathjax_path = ['https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js', | ||
| 'http://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/contrib/auto-render.min.js', | ||
| 'rendermath.js'] | ||
| mathjax_css = 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css' | ||
|
|
||
| with rendermath.js containing:: | ||
|
|
||
| document.addEventListener("DOMContentLoaded", function(event) { | ||
| renderMathInElement(document.body); | ||
| }); | ||
|
|
||
| 2016-08-09 Jason Sachs | ||
| * allow list of URLS for mathjax_path, which permits use of katex.js | ||
| """ | ||
|
|
||
| import sphinx | ||
| from docutils import nodes | ||
| from sphinx.errors import ExtensionError | ||
| from sphinx.ext.mathbase import setup_math as mathbase_setup | ||
| from sphinx.locale import _ | ||
|
|
||
|
|
||
| def html_visit_math(self, node): | ||
| self.body.append(self.starttag(node, 'span', '', CLASS='math')) | ||
| self.body.append(self.builder.config.mathjax_inline[0] + | ||
| self.encode(node['latex']) + | ||
| self.builder.config.mathjax_inline[1] + '</span>') | ||
| raise nodes.SkipNode | ||
|
|
||
|
|
||
| def html_visit_displaymath(self, node): | ||
| self.body.append(self.starttag(node, 'div', CLASS='math')) | ||
| if node['nowrap']: | ||
| self.body.append(self.encode(node['latex'])) | ||
| self.body.append('</div>') | ||
| raise nodes.SkipNode | ||
|
|
||
| # necessary to e.g. set the id property correctly | ||
| if node['number']: | ||
| self.body.append('<span class="eqno">(%s)' % node['number']) | ||
| self.add_permalink_ref(node, _('Permalink to this equation')) | ||
| self.body.append('</span>') | ||
| self.body.append(self.builder.config.mathjax_display[0]) | ||
| parts = [prt for prt in node['latex'].split('\n\n') if prt.strip()] | ||
| if len(parts) > 1: # Add alignment if there are more than 1 equation | ||
| self.body.append(r' \begin{align}\begin{aligned}') | ||
| for i, part in enumerate(parts): | ||
| part = self.encode(part) | ||
| if r'\\' in part: | ||
| self.body.append(r'\begin{split}' + part + r'\end{split}') | ||
| else: | ||
| self.body.append(part) | ||
| if i < len(parts) - 1: # append new line if not the last equation | ||
| self.body.append(r'\\') | ||
| if len(parts) > 1: # Add alignment if there are more than 1 equation | ||
| self.body.append(r'\end{aligned}\end{align} ') | ||
| self.body.append(self.builder.config.mathjax_display[1]) | ||
| self.body.append('</div>\n') | ||
| raise nodes.SkipNode | ||
|
|
||
| try: | ||
| basestring | ||
| except: | ||
| basestring = str | ||
|
|
||
| def builder_inited(app): | ||
| jaxpath = app.config.mathjax_path | ||
| if not jaxpath: | ||
| raise ExtensionError('mathjax_path config value must be set for the ' | ||
| 'mathjax extension to work') | ||
|
|
||
| # app.config.mathjax_path can be a string or a list of strings | ||
| if isinstance(jaxpath, basestring): | ||
| app.add_javascript(jaxpath) | ||
| else: | ||
| for p in jaxpath: | ||
| app.add_javascript(p) | ||
|
|
||
| if app.config.mathjax_css: | ||
| app.add_stylesheet(app.config.mathjax_css) | ||
|
|
||
|
|
||
| def setup(app): | ||
| try: | ||
| mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None)) | ||
| except ExtensionError: | ||
| raise ExtensionError('sphinx.ext.mathjax: other math package is already loaded') | ||
|
|
||
| # more information for mathjax secure url is here: | ||
| # http://docs.mathjax.org/en/latest/start.html#secure-access-to-the-cdn | ||
| app.add_config_value('mathjax_path', | ||
| 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?' | ||
| 'config=TeX-MML-AM_CHTML', | ||
| False) | ||
| app.add_config_value('mathjax_css', None, 'html') | ||
| app.add_config_value('mathjax_use_katex', False, 'html') | ||
| app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html') | ||
| app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html') | ||
| app.connect('builder-inited', builder_inited) | ||
|
|
||
| return {'version': sphinx.__display_version__, 'parallel_read_safe': True} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Please let me know if any additional
hatch-sphinxfeatures are needed for this work!)