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

Support for Exercises directive & Added Chinese translation (zh_CN) #90

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, exercise and fact directives.


## Get started
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, exercise and fact directives.

**Features**:

Expand Down
73 changes: 73 additions & 0 deletions docs/source/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,79 @@ 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.

### 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`.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"""
Expand Down
22 changes: 22 additions & 0 deletions sphinx_proof/_static/proof.css
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,25 @@ 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);
}
/*********************************************
* 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);
}
10 changes: 10 additions & 0 deletions sphinx_proof/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ class assumption_node(nodes.Admonition, nodes.Element):
pass


class exercise_node(nodes.Admonition, nodes.Element):
pass


class fact_node(nodes.Admonition, nodes.Element):
pass


NODE_TYPES = {
"axiom": axiom_node,
"theorem": theorem_node,
Expand All @@ -202,4 +210,6 @@ class assumption_node(nodes.Admonition, nodes.Element):
"observation": observation_node,
"proposition": proposition_node,
"assumption": assumption_node,
"exercise": exercise_node,
"fact": fact_node,
}
14 changes: 14 additions & 0 deletions sphinx_proof/proof_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class AssumptionDirective(ElementDirective):
name = "assumption"


class ExerciseDirective(ElementDirective):
"""A custom exercise directive."""

name = "exercise"


class FactDirective(ElementDirective):
"""A custom fact directive."""

name = "fact"


PROOF_TYPES = {
"axiom": AxiomDirective,
"theorem": TheoremDirective,
Expand All @@ -110,4 +122,6 @@ class AssumptionDirective(ElementDirective):
"observation": ObservationDirective,
"proposition": PropositionDirective,
"assumption": AssumptionDirective,
"exercise": ExerciseDirective,
"fact": FactDirective,
}
2 changes: 1 addition & 1 deletion sphinx_proof/translations/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('"', '\\"')
Expand Down
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Algorithm.json
Original file line number Diff line number Diff line change
@@ -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":"算法"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Assumption.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"language":"English","symbol":"en","text":"Assumption"}]
[{"language":"English","symbol":"en","text":"Assumption"},{"language":"Chinese","symbol":"zh_CN","text":"假设"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Axiom.json
Original file line number Diff line number Diff line change
@@ -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":"公理"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Conjecture.json
Original file line number Diff line number Diff line change
@@ -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":"猜想"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Criterion.json
Original file line number Diff line number Diff line change
@@ -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":"准则"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Definition.json
Original file line number Diff line number Diff line change
@@ -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":"定义"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Example.json
Original file line number Diff line number Diff line change
@@ -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":"例子"}]
1 change: 1 addition & 0 deletions sphinx_proof/translations/jsons/Exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"language":"English","symbol":"en","text":"Exercise"},{"language":"Chinese","symbol":"zh_CN","text":"练习"}]
1 change: 1 addition & 0 deletions sphinx_proof/translations/jsons/Fact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"language":"English","symbol":"en","text":"Fact"},{"language":"Chinese","symbol":"zh_CN","text":"事实"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Lemma.json
Original file line number Diff line number Diff line change
@@ -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":"引理"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Observation.json
Original file line number Diff line number Diff line change
@@ -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":"观察"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Property.json
Original file line number Diff line number Diff line change
@@ -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":"性质"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Proposition.json
Original file line number Diff line number Diff line change
@@ -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":"命题"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Remark.json
Original file line number Diff line number Diff line change
@@ -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":"评注"}]
2 changes: 1 addition & 1 deletion sphinx_proof/translations/jsons/Theorem.json
Original file line number Diff line number Diff line change
@@ -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":"定理"}]