From 8683824da6c1538788326c184574da0a9f55e214 Mon Sep 17 00:00:00 2001 From: Shailesh Kumar Date: Sat, 18 Jun 2022 09:55:54 +0530 Subject: [PATCH 1/3] Support for assumption directive #73 --- README.md | 2 +- docs/source/index.md | 2 +- docs/source/syntax.md | 37 ++++++++++++++++++++++++++++++++++ setup.py | 2 +- sphinx_proof/_static/proof.css | 12 +++++++++++ sphinx_proof/nodes.py | 4 ++++ sphinx_proof/proof_type.py | 8 ++++++++ 7 files changed, 64 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 12f22a7..9c2a0ed 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension for producing proof, theorem, axiom, lemma, definition, criterion, remark, conjecture, -corollary, algorithm, example, property, observation and proposition directives. +corollary, algorithm, example, property, observation, proposition and assumption directives. ## Get started diff --git a/docs/source/index.md b/docs/source/index.md index 71dcf78..21ebe67 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -17,7 +17,7 @@ zreferences This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension for producing proof, theorem, axiom, lemma, definition, criterion, remark, conjecture, -corollary, algorithm, example, property, observation and proposition directives. +corollary, algorithm, example, property, observation, proposition and assumption directives. **Features**: diff --git a/docs/source/syntax.md b/docs/source/syntax.md index e430075..044c578 100644 --- a/docs/source/syntax.md +++ b/docs/source/syntax.md @@ -696,6 +696,43 @@ This is a dummy proposition directive. You can refer to a proposition using the `{prf:ref}` role like: ```{prf:ref}`my-proposition` ```, which will replace the reference with the proposition number like so: {prf:ref}`my-proposition`. When an explicit text is provided, this caption will serve as the title of the reference. + +### Assumptions + +An assumption directive can be included using the `prf:assumption` pattern. The directive is enumerated by default and can take in an optional title argument. The following options are also supported: + +* `label` : text + + A unique identifier for your assumption that you can use to reference it with `{prf:ref}`. Cannot contain spaces or special characters. +* `class` : text + + Value of the assumption’s class attribute which can be used to add custom CSS or JavaScript. +* `nonumber` : flag (empty) + + Turns off assumption auto numbering. + +**Example** + +```{prf:assumption} +:label: my-assumption + +This is a dummy assumption directive. +``` + +**MyST Syntax** + +``````md +```{prf:assumption} +:label: my-assumption + +This is a dummy assumption directive. +``` +`````` + +#### Referencing Assumptions + +You can refer to an assumption using the `{prf:ref}` role like: ```{prf:ref}`my-assumption` ```, which will replace the reference with the assumption number like so: {prf:ref}`my-assumption`. When an explicit text is provided, this caption will serve as the title of the reference. + ## How to Hide Content Directive content can be hidden using the `dropdown` class which is available through [sphinx-togglebutton](https://sphinx-togglebutton.readthedocs.io/en/latest/). If your project utilizes the [MyST-NB](https://myst-nb.readthedocs.io/en/latest/) extension, there is no need to activate `sphinx-togglebutton` since it is already bundled with `MyST-NB`. diff --git a/setup.py b/setup.py index 4a16c5d..51687d8 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ LONG_DESCRIPTION = """ This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension for producing proof, theorem, axiom, lemma, definition, criterion, remark, conjecture, -corollary, algorithm, example, property, observation and proposition directives. +corollary, algorithm, example, property, observation, proposition, and assumption directives. This project is maintained and supported by [najuzilu](https://github.com/najuzilu). """ diff --git a/sphinx_proof/_static/proof.css b/sphinx_proof/_static/proof.css index 51e0c9f..b81a24d 100644 --- a/sphinx_proof/_static/proof.css +++ b/sphinx_proof/_static/proof.css @@ -194,3 +194,15 @@ div.proposition { div.proposition p.admonition-title { background-color: var(--note-title-color); } +/********************************************* +* Assumption * +*********************************************/ +div.assumption { + border-color: var(--hint-border-color); + background-color: var(--hint-title-color); +} + +div.assumption p.admonition-title { + background-color: var(--hint-title-color); +} + diff --git a/sphinx_proof/nodes.py b/sphinx_proof/nodes.py index 8e7a429..18a78c5 100644 --- a/sphinx_proof/nodes.py +++ b/sphinx_proof/nodes.py @@ -182,6 +182,9 @@ class proposition_node(nodes.Admonition, nodes.Element): class unenumerable_node(nodes.Admonition, nodes.Element): pass +class assumption_node(nodes.Admonition, nodes.Element): + pass + NODE_TYPES = { "axiom": axiom_node, @@ -197,4 +200,5 @@ class unenumerable_node(nodes.Admonition, nodes.Element): "property": property_node, "observation": observation_node, "proposition": proposition_node, + "assumption": assumption_node, } diff --git a/sphinx_proof/proof_type.py b/sphinx_proof/proof_type.py index 12dafb2..bb0bb79 100644 --- a/sphinx_proof/proof_type.py +++ b/sphinx_proof/proof_type.py @@ -88,6 +88,13 @@ class PropositionDirective(ElementDirective): name = "proposition" +class AssumptionDirective(ElementDirective): + """A custom assumption directive.""" + + name = "assumption" + + + PROOF_TYPES = { "axiom": AxiomDirective, @@ -103,4 +110,5 @@ class PropositionDirective(ElementDirective): "property": PropertyDirective, "observation": ObservationDirective, "proposition": PropositionDirective, + "assumption" : AssumptionDirective } From 12a396277668f0b5df69b64a21ab8d2e43751aa0 Mon Sep 17 00:00:00 2001 From: AakashGC Date: Wed, 13 Jul 2022 11:46:27 +1000 Subject: [PATCH 2/3] pre-commit runs --- setup.py | 3 ++- sphinx_proof/_static/proof.css | 1 - sphinx_proof/nodes.py | 1 + sphinx_proof/proof_type.py | 5 ++--- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 51687d8..8975b4c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,8 @@ LONG_DESCRIPTION = """ This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension for producing proof, theorem, axiom, lemma, definition, criterion, remark, conjecture, -corollary, algorithm, example, property, observation, proposition, and assumption directives. +corollary, algorithm, example, property, observation, proposition, and +assumption directives. This project is maintained and supported by [najuzilu](https://github.com/najuzilu). """ diff --git a/sphinx_proof/_static/proof.css b/sphinx_proof/_static/proof.css index b81a24d..f975944 100644 --- a/sphinx_proof/_static/proof.css +++ b/sphinx_proof/_static/proof.css @@ -205,4 +205,3 @@ div.assumption { div.assumption p.admonition-title { background-color: var(--hint-title-color); } - diff --git a/sphinx_proof/nodes.py b/sphinx_proof/nodes.py index 18a78c5..5f164ae 100644 --- a/sphinx_proof/nodes.py +++ b/sphinx_proof/nodes.py @@ -182,6 +182,7 @@ class proposition_node(nodes.Admonition, nodes.Element): class unenumerable_node(nodes.Admonition, nodes.Element): pass + class assumption_node(nodes.Admonition, nodes.Element): pass diff --git a/sphinx_proof/proof_type.py b/sphinx_proof/proof_type.py index bb0bb79..9176e97 100644 --- a/sphinx_proof/proof_type.py +++ b/sphinx_proof/proof_type.py @@ -88,14 +88,13 @@ class PropositionDirective(ElementDirective): name = "proposition" + class AssumptionDirective(ElementDirective): """A custom assumption directive.""" name = "assumption" - - PROOF_TYPES = { "axiom": AxiomDirective, "theorem": TheoremDirective, @@ -110,5 +109,5 @@ class AssumptionDirective(ElementDirective): "property": PropertyDirective, "observation": ObservationDirective, "proposition": PropositionDirective, - "assumption" : AssumptionDirective + "assumption": AssumptionDirective, } From 0abcab192995657b81509f059af363574c615cfa Mon Sep 17 00:00:00 2001 From: Shailesh Kumar Date: Wed, 13 Jul 2022 11:50:56 +0530 Subject: [PATCH 3/3] translation json for assumption directive --- sphinx_proof/translations/jsons/Assumption.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 sphinx_proof/translations/jsons/Assumption.json diff --git a/sphinx_proof/translations/jsons/Assumption.json b/sphinx_proof/translations/jsons/Assumption.json new file mode 100644 index 0000000..17e55b3 --- /dev/null +++ b/sphinx_proof/translations/jsons/Assumption.json @@ -0,0 +1 @@ +[{"language":"English","symbol":"en","text":"Assumption"}]