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

+136
View File
@@ -0,0 +1,136 @@
use common::{Glue, GlueOrder, Scaled, ScaledUnit};
use crate::prelude as txl;
use crate::traits::*;
use crate::*;
use super::keyword::parse_keyword;
impl Parsable for types::MuGlue {
fn parse_impl<S: TexlangState>(input: &mut vm::ExpandedStream<S>) -> txl::Result<Self> {
if let Some(glue) = S::scan_mu_glue(input)? {
return Ok(glue);
}
let negative = super::integer::parse_optional_signs(input)?.is_some();
if let Some(first_token) = input.next()? {
if let token::Value::CommandRef(command_ref) = first_token.value() {
if let super::integer::InternalNumber::MuGlue(glue) =
super::integer::parse_internal_number(input, first_token, command_ref)?
{
return Ok(if negative {
types::MuGlue(glue.0 * -1)
} else {
glue
});
}
}
input.back(first_token);
}
let width = scan_mu_dimen(input, None)?;
let mut glue = Glue {
width,
..Glue::default()
};
if parse_keyword(input, "plus")? {
glue.stretch = scan_mu_dimen(input, Some(&mut glue.stretch_order))?;
}
if parse_keyword(input, "minus")? {
glue.shrink = scan_mu_dimen(input, Some(&mut glue.shrink_order))?;
}
if negative {
glue = glue * -1;
}
Ok(types::MuGlue(glue))
}
}
fn scan_mu_dimen<S: TexlangState>(
input: &mut vm::ExpandedStream<S>,
mut glue_order: Option<&mut GlueOrder>,
) -> txl::Result<Scaled> {
let negative = super::integer::parse_optional_signs(input)?.is_some();
let first_token = input.next_or_err(MuGlueEndOfInputError {})?;
let (integer_part, fractional_part) = match first_token.value() {
token::Value::CommandRef(command_ref) => {
match super::integer::parse_internal_number(input, first_token, command_ref)? {
super::integer::InternalNumber::MuGlue(glue) => {
let width = glue.0.width;
return Ok(if negative { -width } else { width });
}
super::integer::InternalNumber::Integer(value) => (value.abs(), Scaled::ZERO),
_ => {
input.error(parse::Error::new(
"a math glue value",
Some(first_token),
"math glue assignments require values measured in mu",
))?;
return Ok(Scaled::ZERO);
}
}
}
_ => super::dimen::scan_constant_dimen(input, first_token)?,
};
let unit_found = match glue_order.as_deref_mut() {
Some(order) if parse_keyword(input, "fil")? => {
*order = GlueOrder::Fil;
while let Some(token) = input.next()? {
match token.value() {
token::Value::Letter('l' | 'L') => match order.next() {
Some(next) => *order = next,
None => {
input.error(parse::Error::new(
"an infinite glue order",
Some(token),
"too many l characters in the glue order",
))?;
}
},
_ => {
input.back(token);
break;
}
}
}
super::OptionalSpace::parse(input)?;
true
}
_ => {
let found = parse_keyword(input, "mu")?;
if found {
super::OptionalSpace::parse(input)?;
}
found
}
};
if !unit_found {
input.error(parse::Error::new(
"a math unit (mu)",
Some(first_token),
"muskip values require mu units",
))?;
return Ok(Scaled::ZERO);
}
let value = match Scaled::new(integer_part, fractional_part, ScaledUnit::Point) {
Ok(value) => value,
Err(_) => {
input.error(parse::Error::new(
"a math glue value in TeX's supported range",
Some(first_token),
"the value is too large",
))?;
Scaled::MAX_DIMEN
}
};
Ok(if negative { -value } else { value })
}
#[derive(Debug)]
struct MuGlueEndOfInputError;
impl error::EndOfInputError for MuGlueEndOfInputError {
fn doing(&self) -> String {
"parsing math glue".into()
}
}