pub struct TheoremsConfig {
pub classes: BTreeMap<Name, TheoremClass>,
pub kinds: BTreeMap<Name, TheoremKind>,
pub number_format: NumberTemplate,
pub label_types: Vec<String>,
}Expand description
The configuration of the Theorems feature: the
theorem classes and the theorem kinds, the number format of every kind,
and the label types every numbered kind accepts.
Every kind is an environment of its own name, \begin{lemma}…\end{lemma},
with no code written for it: a host adds exercise by declaring it here.
The default (TheoremsConfig::new) declares three classes and eight
kinds:
| class | numbered | counter | closing mark | back-reference | kinds |
|---|---|---|---|---|---|
theoremlike | yes | shared | none | no | theorem, proposition, lemma, corollary, conjecture |
definitionlike | yes | shared | none | no | definition, remark |
prooflike | no | — | □ | yes | proof |
with the heading DEFAULT_HEADING for every class. theorem,
proposition, lemma and corollary expect a proof; the others do not.
simpleset and
richset are two other complete sets a host
may start from. A host edits any of them through the builders:
use flm_core::stdlib::features::numbering::{PluralWords, PrefixWords};
use flm_core::stdlib::features::theorems::{TheoremKind, TheoremsConfig};
let config = TheoremsConfig::new()
.kind(
"exercise",
TheoremKind::new(
"definitionlike",
PrefixWords::new("Exercise", "Exercises")
.with_variant("short", PluralWords::new("Ex.", "Exs.")),
),
)
.without_kind("conjecture");
assert_eq!(config.kinds.len(), 8);
assert!(config.validate().is_ok());The value is what Theorems::new takes, and a
host passes it through
StdlibConfig::theorems. It is
the feature’s configuration, fixed when the registry is built (see
settings, options and
configuration),
because the environments are part of the language and the counters and
counter styles the feature declares depend on it. For the same reason it
enters the registry digest (digest_bytes).
The configuration is checked when the registry is built. The feature’s
registration fails, with a message that identifies the class or the kind,
on what validate refuses: a kind whose class
the configuration does not declare, a class or kind name that is not a
valid environment name, or a kind that expects a proof but accepts no
label. Once the language is built, the registry build also fails on a
heading template that does not compile, a closing mark that does not
parse and a word that does not parse. A kind whose environment name another
feature already declares is reported as any clash of names in the
registry is.
Fields§
§classes: BTreeMap<Name, TheoremClass>The theorem classes, by name.
kinds: BTreeMap<Name, TheoremKind>The theorem kinds, by environment name.
number_format: NumberTemplateThe number format every kind’s number is written in, a number
template of the numbering feature, #{arabic} by default. To write
one kind’s number otherwise, a host replaces that kind’s counter style
(flm.theorems.style.<kind>, see numbers) by name
through the numbering feature’s configuration.
label_types: Vec<String>The label types that every numbered kind accepts on a \label written
on one of its theorems; DEFAULT_LABEL_TYPES by default. A theorem
of an unnumbered kind accepts no label.
Implementations§
Source§impl TheoremsConfig
impl TheoremsConfig
Sourcepub fn new() -> TheoremsConfig
pub fn new() -> TheoremsConfig
The default set of kinds, the set the Python implementation of FLM
calls defaultset: eight kinds in the three shipped classes,
theorem, proposition, lemma, corollary, conjecture,
definition, remark and proof (TheoremsConfig lists them by
class).
Sourcepub fn simpleset() -> TheoremsConfig
pub fn simpleset() -> TheoremsConfig
The smallest shipped set, the set the Python implementation of FLM
calls simpleset: six kinds, theorem, proposition, lemma,
corollary, definition and proof, in the three shipped classes.
Sourcepub fn richset() -> TheoremsConfig
pub fn richset() -> TheoremsConfig
The largest shipped set, the set the Python implementation of FLM
calls richset: thirteen kinds, the eight of TheoremsConfig::new,
and idea, question, claim, observation and problem in the
class definitionlike.
Sourcepub fn empty() -> TheoremsConfig
pub fn empty() -> TheoremsConfig
A configuration declaring no class and no kind, with the default number format and label types: the start of a configuration built entirely by the builders.
Sourcepub fn kind(self, name: impl Into<Name>, kind: TheoremKind) -> TheoremsConfig
pub fn kind(self, name: impl Into<Name>, kind: TheoremKind) -> TheoremsConfig
Builder: declares the kind name, replacing the kind of that name if
there is one.
Sourcepub fn without_kind(self, name: &str) -> TheoremsConfig
pub fn without_kind(self, name: &str) -> TheoremsConfig
Builder: removes the kind name, if there is one.
Sourcepub fn class(self, name: impl Into<Name>, class: TheoremClass) -> TheoremsConfig
pub fn class(self, name: impl Into<Name>, class: TheoremClass) -> TheoremsConfig
Builder: declares the class name, replacing the class of that name
if there is one.
Sourcepub fn number_format(self, number_format: NumberTemplate) -> TheoremsConfig
pub fn number_format(self, number_format: NumberTemplate) -> TheoremsConfig
Builder: sets the number format of every kind.
Sourcepub fn label_types(
self,
label_types: impl IntoIterator<Item = impl Into<String>>,
) -> TheoremsConfig
pub fn label_types( self, label_types: impl IntoIterator<Item = impl Into<String>>, ) -> TheoremsConfig
Builder: sets the label types that every numbered kind accepts.
Sourcepub fn kind_and_class(
&self,
name: &str,
) -> Option<(&TheoremKind, &TheoremClass)>
pub fn kind_and_class( &self, name: &str, ) -> Option<(&TheoremKind, &TheoremClass)>
The kind name and its class; None where the kind or its class is
not declared.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Checks the parts of the configuration that can be checked before the language is built. The feature calls it when it registers; a host may call it earlier to report a mistake in its own terms.
The texts (heading templates, closing marks, words) are compiled only once the language is built, so a text that does not compile passes this check and fails the registry build later.
§Errors
A sentence that describes the first problem found: a class or kind
name that is empty or holds whitespace, a brace, a backslash or a
comment character (%); a kind whose class is not declared; a kind
that expects a proof but accepts no
label (a kind of an unnumbered class, or any kind under a
configuration declaring no label_types),
which no proof could refer back to.
Sourcepub fn digest_bytes(&self) -> Vec<u8> ⓘ
pub fn digest_bytes(&self) -> Vec<u8> ⓘ
The configuration written out as bytes: what the feature feeds into
the registry digest, and what the Hash implementation hashes.
Every class and every kind is written in the order of its name, with every field of it, each text preceded by its length; then the number format and the label types. Two configurations give the same bytes exactly when they are equal. The code takes the fields apart by name, so a field added to a type and not written here fails to compile.
Trait Implementations§
Source§impl Clone for TheoremsConfig
impl Clone for TheoremsConfig
Source§impl Debug for TheoremsConfig
impl Debug for TheoremsConfig
Source§impl Default for TheoremsConfig
impl Default for TheoremsConfig
Source§fn default() -> TheoremsConfig
fn default() -> TheoremsConfig
Source§impl<'de> Deserialize<'de> for TheoremsConfigwhere
TheoremsConfig: Default,
impl<'de> Deserialize<'de> for TheoremsConfigwhere
TheoremsConfig: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for TheoremsConfig
Source§impl Hash for TheoremsConfig
impl Hash for TheoremsConfig
Source§impl JsonSchema for TheoremsConfig
impl JsonSchema for TheoremsConfig
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for TheoremsConfig
impl PartialEq for TheoremsConfig
impl StructuralPartialEq for TheoremsConfig
Auto Trait Implementations§
impl Forget for TheoremsConfig
impl Freeze for TheoremsConfig
impl Move for TheoremsConfig
impl RefUnwindSafe for TheoremsConfig
impl Send for TheoremsConfig
impl Sync for TheoremsConfig
impl Unpin for TheoremsConfig
impl UnsafeUnpin for TheoremsConfig
impl UnwindSafe for TheoremsConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more