Consume class and theorem declaration options

This commit is contained in:
gloamxun committed 2026-10-20 01:11:38 +08:00
1 parent 466abd4ce6
commit 5fd5f92bb4
2 files changed
+58 -4

No files matched your search

-4
View File
@@ -105,7 +105,6 @@ const PRELUDE: &str = r#"
\long\def\@ifundefined#1#2#3{#3}
\def\settowidth#1#2{}
\def\pagenumbering#1{}
\def\newtheorem#1#2{}
\def\theoremstyle#1{}
\def\newtheoremstyle#1#2#3#4#5#6#7#8#9{}
\def\setcitestyle#1{}
@@ -382,9 +381,6 @@ const PRELUDE: &str = r#"
\def\Biggr#1{\texrramathmanualdelimiter{35}{closing}#1}
% ---- LaTeX compatibility layer -------------------------------------------
\def\ProvidesClass#1{}
\def\ProvidesPackage#1{}
\def\ProvidesFile#1{}
\def\rmdefault{cmr}
\def\sfdefault{cmss}
\def\ttdefault{cmtt}
+58
View File
@@ -2247,6 +2247,48 @@ fn author_frontmatter_primitive(
Ok(())
}
fn skip_optional_bracket(
input: &mut vm::ExecutionInput<CompilerState>,
) -> texlang::prelude::Result<()> {
let Some(first) = input.unexpanded().next()? else {
return Ok(());
};
if !matches!(first.value(), token::Value::Other('[')) {
input.unexpanded().back(first);
return Ok(());
}
let mut depth = 0usize;
while let Some(next) = input.unexpanded().next()? {
match next.value() {
token::Value::BeginGroup(_) => depth += 1,
token::Value::EndGroup(_) => depth = depth.saturating_sub(1),
token::Value::Other(']') if depth == 0 => return Ok(()),
_ => {}
}
}
Ok(())
}
fn provides_declaration_primitive(
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
) -> texlang::prelude::Result<()> {
let _ = read_unexpanded_argument(input, token, "file name")?;
skip_optional_bracket(input)?;
Ok(())
}
fn new_theorem_primitive(
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
) -> texlang::prelude::Result<()> {
let _ = read_unexpanded_argument(input, token, "theorem environment")?;
skip_optional_bracket(input)?;
let _ = read_unexpanded_argument(input, token, "theorem title")?;
skip_optional_bracket(input)?;
Ok(())
}
fn affiliation_frontmatter_primitive(
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
@@ -7743,6 +7785,22 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
"pagestyle",
texlang::command::BuiltIn::new_execution(page_style_primitive),
);
built_ins.insert(
"ProvidesClass",
texlang::command::BuiltIn::new_execution(provides_declaration_primitive),
);
built_ins.insert(
"ProvidesPackage",
texlang::command::BuiltIn::new_execution(provides_declaration_primitive),
);
built_ins.insert(
"ProvidesFile",
texlang::command::BuiltIn::new_execution(provides_declaration_primitive),
);
built_ins.insert(
"newtheorem",
texlang::command::BuiltIn::new_execution(new_theorem_primitive),
);
built_ins.insert(
"thispagestyle",
texlang::command::BuiltIn::new_execution(this_page_style_primitive),