Initial texrra engine

Rename the crate, binary, core crate, font families, env vars, and internal commands from texcraft/tex-engine to texrra. Serve the separately versioned texrra-web frontend from TEXRRA_WEB_DIR, ../web, or ./web instead of embedding index.html. Add starred section heading support and an arXiv template conformance fixture.
This commit is contained in:
gloamxun committed 2026-10-19 11:41:46 +08:00
commit bb1d9e0561
147 files changed
+66719

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
use std::collections::HashMap;
use crate::document::{Block, DocumentModel, ListBlock, ParsedDocument, Run, UnresolvedReference};
/// Resolves document references after parsing has collected all labels and citations.
pub fn resolve(parsed: ParsedDocument) -> DocumentModel {
let mut document = parsed.0;
fn resolve_runs(
runs: &mut [Run],
labels: &HashMap<String, String>,
citations: &HashMap<String, usize>,
) {
for run in runs {
let Some(reference) = run.unresolved_reference.take() else {
continue;
};
run.text = match reference {
UnresolvedReference::Label(key) => labels
.get(&key)
.cloned()
.unwrap_or_else(|| "??".to_string()),
UnresolvedReference::Citation(keys) => {
let formatted = keys
.iter()
.map(|key| {
citations
.get(key)
.map(usize::to_string)
.unwrap_or_else(|| key.clone())
})
.collect::<Vec<_>>()
.join(", ");
format!("[{formatted}]")
}
};
}
}
fn resolve_list(
list: &mut ListBlock,
labels: &HashMap<String, String>,
citations: &HashMap<String, usize>,
) {
for item in &mut list.items {
resolve_runs(&mut item.runs, labels, citations);
for nested in &mut item.nested {
resolve_list(nested, labels, citations);
}
}
}
let labels = &document.labels;
let citations = &document.citations;
for block in &mut document.blocks {
match block {
Block::Paragraph(runs) | Block::Heading { runs, .. } => {
resolve_runs(runs, labels, citations)
}
Block::List(list) => resolve_list(list, labels, citations),
Block::Table { rows, caption, .. } => {
for cell in rows.iter_mut().flatten() {
resolve_runs(cell, labels, citations);
}
if let Some(caption) = caption {
resolve_runs(caption, labels, citations);
}
}
Block::Image { caption, .. } => {
if let Some(caption) = caption {
resolve_runs(caption, labels, citations);
}
}
Block::FramedBox { runs, .. } | Block::Centered { runs } => {
resolve_runs(runs, labels, citations)
}
Block::Bibliography(items) => {
for (_, runs) in items {
resolve_runs(runs, labels, citations);
}
}
Block::HorizontalRule { .. }
| Block::Math { .. }
| Block::VerticalKern(_)
| Block::VerticalGlue(_)
| Block::Penalty(_)
| Block::PageBreak => {}
}
}
document
}