Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: work on arxiv.2301.00029 #178

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading