Allow documents to replace the title block

This commit is contained in:
gloamxun committed 2026-10-19 14:32:35 +08:00
1 parent 23cf1f13de
commit 5e9552d785
8 files changed
+89 -18

No files matched your search

+3 -3
View File
@@ -22,6 +22,9 @@ const PRELUDE: &str = r#"
\def\title#1{\texrrametadatastart{title}#1\texrrametadataend{title}}
\def\author#1{\texrrametadatastart{author}#1\texrrametadataend{author}}
\def\date#1{\texrrametadatastart{date}#1\texrrametadataend{date}}
\def\@title{\texrrametadatatitle}
\def\@author{\texrrametadataauthor}
\def\@date{\texrrametadatadate}
\def\today{__TEXRRA_TODAY__}
\def\maketitle{\texrramaketitle}
\def\noindent{\texrranoindent}
@@ -361,9 +364,6 @@ const PRELUDE: &str = r#"
\def\thefootnote{*}
\def\footnoterule{}
\def\thanks#1{\footnote{#1}}
\def\@title{}
\def\@author{}
\def\@date{}
\def\@thanks{}
\def\@makefntext#1{}
\def\@makefnmark{}
+42 -1
View File
@@ -2121,6 +2121,15 @@ fn metadata_field_argument(
}
}
fn metadata_value_primitive(
field: MetadataField,
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
) -> texlang::prelude::Result<()> {
write_event(input, token, FrontendEventKind::MetadataValue(field));
Ok(())
}
fn metadata_start_primitive(
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
@@ -4751,7 +4760,21 @@ fn define_latex_command(
// parser. Style files routinely replace them with box-level LaTeX
// implementations the engine cannot execute, so keep the native
// meaning instead of failing or replacing it with an unusable macro.
return Ok(());
// A document may still replace its own title block in the main source.
let from_style_file = match input.vm().trace(token).origin {
trace::Origin::File(path) => matches!(
path.extension().and_then(|extension| extension.to_str()),
Some("sty" | "cls")
),
trace::Origin::Terminal => false,
};
let document_title_block = matches!(
&macro_name,
EngineCommandName::ControlSequence(name) if name == "maketitle"
);
if !document_title_block || from_style_file {
return Ok(());
}
}
let already_defined = input.state().engine.macros.get(&macro_name).is_some()
|| input.vm().commands_map.get_command(&name_ref).is_some();
@@ -6904,6 +6927,24 @@ fn built_in_commands() -> HashMap<&'static str, texlang::command::BuiltIn<Compil
"texrramaketitle",
texlang::command::BuiltIn::new_execution(make_title_primitive),
);
built_ins.insert(
"texrrametadatatitle",
texlang::command::BuiltIn::new_execution(|token, input| {
metadata_value_primitive(MetadataField::Title, token, input)
}),
);
built_ins.insert(
"texrrametadataauthor",
texlang::command::BuiltIn::new_execution(|token, input| {
metadata_value_primitive(MetadataField::Author, token, input)
}),
);
built_ins.insert(
"texrrametadatadate",
texlang::command::BuiltIn::new_execution(|token, input| {
metadata_value_primitive(MetadataField::Date, token, input)
}),
);
built_ins.insert(
"texrrametadatastart",
texlang::command::BuiltIn::new_execution(metadata_start_primitive),