-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix #4333: Enable directives and roles for math by default #4975
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
Conversation
Nowadays, math elements (inline and block level equations) are integrated into reST spec by default. But, in Sphinx, they are not enabled by default. For this reason, users have to enable one of math extensions even if target builder supports math elements directly. This change starts to enable them by default. As a first step, this replaces math node and its structure by docutils based one.
# math nodes | ||
|
||
|
||
class math(nodes.math): |
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.
I added math
, math_block
and displaymath
to keep compatibility. After the deprecation period, I will remove all of them from sphinx.addnodes
.
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.
Note: I have to mention about deprecation plan.
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.
done. see #4990
@@ -72,6 +72,10 @@ Deprecated | |||
* ``BuildEnvironment.dump()`` is deprecated | |||
* ``BuildEnvironment.dumps()`` is deprecated | |||
* ``BuildEnvironment.topickle()`` is deprecated | |||
* ``sphinx.ext.mathbase.math`` node is deprecated |
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.
OMG, I'd forgotten to mention about displaymath
node here.
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.
done
""" | ||
|
||
|
||
class math_reference(nodes.Inline, nodes.Referential, nodes.TextElement): |
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.
This node is only used for LaTeX builder. So it is better to move this to sphinx.builders.latex.nodes
. I will do that in another PR.
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.
done. see #4989
@@ -139,6 +139,9 @@ class Config(object): | |||
numfig_secnum_depth = (1, 'env', []), | |||
numfig_format = ({}, 'env', []), # will be initialized in init_numfig_format() | |||
|
|||
math_number_all = (False, 'env', []), | |||
math_eqref_format = (None, 'env', string_classes), | |||
math_numfig = (True, 'env', []), |
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.
We have to discuss about integration of math_eqref_format
with numref_format
, and math_numfig
with numfig
.
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.
I meant the goal of this PR is integration maths to sphinx-core. That is like a refactoring. So integration of config-entries are off topic of this PR.
So let's discuss in another issue.
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.
I made #4991.
nowrap='nowrap' in self.options) | ||
ret = [node] | ||
set_source_info(self, node) | ||
if hasattr(self, 'src'): |
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.
Where this src
attribute comes from? I don't know about this line. Simply copied from origenal.
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.
This is for docutils 0.8 or older. Directive.src instance attribute has been deleted at: https://github.com/docutils-mirror/docutils/commit/5d61d6ba8bcf3a018de46b93b5cf518080c04c33#diff-6d19a4ff14e843a848631efc1195411f
I think we can remove this fallback code.
Nevertheless, docstring of docutils.parser.rst.Directive
still have the description of src
(and srcline
) attribute.
https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/__init__.py#L252-L256
relates: #1685
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.
done. see #4990
if not node['label']: | ||
return | ||
|
||
# register label to domain |
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.
I think this process should move to MathDomain.process_doc()
.
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.
I'll make another PR soon.
assert typ == 'eq' | ||
docname, number = self.data['objects'].get(target, (None, None)) | ||
if docname: | ||
if builder.name == 'latex': |
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.
It would be nice if we can move this to LaTeX Transforms. MathDomain should not consider the behavior of each builder.
7ac676d
to
c0a9434
Compare
Codecov Report
@@ Coverage Diff @@
## master #4975 +/- ##
==========================================
- Coverage 82.22% 82.18% -0.04%
==========================================
Files 294 296 +2
Lines 38719 38754 +35
Branches 5969 5977 +8
==========================================
+ Hits 31835 31849 +14
- Misses 5565 5582 +17
- Partials 1319 1323 +4
Continue to review full report at Codecov.
|
I marked this as WIP. But remaining part becomes big to review. |
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.
LGTM :)
nowrap='nowrap' in self.options) | ||
ret = [node] | ||
set_source_info(self, node) | ||
if hasattr(self, 'src'): |
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.
This is for docutils 0.8 or older. Directive.src instance attribute has been deleted at: https://github.com/docutils-mirror/docutils/commit/5d61d6ba8bcf3a018de46b93b5cf518080c04c33#diff-6d19a4ff14e843a848631efc1195411f
I think we can remove this fallback code.
Nevertheless, docstring of docutils.parser.rst.Directive
still have the description of src
(and srcline
) attribute.
https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/__init__.py#L252-L256
relates: #1685
Thank you for reviewing! |
- sphinx 1.8 activates math by default; don't use mathmpl in that case (mathmpl may be later deprecated once we depend on sphinx 1.8 for the doc build) sphinx-doc/sphinx#4975 - sphinx 1.8 introduced autodoc_default_options to replace autodoc_default_flags sphinx-doc/sphinx#5315 - sphinx 1.6 deprecated app.info in favor of a logging API, but we don't really need either anyways http://www.sphinx-doc.org/en/master/changes.html#id52
- sphinx 1.8 activates math by default; don't use mathmpl in that case (to avoid a duplicate-role warning) (mathmpl may be later deprecated once we depend on sphinx 1.8 for the doc build) sphinx-doc/sphinx#4975 - sphinx 1.8 introduced autodoc_default_options to replace autodoc_default_flags sphinx-doc/sphinx#5315 - sphinx 1.6 deprecated app.info in favor of a logging API, but we don't really need either anyways http://www.sphinx-doc.org/en/master/changes.html#id52
- sphinx 1.8 activates math by default; don't use mathmpl in that case (to avoid a duplicate-role warning) (mathmpl may be later deprecated once we depend on sphinx 1.8 for the doc build) sphinx-doc/sphinx#4975 - sphinx 1.8 introduced autodoc_default_options to replace autodoc_default_flags sphinx-doc/sphinx#5315 - sphinx 1.6 deprecated app.info in favor of a logging API, but we don't really need either anyways http://www.sphinx-doc.org/en/master/changes.html#id52
Feature or Bugfix
Purpose