-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
They are specifically defined in such a way in the front end as to allow nesting of other Markdown elements inside their description. This makes it more natural to have theorems not only consisting of math blocks while allowing the natural nesting of them.
- Loading branch information
1 parent
50620ed
commit 5da1e73
Showing
16 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Theorems | ||
|
||
{definition} | ||
> A natural number `$ n` is called prime if it has exactly two divisors. | ||
{lemma, title="Euclid"} | ||
> If `$ p` is prime and divides `$ ab` then it divides `$ a` or `$ b`. | ||
{corollary, title="Prime factorization"} | ||
> Each number has a canonical decomposition into prime factors. | ||
{theorem, title="The main theorem"} | ||
> There is an infinite number of prime numbers. | ||
{proof} | ||
> Assume `$ p` to be the largest prime number. Define | ||
> ```$$ | ||
> P' = 1+ \prod^p_{i=0, i prime} i | ||
> ``` | ||
> Then `$ P'` is not divisible by any prime. But it has at least two divisors, one and itself, so there must a prime divisor larger than `$ p`. This is a contradiction. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::io::Write; | ||
|
||
use crate::backend::{Backend, CodeGenUnit}; | ||
use crate::config::Config; | ||
use crate::error::Result; | ||
use crate::frontend::range::WithRange; | ||
use crate::generator::event::{Event, Proof, ProofKind}; | ||
use crate::generator::Generator; | ||
|
||
trait ContextName { | ||
fn context_name(&self) -> &'static str; | ||
} | ||
|
||
impl ContextName for ProofKind { | ||
fn context_name(&self) -> &'static str { | ||
match self { | ||
ProofKind::Corollary => "amsthm-corollary", | ||
ProofKind::Definition => "amsthm-definition", | ||
ProofKind::Lemma => "amsthm-lemma", | ||
ProofKind::Proof => "proof", | ||
ProofKind::Theorem=> "amsthm-theorem", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ProofGen { | ||
kind: ProofKind, | ||
} | ||
|
||
impl<'a> CodeGenUnit<'a, Proof<'a>> for ProofGen { | ||
fn new( | ||
_cfg: &'a Config, proof: WithRange<Proof<'a>>, | ||
gen: &mut Generator<'a, impl Backend<'a>, impl Write>, | ||
) -> Result<Self> { | ||
let WithRange(element, _range) = proof; | ||
let out = gen.get_out(); | ||
write!(out, "\\begin{{{}}}", element.kind.context_name())?; | ||
if let Some(WithRange(title, _)) = element.title { | ||
write!(out, "[{}]", title)?; | ||
} | ||
if let Some(WithRange(label, _)) = element.label { | ||
write!(out, "\\label{{{}}}", label)?; | ||
} | ||
Ok(ProofGen { | ||
kind: element.kind, | ||
}) | ||
} | ||
|
||
fn finish( | ||
self, gen: &mut Generator<'a, impl Backend<'a>, impl Write>, | ||
_peek: Option<WithRange<&Event<'a>>>, | ||
) -> Result<()> { | ||
write!(gen.get_out(), "\\end{{{}}}", self.kind.context_name())?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters