From 00cd01e10e3c854678b53d28853ea2e8611859ae Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Fri, 26 Jul 2024 21:41:10 +0900 Subject: [PATCH] Styling --- src/doc/common/static/custom-furo.css | 5 ++ src/sage/misc/sagedoc_conf.py | 1 + .../probability/probability_distribution.pyx | 15 ++-- src/sage/structure/formal_sum.py | 31 +++---- src/sage_docbuild/conf.py | 82 +++++++++++++++++++ 5 files changed, 112 insertions(+), 22 deletions(-) diff --git a/src/doc/common/static/custom-furo.css b/src/doc/common/static/custom-furo.css index 85d2a0776cf..61c643f07ca 100644 --- a/src/doc/common/static/custom-furo.css +++ b/src/doc/common/static/custom-furo.css @@ -74,3 +74,8 @@ body[data-theme="dark"] { } } +/* For sections INPUT, OUTPUT, EXAMPLES, etc. */ + +abbr { + font-weight: 450; +} diff --git a/src/sage/misc/sagedoc_conf.py b/src/sage/misc/sagedoc_conf.py index d8e6c95e9a4..0fccc470c91 100644 --- a/src/sage/misc/sagedoc_conf.py +++ b/src/sage/misc/sagedoc_conf.py @@ -154,6 +154,7 @@ def apply(self): node.rawsource = source node[:] = [nodes.Text(source)] + # This is only used by sage.misc.sphinxify diff --git a/src/sage/probability/probability_distribution.pyx b/src/sage/probability/probability_distribution.pyx index 59ba4a95ab6..b405206c1f2 100644 --- a/src/sage/probability/probability_distribution.pyx +++ b/src/sage/probability/probability_distribution.pyx @@ -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 @@ -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 diff --git a/src/sage/structure/formal_sum.py b/src/sage/structure/formal_sum.py index f037f71042e..f91461b11f2 100644 --- a/src/sage/structure/formal_sum.py +++ b/src/sage/structure/formal_sum.py @@ -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:: @@ -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 + """ # **************************************************************************** diff --git a/src/sage_docbuild/conf.py b/src/sage_docbuild/conf.py index 50d56ccfd05..46adbcfc6f5 100644 --- a/src/sage_docbuild/conf.py +++ b/src/sage_docbuild/conf.py @@ -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) @@ -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)