From c11e952afede225621ad2edfd37ae92b0219de92 Mon Sep 17 00:00:00 2001 From: Myriad-Dreamin Date: Thu, 1 Aug 2024 01:45:45 +0800 Subject: [PATCH] dev: work on arxiv.2301.00029 --- crates/mitex-cli/src/main.rs | 8 ++-- packages/mitex/specs/latex/standard.typ | 52 +++++++++++++++++++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/crates/mitex-cli/src/main.rs b/crates/mitex-cli/src/main.rs index d9129aa..79fde6a 100644 --- a/crates/mitex-cli/src/main.rs +++ b/crates/mitex-cli/src/main.rs @@ -89,9 +89,9 @@ fn compile(input_path: &str, output_path: &str, is_ast: bool) -> Result<(), Erro // Insert preludes // todo: better way? let mut builtin_set = std::collections::HashSet::<&'static str>::new(); - builtin_set.extend(["and", "or", "in", "not"]); + builtin_set.extend(["and", "or", "in", "not", "footnote", "dot"]); let mut alias_set = std::collections::HashSet::>::new(); - for (_, cmd) in spec.items() { + for (key, cmd) in spec.items() { let alias = match cmd { CommandSpecItem::Cmd(CmdShape { alias: Some(alias), .. @@ -99,8 +99,10 @@ fn compile(input_path: &str, output_path: &str, is_ast: bool) -> Result<(), Erro CommandSpecItem::Env(EnvShape { alias: Some(alias), .. }) => alias.as_str(), - _ => continue, + _ => key, }; + // todo: this is hacky + let alias = alias.trim_start_matches('#'); if alias.is_empty() || !alias.chars().all(|c| c.is_ascii_alphanumeric()) { continue; } diff --git a/packages/mitex/specs/latex/standard.typ b/packages/mitex/specs/latex/standard.typ index 72c302d..09c2878 100644 --- a/packages/mitex/specs/latex/standard.typ +++ b/packages/mitex/specs/latex/standard.typ @@ -49,13 +49,16 @@ alias: none, handle: math.mat.with(delim: delim), ) -#let call-or-ignore(fn) = (..args) => if args.pos().len() > 0 { - fn(..args) -} else { - math.zws -} +#let call-or-ignore(fn) = ( + (..args) => if args.pos().len() > 0 { + fn(..args) + } else { + math.zws + } +) #let ignore-me = (..args) => { } #let ignore-sym = define-sym("") +#let ignore-command(n, alias: none) = define-cmd(n, alias: alias, handle: ignore-me) // 2. Standard package definitions, generate specs and scopes, // for parser/convert and typst respectively @@ -80,12 +83,12 @@ enumerate: define-env(none, kind: "is-enumerate"), quote: define-env(none, alias: "quote(block: true)"), abstract: define-env(none, alias: "quote(block: true)"), + document: define-env(none, alias: ""), figure: define-glob-env("{,b}", kind: "is-figure", alias: "figure"), table: define-glob-env("{,b}", kind: "is-figure", alias: "figure"), tabular: define-env(1, kind: "is-table", alias: "table"), // commands for figure centering: ignore-sym, - textwidth: sym, caption: define-cmd(1, alias: "mitexcaption", handle: ignore-me), includegraphics: define-glob-cmd("{,b}t", "#miteximage", handle: ignore-me), // commands for tabular @@ -972,7 +975,7 @@ xlongequal: arrow-handle(math.eq), pmod: define-cmd(1, handle: it => $quad (mod thick it)$), pod: define-cmd(1, handle: it => $quad (it)$), - "set": define-cmd(1, handle: it => $\{it\}$), + "set": define-cmd(1, alias: "mitexset", handle: it => $\{it\}$), Set: define-cmd(1, handle: it => $lr(\{it\})$), bra: define-cmd(1, handle: it => $angle.l it|$), Bra: define-cmd(1, handle: it => $lr(angle.l it|)$), @@ -1092,10 +1095,6 @@ ProvideTextCommandDefault: ignore-sym, providecommand: ignore-sym, "providecommand*": ignore-sym, - newenvironment: ignore-sym, - "newenvironment*": ignore-sym, - renewenvironment: ignore-sym, - "renewenvironment*": ignore-sym, AtEndOfClass: ignore-sym, AtEndOfPackage: ignore-sym, AtBeginDocument: ignore-sym, @@ -1140,6 +1139,37 @@ ProvidesClass: ignore-sym, LoadClass: ignore-sym, LoadClassWithOptions: ignore-sym, + + title: ignore-command(1), + author: ignore-command(1), + date: ignore-command(1), + usepackage: ignore-command(1), + thanks: ignore-command(1), + comment: define-env(none, alias: "mitexcomment", handle: ignore-me), + + // todo: set/length commands + topmargin: ignore-sym, + oddsidemargin: ignore-sym, + textwidth: ignore-sym, + today: ignore-sym, + maketitle: ignore-sym, + textheight: ignore-sym, + footskip: ignore-sym, + interfootnotelinepenalty: ignore-sym, + + makeatother: ignore-sym, + makeatletter: ignore-sym, + "env@matrix": ignore-command(1), + arraystretch: ignore-command(1), + bibliography: ignore-command(1, alias: "mitexbibliography"), + bibliographystyle: ignore-command(1), + arraycolsep: ignore-sym, + "@ifnextchar": ignore-sym, + "new@ifnextchar": ignore-sym, + // \edef\arraystretch{#1}% + "let": ignore-sym, + edef: ignore-sym, + // todo: \newcommand{\newtheorem}[2]{\newenvironment{#1}{}{}} )) // export: include package name, spec and scope