Skip to content

Commit

Permalink
dev: work on arxiv.2301.00029
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Jul 31, 2024
1 parent 5f80c34 commit c11e952
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
8 changes: 5 additions & 3 deletions crates/mitex-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,20 @@ 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::<Box<str>>::new();
for (_, cmd) in spec.items() {
for (key, cmd) in spec.items() {
let alias = match cmd {
CommandSpecItem::Cmd(CmdShape {
alias: Some(alias), ..
}) => alias.as_str(),
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;
}
Expand Down
52 changes: 41 additions & 11 deletions packages/mitex/specs/latex/standard.typ
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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|)$),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c11e952

Please sign in to comment.