From f43d4b9f52e1dae7d51051d46d4a1501da3b135c Mon Sep 17 00:00:00 2001 From: Anthony_3972 Date: Mon, 12 Sep 2022 11:16:34 +0800 Subject: [PATCH 1/3] exercise& Chinese translation --- README.md | 2 +- docs/source/index.md | 2 +- docs/source/syntax.md | 38 +++++++++++++++++++ sphinx_proof/_static/proof.css | 11 ++++++ sphinx_proof/nodes.py | 3 ++ sphinx_proof/proof_type.py | 6 +++ sphinx_proof/translations/_convert.py | 2 +- .../translations/jsons/Algorithm.json | 2 +- .../translations/jsons/Assumption.json | 2 +- sphinx_proof/translations/jsons/Axiom.json | 2 +- .../translations/jsons/Conjecture.json | 2 +- .../translations/jsons/Criterion.json | 2 +- .../translations/jsons/Definition.json | 2 +- sphinx_proof/translations/jsons/Example.json | 2 +- sphinx_proof/translations/jsons/Exercise.json | 1 + sphinx_proof/translations/jsons/Lemma.json | 2 +- .../translations/jsons/Observation.json | 2 +- sphinx_proof/translations/jsons/Property.json | 2 +- .../translations/jsons/Proposition.json | 2 +- sphinx_proof/translations/jsons/Remark.json | 2 +- sphinx_proof/translations/jsons/Theorem.json | 2 +- 21 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 sphinx_proof/translations/jsons/Exercise.json diff --git a/README.md b/README.md index 9c2a0ed..fb7c57a 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, proposition and assumption directives. +corollary, algorithm, example, property, observation, proposition ,assumption and exercise directives. ## Get started diff --git a/docs/source/index.md b/docs/source/index.md index 21ebe67..1a976b9 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, proposition and assumption directives. +corollary, algorithm, example, property, observation, proposition, assumption and exercise directives. **Features**: diff --git a/docs/source/syntax.md b/docs/source/syntax.md index 044c578..75d1f51 100644 --- a/docs/source/syntax.md +++ b/docs/source/syntax.md @@ -733,6 +733,44 @@ This is a dummy assumption directive. 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. + + +### Exercises + +An exercise directive can be included using the `prf:exercise` 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 exercise that you can use to reference it with `{prf:ref}`. Cannot contain spaces or special characters. +* `class` : text + + Value of the exercise’s class attribute which can be used to add custom CSS or JavaScript. +* `nonumber` : flag (empty) + + Turns off exercise auto numbering. + +**Example** + +```{prf:exercise} +:label: your-exercise + +This is a dummy exercise directive. +``` + +**MyST Syntax** + +``````md +```{prf:exercise} +:label: your-exercise + +This is a dummy exercise directive. +``` +`````` + +#### Referencing Exercises + +You can refer to an exercise using the `{prf:ref}` role like: ```{prf:ref}`your-exercise` ```, which will replace the reference with the exercise number like so: {prf:ref}`your-exercise`. 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/sphinx_proof/_static/proof.css b/sphinx_proof/_static/proof.css index f975944..d711f0e 100644 --- a/sphinx_proof/_static/proof.css +++ b/sphinx_proof/_static/proof.css @@ -205,3 +205,14 @@ div.assumption { div.assumption p.admonition-title { background-color: var(--hint-title-color); } +/********************************************* +* Exercises * +*********************************************/ +div.exercise { + border-color: var(--hint-border-color); + background-color: var(--hint-title-color); +} + +div.exercise p.admonition-title { + background-color: var(--hint-title-color); +} diff --git a/sphinx_proof/nodes.py b/sphinx_proof/nodes.py index 5f164ae..c88446b 100644 --- a/sphinx_proof/nodes.py +++ b/sphinx_proof/nodes.py @@ -186,6 +186,8 @@ class unenumerable_node(nodes.Admonition, nodes.Element): class assumption_node(nodes.Admonition, nodes.Element): pass +class exercise_node(nodes.Admonition, nodes.Element): + pass NODE_TYPES = { "axiom": axiom_node, @@ -202,4 +204,5 @@ class assumption_node(nodes.Admonition, nodes.Element): "observation": observation_node, "proposition": proposition_node, "assumption": assumption_node, + "exercise": exercise_node, } diff --git a/sphinx_proof/proof_type.py b/sphinx_proof/proof_type.py index 9176e97..e9cb498 100644 --- a/sphinx_proof/proof_type.py +++ b/sphinx_proof/proof_type.py @@ -94,6 +94,11 @@ class AssumptionDirective(ElementDirective): name = "assumption" + +class ExerciseDirective(ElementDirective): + """A custom exercise directive.""" + + name = "exercise" PROOF_TYPES = { "axiom": AxiomDirective, @@ -110,4 +115,5 @@ class AssumptionDirective(ElementDirective): "observation": ObservationDirective, "proposition": PropositionDirective, "assumption": AssumptionDirective, + "exercise": ExerciseDirective, } diff --git a/sphinx_proof/translations/_convert.py b/sphinx_proof/translations/_convert.py index 8fc9928..74198e4 100755 --- a/sphinx_proof/translations/_convert.py +++ b/sphinx_proof/translations/_convert.py @@ -34,7 +34,7 @@ def convert_json(folder=None): """ out_path.write_text(header) - with out_path.open("a") as f: + with out_path.open("a", encoding = "utf8") as f: f.write("\n") f.write(f'msgid "{english}"\n') text = item["text"].replace('"', '\\"') diff --git a/sphinx_proof/translations/jsons/Algorithm.json b/sphinx_proof/translations/jsons/Algorithm.json index aec3871..d08d1f9 100644 --- a/sphinx_proof/translations/jsons/Algorithm.json +++ b/sphinx_proof/translations/jsons/Algorithm.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Algorithm"},{"language":"French","symbol":"fr","text":"Algorithme"},{"language":"Italian","symbol":"it","text":"Algoritmo"},{"language":"Czech","symbol":"cs","text":"Algoritmus"}] +[{"language":"English","symbol":"en","text":"Algorithm"},{"language":"French","symbol":"fr","text":"Algorithme"},{"language":"Italian","symbol":"it","text":"Algoritmo"},{"language":"Czech","symbol":"cs","text":"Algoritmus"},{"language":"Chinese","symbol":"zh_CN","text":"算法"}] diff --git a/sphinx_proof/translations/jsons/Assumption.json b/sphinx_proof/translations/jsons/Assumption.json index 17e55b3..9103f11 100644 --- a/sphinx_proof/translations/jsons/Assumption.json +++ b/sphinx_proof/translations/jsons/Assumption.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Assumption"}] +[{"language":"English","symbol":"en","text":"Assumption"},{"language":"Chinese","symbol":"zh_CN","text":"假设"}] diff --git a/sphinx_proof/translations/jsons/Axiom.json b/sphinx_proof/translations/jsons/Axiom.json index a6c667a..85178c7 100644 --- a/sphinx_proof/translations/jsons/Axiom.json +++ b/sphinx_proof/translations/jsons/Axiom.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Axiom"},{"language":"French","symbol":"fr","text":"Axiome"},{"language":"Italian","symbol":"it","text":"Assioma"},{"language":"Czech","symbol":"cs","text":"Axiom"}] +[{"language":"English","symbol":"en","text":"Axiom"},{"language":"French","symbol":"fr","text":"Axiome"},{"language":"Italian","symbol":"it","text":"Assioma"},{"language":"Czech","symbol":"cs","text":"Axiom"},{"language":"Chinese","symbol":"zh_CN","text":"公理"}] diff --git a/sphinx_proof/translations/jsons/Conjecture.json b/sphinx_proof/translations/jsons/Conjecture.json index 2756d89..443534b 100644 --- a/sphinx_proof/translations/jsons/Conjecture.json +++ b/sphinx_proof/translations/jsons/Conjecture.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Conjecture"},{"language":"Arabic","symbol":"ar","text":"تخمين"},{"language":"Dutch","symbol":"nl","text":"Vermoeden"},{"language":"French","symbol":"fr","text":"Conjecture"},{"language":"German","symbol":"de","text":"Vermutung"},{"language":"Italian","symbol":"it","text":"Congetturare"},{"language":"Japanese","symbol":"ja","text":"推測"},{"language":"Russian","symbol":"ru","text":"Гипотеза"},{"language":"Spanish","symbol":"es","text":"Conjetura"},{"language":"Czech","symbol":"cs","text":"Domněnka"}] +[{"language":"English","symbol":"en","text":"Conjecture"},{"language":"Arabic","symbol":"ar","text":"تخمين"},{"language":"Dutch","symbol":"nl","text":"Vermoeden"},{"language":"French","symbol":"fr","text":"Conjecture"},{"language":"German","symbol":"de","text":"Vermutung"},{"language":"Italian","symbol":"it","text":"Congetturare"},{"language":"Japanese","symbol":"ja","text":"推測"},{"language":"Russian","symbol":"ru","text":"Гипотеза"},{"language":"Spanish","symbol":"es","text":"Conjetura"},{"language":"Czech","symbol":"cs","text":"Domněnka"},{"language":"Chinese","symbol":"zh_CN","text":"猜想"}] diff --git a/sphinx_proof/translations/jsons/Criterion.json b/sphinx_proof/translations/jsons/Criterion.json index e4bc089..147ab8d 100644 --- a/sphinx_proof/translations/jsons/Criterion.json +++ b/sphinx_proof/translations/jsons/Criterion.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Criterion"},{"language":"French","symbol":"fr","text":"Critère"},{"language":"Italian","symbol":"it","text":"Criterio"},{"language":"Czech","symbol":"cs","text":"Kritérium"}] +[{"language":"English","symbol":"en","text":"Criterion"},{"language":"French","symbol":"fr","text":"Critère"},{"language":"Italian","symbol":"it","text":"Criterio"},{"language":"Czech","symbol":"cs","text":"Kritérium"},{"language":"Chinese","symbol":"zh_CN","text":"准则"}] diff --git a/sphinx_proof/translations/jsons/Definition.json b/sphinx_proof/translations/jsons/Definition.json index c033dcb..b57685f 100644 --- a/sphinx_proof/translations/jsons/Definition.json +++ b/sphinx_proof/translations/jsons/Definition.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Definition"},{"language":"Arabic","symbol":"ar","text":"تعريف"},{"language":"Dutch","symbol":"nl","text":"Definitie"},{"language":"French","symbol":"fr","text":"Définition"},{"language":"German","symbol":"de","text":"Definition"},{"language":"Italian","symbol":"it","text":"Definizione"},{"language":"Japanese","symbol":"ja","text":"意味"},{"language":"Russian","symbol":"ru","text":"Определение"},{"language":"Spanish","symbol":"es","text":"Definición"},{"language":"Czech","symbol":"cs","text":"Definice"}] +[{"language":"English","symbol":"en","text":"Definition"},{"language":"Arabic","symbol":"ar","text":"تعريف"},{"language":"Dutch","symbol":"nl","text":"Definitie"},{"language":"French","symbol":"fr","text":"Définition"},{"language":"German","symbol":"de","text":"Definition"},{"language":"Italian","symbol":"it","text":"Definizione"},{"language":"Japanese","symbol":"ja","text":"意味"},{"language":"Russian","symbol":"ru","text":"Определение"},{"language":"Spanish","symbol":"es","text":"Definición"},{"language":"Czech","symbol":"cs","text":"Definice"},{"language":"Chinese","symbol":"zh_CN","text":"定义"}] diff --git a/sphinx_proof/translations/jsons/Example.json b/sphinx_proof/translations/jsons/Example.json index e6b8fe7..ca62e8e 100644 --- a/sphinx_proof/translations/jsons/Example.json +++ b/sphinx_proof/translations/jsons/Example.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Example"},{"language":"French","symbol":"fr","text":"Exemple"},{"language":"Italian","symbol":"it","text":"Esempio"},{"language":"Czech","symbol":"cs","text":"Příklad"}] +[{"language":"English","symbol":"en","text":"Example"},{"language":"French","symbol":"fr","text":"Exemple"},{"language":"Italian","symbol":"it","text":"Esempio"},{"language":"Czech","symbol":"cs","text":"Příklad"},{"language":"Chinese","symbol":"zh_CN","text":"例子"}] diff --git a/sphinx_proof/translations/jsons/Exercise.json b/sphinx_proof/translations/jsons/Exercise.json new file mode 100644 index 0000000..725bf48 --- /dev/null +++ b/sphinx_proof/translations/jsons/Exercise.json @@ -0,0 +1 @@ +[{"language":"English","symbol":"en","text":"Exercise"},{"language":"Chinese","symbol":"zh_CN","text":"练习"}] diff --git a/sphinx_proof/translations/jsons/Lemma.json b/sphinx_proof/translations/jsons/Lemma.json index 4746ea9..6f76db7 100644 --- a/sphinx_proof/translations/jsons/Lemma.json +++ b/sphinx_proof/translations/jsons/Lemma.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Lemma"},{"language":"Arabic","symbol":"ar","text":"ليما"},{"language":"Dutch","symbol":"nl","text":"Lemma"},{"language":"French","symbol":"fr","text":"Lemme"},{"language":"German","symbol":"de","text":"Lemma"},{"language":"Italian","symbol":"it","text":"Lemma"},{"language":"Japanese","symbol":"ja","text":"補題"},{"language":"Russian","symbol":"ru","text":"Лемма"},{"language":"Spanish","symbol":"es","text":"Lema"},{"language":"Czech","symbol":"cs","text":"Lemma"}] +[{"language":"English","symbol":"en","text":"Lemma"},{"language":"Arabic","symbol":"ar","text":"ليما"},{"language":"Dutch","symbol":"nl","text":"Lemma"},{"language":"French","symbol":"fr","text":"Lemme"},{"language":"German","symbol":"de","text":"Lemma"},{"language":"Italian","symbol":"it","text":"Lemma"},{"language":"Japanese","symbol":"ja","text":"補題"},{"language":"Russian","symbol":"ru","text":"Лемма"},{"language":"Spanish","symbol":"es","text":"Lema"},{"language":"Czech","symbol":"cs","text":"Lemma"},{"language":"Chinese","symbol":"zh_CN","text":"引理"}] diff --git a/sphinx_proof/translations/jsons/Observation.json b/sphinx_proof/translations/jsons/Observation.json index 201ccb2..5d7ca1e 100644 --- a/sphinx_proof/translations/jsons/Observation.json +++ b/sphinx_proof/translations/jsons/Observation.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Observation"},{"language":"French","symbol":"fr","text":"Observation"},{"language":"Italian","symbol":"it","text":"Osservazione"},{"language":"Czech","symbol":"cs","text":"Pozorování"}] +[{"language":"English","symbol":"en","text":"Observation"},{"language":"French","symbol":"fr","text":"Observation"},{"language":"Italian","symbol":"it","text":"Osservazione"},{"language":"Czech","symbol":"cs","text":"Pozorování"},{"language":"Chinese","symbol":"zh_CN","text":"观测"}] diff --git a/sphinx_proof/translations/jsons/Property.json b/sphinx_proof/translations/jsons/Property.json index 2543e61..03983f7 100644 --- a/sphinx_proof/translations/jsons/Property.json +++ b/sphinx_proof/translations/jsons/Property.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Property"},{"language":"French","symbol":"fr","text":"Propriété"},{"language":"Italian","symbol":"it","text":"Proprietà"},{"language":"Czech","symbol":"cs","text":"Vlastnost"}] +[{"language":"English","symbol":"en","text":"Property"},{"language":"French","symbol":"fr","text":"Propriété"},{"language":"Italian","symbol":"it","text":"Proprietà"},{"language":"Czech","symbol":"cs","text":"Vlastnost"},{"language":"Chinese","symbol":"zh_CN","text":"性质"}] diff --git a/sphinx_proof/translations/jsons/Proposition.json b/sphinx_proof/translations/jsons/Proposition.json index 153e152..2bfa2a5 100644 --- a/sphinx_proof/translations/jsons/Proposition.json +++ b/sphinx_proof/translations/jsons/Proposition.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Proposition"},{"language":"French","symbol":"fr","text":"Proposition"},{"language":"Italian","symbol":"it","text":"Proposizione"}] +[{"language":"English","symbol":"en","text":"Proposition"},{"language":"French","symbol":"fr","text":"Proposition"},{"language":"Italian","symbol":"it","text":"Proposizione"},{"language":"Chinese","symbol":"zh_CN","text":"命题"}] diff --git a/sphinx_proof/translations/jsons/Remark.json b/sphinx_proof/translations/jsons/Remark.json index fc89083..1d22d14 100644 --- a/sphinx_proof/translations/jsons/Remark.json +++ b/sphinx_proof/translations/jsons/Remark.json @@ -1,2 +1,2 @@ [{"language":"English","symbol":"en","text":"Remark"},{"language":"Arabic","symbol":"ar","text":"ملاحظة"},{"language":"Dutch","symbol":"nl","text":"Opmerking"},{"language":"French","symbol":"fr","text":"Remarque"},{"language":"German","symbol":"de","text":"Anmerkung"},{"language":"Italian","symbol":"it","text":"osservazione"},{"language":"Japanese","symbol":"ja","text":"述べる"},{"language":"Russian","symbol":"ru","text":"Замечание"},{"language":"Spanish","symbol":"es","text":"Observación"}, -{"language":"Czech","symbol":"cs","text":"Poznámka"}] +{"language":"Czech","symbol":"cs","text":"Poznámka"},{"language":"Chinese","symbol":"zh_CN","text":"评注"}] diff --git a/sphinx_proof/translations/jsons/Theorem.json b/sphinx_proof/translations/jsons/Theorem.json index 1e7e49c..9d98985 100644 --- a/sphinx_proof/translations/jsons/Theorem.json +++ b/sphinx_proof/translations/jsons/Theorem.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Theorem"},{"language":"Arabic","symbol":"ar","text":"نظرية"},{"language":"Dutch","symbol":"nl","text":"Stelling"},{"language":"French","symbol":"fr","text":"Théorème"},{"language":"German","symbol":"de","text":"Satz"},{"language":"Italian","symbol":"it","text":"Teorema"},{"language":"Japanese","symbol":"ja","text":"定理"},{"language":"Russian","symbol":"ru","text":"Теорема"},{"language":"Spanish","symbol":"es","text":"Věta"}] +[{"language":"English","symbol":"en","text":"Theorem"},{"language":"Arabic","symbol":"ar","text":"نظرية"},{"language":"Dutch","symbol":"nl","text":"Stelling"},{"language":"French","symbol":"fr","text":"Théorème"},{"language":"German","symbol":"de","text":"Satz"},{"language":"Italian","symbol":"it","text":"Teorema"},{"language":"Japanese","symbol":"ja","text":"定理"},{"language":"Russian","symbol":"ru","text":"Теорема"},{"language":"Spanish","symbol":"es","text":"Věta"},{"language":"Chinese","symbol":"zh_CN","text":"定理"}] From 7d0e596e4f3d20c0daea944a796363c832ca6854 Mon Sep 17 00:00:00 2001 From: Anthony_3972 Date: Tue, 13 Sep 2022 16:05:31 +0800 Subject: [PATCH 2/3] pre-commit revision --- sphinx_proof/nodes.py | 2 ++ sphinx_proof/proof_type.py | 5 +++-- sphinx_proof/translations/_convert.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sphinx_proof/nodes.py b/sphinx_proof/nodes.py index c88446b..eaf5edc 100644 --- a/sphinx_proof/nodes.py +++ b/sphinx_proof/nodes.py @@ -186,9 +186,11 @@ class unenumerable_node(nodes.Admonition, nodes.Element): class assumption_node(nodes.Admonition, nodes.Element): pass + class exercise_node(nodes.Admonition, nodes.Element): pass + NODE_TYPES = { "axiom": axiom_node, "theorem": theorem_node, diff --git a/sphinx_proof/proof_type.py b/sphinx_proof/proof_type.py index e9cb498..9f819fe 100644 --- a/sphinx_proof/proof_type.py +++ b/sphinx_proof/proof_type.py @@ -94,11 +94,12 @@ class AssumptionDirective(ElementDirective): name = "assumption" - + class ExerciseDirective(ElementDirective): """A custom exercise directive.""" - name = "exercise" + name = "exercise" + PROOF_TYPES = { "axiom": AxiomDirective, diff --git a/sphinx_proof/translations/_convert.py b/sphinx_proof/translations/_convert.py index 74198e4..dfe4463 100755 --- a/sphinx_proof/translations/_convert.py +++ b/sphinx_proof/translations/_convert.py @@ -34,7 +34,7 @@ def convert_json(folder=None): """ out_path.write_text(header) - with out_path.open("a", encoding = "utf8") as f: + with out_path.open("a", encoding="utf8") as f: f.write("\n") f.write(f'msgid "{english}"\n') text = item["text"].replace('"', '\\"') From 58b778fd7a26c01c765c4375aec309e0884bbb52 Mon Sep 17 00:00:00 2001 From: Anthony_3972 Date: Tue, 4 Oct 2022 18:53:02 +0800 Subject: [PATCH 3/3] Add Facts directive --- README.md | 2 +- docs/source/index.md | 2 +- docs/source/syntax.md | 37 ++++++++++++++++++- setup.py | 4 +- sphinx_proof/_static/proof.css | 11 ++++++ sphinx_proof/nodes.py | 5 +++ sphinx_proof/proof_type.py | 7 ++++ sphinx_proof/translations/jsons/Fact.json | 1 + .../translations/jsons/Observation.json | 2 +- 9 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 sphinx_proof/translations/jsons/Fact.json diff --git a/README.md b/README.md index fb7c57a..24a26bb 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, proposition ,assumption and exercise directives. +corollary, algorithm, example, property, observation, proposition ,assumption, exercise and fact directives. ## Get started diff --git a/docs/source/index.md b/docs/source/index.md index 1a976b9..39b8177 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, proposition, assumption and exercise directives. +corollary, algorithm, example, property, observation, proposition, assumption, exercise and fact directives. **Features**: diff --git a/docs/source/syntax.md b/docs/source/syntax.md index 75d1f51..01714ee 100644 --- a/docs/source/syntax.md +++ b/docs/source/syntax.md @@ -766,11 +766,46 @@ This is a dummy exercise directive. This is a dummy exercise directive. ``` `````` - #### Referencing Exercises You can refer to an exercise using the `{prf:ref}` role like: ```{prf:ref}`your-exercise` ```, which will replace the reference with the exercise number like so: {prf:ref}`your-exercise`. When an explicit text is provided, this caption will serve as the title of the reference. +### Facts + +An fact directive can be included using the `prf:fact` 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 fact that you can use to reference it with `{prf:ref}`. Cannot contain spaces or special characters. +* `class` : text + + Value of the fact's class attribute which can be used to add custom CSS or JavaScript. +* `nonumber` : flag (empty) + + Turns off fact auto numbering. + +**Example** + +```{prf:fact} +:label: my-fact + +This is a dummy fact directive. +``` + +**MyST Syntax** + +``````md +```{prf:fact} +:label: my-fact + +This is a dummy fact directive. +``` +`````` + +#### Referencing Facts + +You can refer to an fact using the `{prf:ref}` role like: ```{prf:ref}`my-fact` ```, which will replace the reference with the fact number like so: {prf:ref}`my-fact`. 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 8975b4c..3f593c4 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +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, +assumption, exercise, and fact 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 d711f0e..9953385 100644 --- a/sphinx_proof/_static/proof.css +++ b/sphinx_proof/_static/proof.css @@ -216,3 +216,14 @@ div.exercise { div.exercise p.admonition-title { background-color: var(--hint-title-color); } +/********************************************* +* Facts * +*********************************************/ +div.fact { + border-color: var(--note-border-color); + background-color: var(--note-title-color); +} + +div.fact p.admonition-title { + background-color: var(--note-title-color); +} diff --git a/sphinx_proof/nodes.py b/sphinx_proof/nodes.py index eaf5edc..919f2cf 100644 --- a/sphinx_proof/nodes.py +++ b/sphinx_proof/nodes.py @@ -191,6 +191,10 @@ class exercise_node(nodes.Admonition, nodes.Element): pass +class fact_node(nodes.Admonition, nodes.Element): + pass + + NODE_TYPES = { "axiom": axiom_node, "theorem": theorem_node, @@ -207,4 +211,5 @@ class exercise_node(nodes.Admonition, nodes.Element): "proposition": proposition_node, "assumption": assumption_node, "exercise": exercise_node, + "fact": fact_node, } diff --git a/sphinx_proof/proof_type.py b/sphinx_proof/proof_type.py index 9f819fe..ceaa8fd 100644 --- a/sphinx_proof/proof_type.py +++ b/sphinx_proof/proof_type.py @@ -101,6 +101,12 @@ class ExerciseDirective(ElementDirective): name = "exercise" +class FactDirective(ElementDirective): + """A custom fact directive.""" + + name = "fact" + + PROOF_TYPES = { "axiom": AxiomDirective, "theorem": TheoremDirective, @@ -117,4 +123,5 @@ class ExerciseDirective(ElementDirective): "proposition": PropositionDirective, "assumption": AssumptionDirective, "exercise": ExerciseDirective, + "fact": FactDirective, } diff --git a/sphinx_proof/translations/jsons/Fact.json b/sphinx_proof/translations/jsons/Fact.json new file mode 100644 index 0000000..e5fd6e0 --- /dev/null +++ b/sphinx_proof/translations/jsons/Fact.json @@ -0,0 +1 @@ +[{"language":"English","symbol":"en","text":"Fact"},{"language":"Chinese","symbol":"zh_CN","text":"事实"}] diff --git a/sphinx_proof/translations/jsons/Observation.json b/sphinx_proof/translations/jsons/Observation.json index 5d7ca1e..601a91d 100644 --- a/sphinx_proof/translations/jsons/Observation.json +++ b/sphinx_proof/translations/jsons/Observation.json @@ -1 +1 @@ -[{"language":"English","symbol":"en","text":"Observation"},{"language":"French","symbol":"fr","text":"Observation"},{"language":"Italian","symbol":"it","text":"Osservazione"},{"language":"Czech","symbol":"cs","text":"Pozorování"},{"language":"Chinese","symbol":"zh_CN","text":"观测"}] +[{"language":"English","symbol":"en","text":"Observation"},{"language":"French","symbol":"fr","text":"Observation"},{"language":"Italian","symbol":"it","text":"Osservazione"},{"language":"Czech","symbol":"cs","text":"Pozorování"},{"language":"Chinese","symbol":"zh_CN","text":"观察"}]