Skip to content
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

Style AUTHORS, INPUT, OUTPUT, EXAMPLES, etc. #37614

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/doc/common/static/custom-furo.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ body[data-theme="dark"] {
}
}

/* For sections INPUT, OUTPUT, EXAMPLES, etc. */

abbr {
font-weight: 450;
}
1 change: 1 addition & 0 deletions src/sage/misc/sagedoc_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def apply(self):
node.rawsource = source
node[:] = [nodes.Text(source)]


# This is only used by sage.misc.sphinxify


Expand Down
15 changes: 8 additions & 7 deletions src/sage/probability/probability_distribution.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ This module provides three types of probability distributions:

- :class:`GeneralDiscreteDistribution`: user-defined discrete distributions.

REFERENCES:

- GNU gsl library, General discrete distributions
http://www.gnu.org/software/gsl/manual/html_node/General-Discrete-Distributions.html

- GNU gsl library, Random number distributions
http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distributions.html

AUTHORS:

- Josh Kantor (2007-02): first version
Expand All @@ -21,13 +29,6 @@ AUTHORS:

- Kwankyu Lee (2010-05-29): F-distribution support.

REFERENCES:

GNU gsl library, General discrete distributions
http://www.gnu.org/software/gsl/manual/html_node/General-Discrete-Distributions.html

GNU gsl library, Random number distributions
http://www.gnu.org/software/gsl/manual/html_node/Random-Number-Distributions.html
"""
# ****************************************************************************
# Copyright (C) 2004, 2005, 2006 Joshua Kantor <[email protected]>
Expand Down
31 changes: 16 additions & 15 deletions src/sage/structure/formal_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@
"""
Formal sums

AUTHORS:

- David Harvey (2006-09-20): changed FormalSum not to derive from
"list" anymore, because that breaks new Element interface

- Nick Alexander (2006-12-06): added test cases.

- William Stein (2006, 2009): wrote the first version in 2006, documented it in 2009.
This module provides the following functions:

- Volker Braun (2010-07-19): new-style coercions, documentation
added. FormalSums now derives from UniqueRepresentation.

FUNCTIONS:

- ``FormalSums(ring)`` -- create the module of formal finite sums with
- ``FormalSums(ring)`` creates the module of formal finite sums with
coefficients in the given ring.

- ``FormalSum(list of pairs (coeff, number))`` -- create a formal sum.
- ``FormalSum(list of pairs (coeff, number))`` creates a formal sum.

EXAMPLES::

Expand Down Expand Up @@ -49,6 +37,19 @@
2/3 + -5/7
sage: loads(dumps(a)) == a
True

AUTHORS:

- David Harvey (2006-09-20): changed FormalSum not to derive from
"list" anymore, because that breaks new Element interface

- Nick Alexander (2006-12-06): added test cases

- William Stein (2006, 2009): wrote the first version in 2006, documented it in 2009

- Volker Braun (2010-07-19): new-style coercions, documentation
added. FormalSums now derives from UniqueRepresentation

"""

# ****************************************************************************
Expand Down
82 changes: 82 additions & 0 deletions src/sage_docbuild/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,87 @@ def apply(self):
parent.insert(index + 1, container)


class DocstringTransform(SphinxTransform):
r"""
Transform sections in Sage docstrings for better rendering.

The following are tests.

AUTHORS:

- Alice
- Bob

INPUT:

- one
- two

OUTPUT:

three

OUTPUT: three

EXAMPLE::

sage: 1 + 2
3

EXAMPLES::

sage: 1 + 2
3

EXAMPLE:

We show that `1 + 2 = 3`::

sage: 1 + 2
3

EXAMPLES:

We show that `1 + 2 = 3`::

sage: 1 + 2
3

"""
default_priority = 600

def apply(self):
for node in self.document.traverse(nodes.paragraph):
if isinstance(node.children[0], nodes.Text) and node.children[0].astext().strip() == 'AUTHORS:':
list_node = node.next_node(siblings=True, descend=False)
if isinstance(list_node, nodes.bullet_list):
new_node = nodes.admonition(classes=['authors'], admonitionclass='authors')
node.replace_self(new_node)
node = new_node
admonition_title = nodes.title()
admonition_title.append(nodes.Text('Authors'))
node.insert(0, admonition_title)
node.append(list_node)
node.parent.remove(list_node)
# Not applied for now, Issue #37614
if False and isinstance(node.children[0], nodes.Text):
text = node.children[0].astext()
for section in ['INPUT', 'OUTPUT', 'EXAMPLES', 'EXAMPLE', 'TESTS', 'TEST',
'ALGORITHM', 'REFERENCE', 'REFERENCES']:
if text.startswith(f'{section}:'):
parent = node.parent
index = parent.index(node)
parent.remove(node)
abbr_node = nodes.abbreviation()
remaining_text = text[len(f'{section}:'):]
abbr_node += nodes.Text(f'{section}:')
para = nodes.paragraph()
para += abbr_node
para += nodes.Text(remaining_text)
parent.insert(index, para)
break


# This replaces the setup() in sage.misc.sagedoc_conf
def setup(app):
app.connect('autodoc-process-docstring', process_docstring_cython)
Expand All @@ -1046,6 +1127,7 @@ def setup(app):
app.connect('autodoc-process-docstring', skip_TESTS_block)
app.connect('autodoc-skip-member', skip_member)
app.add_transform(SagemathTransform)
app.add_transform(DocstringTransform)
if SAGE_LIVE_DOC == 'yes' or SAGE_PREPARSED_DOC == 'yes':
app.add_transform(SagecodeTransform)

Expand Down
Loading