-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add Theorems #107
base: master
Are you sure you want to change the base?
Add Theorems #107
Changes from all commits
50620ed
5da1e73
f0b1e19
62ed0b2
1454170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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. |
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", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
#[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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you destructure the |
||||||
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(()) | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you chose
title
overcaption
? I think usingcaption
instead oftitle
might be more consistent with all other configs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not a caption in the sense of a
\\caption{}
element in Latex. It's more closely a heading. It still might be the best fit for consistency.