Skip to content

Commit

Permalink
Rename the :nowrap and :nosignatures: directive options
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 23, 2025
1 parent ca2ab35 commit 962a7ca
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Features added
:confval:`python_trailing_comma_in_multi_line_signatures` and
:confval:`javascript_trailing_comma_in_multi_line_signatures`
configuration options.
* #13264: Rename the :rst:dir:`math` directive's ``nowrap``option
to :rst:dir:`no-wrap``,
and rename the :rst:dir:`autosummary` directive's ``nosignatures``option
to :rst:dir:`no-signatures``.
Patch by Adam Turner.

Bugs fixed
----------
Expand Down
10 changes: 9 additions & 1 deletion doc/usage/extensions/autosummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ The :mod:`sphinx.ext.autosummary` extension does this in two parts:
.. versionadded:: 3.1
.. rst:directive:option:: nosignatures
.. rst:directive:option:: no-signatures
Do not show function signatures in the summary.
.. versionadded:: 0.6
.. versionchanged:: 8.2
The directive option ``:nosignatures:`` was renamed to ``:no-signatures:``.
The previous name has been retained as an alias,
but will be deprecated and removed
in a future version of Sphinx.
.. rst:directive:option:: template: filename
Specify a custom template for rendering the summary.
Expand Down
12 changes: 10 additions & 2 deletions doc/usage/restructuredtext/directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1553,21 +1553,29 @@ or use Python raw strings (``r"raw"``).
number to be issued. See :rst:role:`eq` for an example. The numbering
style depends on the output format.
.. rst:directive:option:: nowrap
.. rst:directive:option:: no-wrap
Prevent wrapping of the given math in a math environment.
When you give this option, you must make sure
yourself that the math is properly set up.
For example::
.. math::
:nowrap:
:no-wrap:
\begin{eqnarray}
y & = & ax^2 + bx + c \\
f(x) & = & x^2 + 2xy + y^2
\end{eqnarray}
.. versionchanged:: 8.2
The directive option ``:nowrap:`` was renamed to ``:no-wrap:``.
The previous name has been retained as an alias,
but will be deprecated and removed
in a future version of Sphinx.
.. _AmSMath LaTeX package: https://www.ams.org/publications/authors/tex/amslatex

.. seealso::
Expand Down
3 changes: 2 additions & 1 deletion sphinx/directives/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class MathDirective(SphinxDirective):
'label': directives.unchanged,
'name': directives.unchanged,
'class': directives.class_option,
'no-wrap': directives.flag,
'nowrap': directives.flag,
}

Expand All @@ -158,7 +159,7 @@ def run(self) -> list[Node]:
docname=self.env.docname,
number=None,
label=label,
nowrap='nowrap' in self.options,
nowrap='no-wrap' in self.options or 'nowrap' in self.options,
)
self.add_name(node)
self.set_source_info(node)
Expand Down
5 changes: 3 additions & 2 deletions sphinx/ext/autosummary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,10 @@ class Autosummary(SphinxDirective):
'caption': directives.unchanged_required,
'class': directives.class_option,
'toctree': directives.unchanged,
'nosignatures': directives.flag,
'no-signatures': directives.flag,
'recursive': directives.flag,
'template': directives.unchanged,
'nosignatures': directives.flag,
}

def run(self) -> list[Node]:
Expand Down Expand Up @@ -462,7 +463,7 @@ def append_row(*column_texts: str) -> None:

for name, sig, summary, real_name in items:
qualifier = 'obj'
if 'nosignatures' not in self.options:
if 'no-signatures' not in self.options and 'nosignatures' not in self.options:
col1 = f':py:{qualifier}:`{name} <{real_name}>`\\ {rst.escape(sig)}'
else:
col1 = f':py:{qualifier}:`{name} <{real_name}>`'
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/imgmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def html_visit_math(self: HTML5Translator, node: nodes.math) -> None:


def html_visit_displaymath(self: HTML5Translator, node: nodes.math_block) -> None:
if node['nowrap']:
if node['no-wrap'] or node['nowrap']:
latex = node.astext()
else:
latex = wrap_displaymath(node.astext(), None, False)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/mathjax.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def html_visit_math(self: HTML5Translator, node: nodes.math) -> None:

def html_visit_displaymath(self: HTML5Translator, node: nodes.math_block) -> None:
self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight'))
if node['nowrap']:
if node['no-wrap'] or node['nowrap']:
self.body.append(self.encode(node.astext()))
self.body.append('</div>')
raise nodes.SkipNode
Expand Down
2 changes: 1 addition & 1 deletion sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2465,7 +2465,7 @@ def visit_math_block(self, node: nodes.math_block) -> None:
else:
label = None

if node.get('nowrap'):
if node.get('no-wrap', False) or node.get('nowrap', False):
if label:
self.body.append(r'\label{%s}' % label)
self.body.append(node.astext())
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-autosummary-ext/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

.. autosummary::
:nosignatures:
:no-signatures:
:toctree:

dummy_module
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-ext-math/math.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This is inline math: :math:`a^2 + b^2 = c^2`.
n \in \mathbb N
.. math::
:nowrap:
:no-wrap:
a + 1 < b
Expand Down
2 changes: 1 addition & 1 deletion tests/roots/test-root/math.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This is inline math: :math:`a^2 + b^2 = c^2`.
n \in \mathbb N

.. math::
:nowrap:
:no-wrap:

a + 1 < b

Expand Down

0 comments on commit 962a7ca

Please sign in to comment.