Skip to content

Commit

Permalink
Make the hard-coding of \mathstrut more generally usable (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmke8 authored Feb 5, 2025
1 parent 56c975d commit 942b550
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
18 changes: 6 additions & 12 deletions latex2mmlc/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub enum Node<'arena> {
style: Option<Style>,
},
PseudoRow(NodeList<'arena>),
Mathstrut,
Fenced {
style: Option<Style>,
open: &'static ParenOp,
Expand Down Expand Up @@ -106,6 +105,7 @@ pub enum Node<'arena> {
args: NodeList<'arena>,
},
CustomCmdArg(usize),
HardcodedMathML(&'static str),
}

impl PartialEq for &'static Node<'static> {
Expand Down Expand Up @@ -415,12 +415,6 @@ impl<'arena> MathMLEmitter<'arena> {
self.emit(node, base_indent);
}
}
Node::Mathstrut => {
push!(
self.s,
r#"<mpadded width="0" style="visibility:hidden"><mo stretchy="false">(</mo></mpadded>"#
);
}
Node::Fenced {
open,
close,
Expand Down Expand Up @@ -542,6 +536,9 @@ impl<'arena> MathMLEmitter<'arena> {
self.emit(arg, base_indent);
}
}
Node::HardcodedMathML(mathml) => {
push!(self.s, mathml);
}
}
}

Expand Down Expand Up @@ -901,11 +898,8 @@ mod tests {
}

#[test]
fn render_mathstrut() {
assert_eq!(
render(&Node::Mathstrut),
r#"<mpadded width="0" style="visibility:hidden"><mo stretchy="false">(</mo></mpadded>"#
);
fn render_hardcoded_mathml() {
assert_eq!(render(&Node::HardcodedMathML("<mi>hi</mi>")), "<mi>hi</mi>");
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion latex2mmlc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static COMMANDS: phf::Map<&'static str, Token> = phf::phf_map! {
"mathrm" => Token::Transform(MathVariant::Normal),
"mathscr" => Token::Transform(MathVariant::Transform(TextTransform::Script)),
"mathsf" => Token::Transform(MathVariant::Transform(TextTransform::SansSerif)),
"mathstrut" => Token::Mathstrut,
"mathstrut" => Token::HardcodedMathML(r#"<mpadded width="0" style="visibility:hidden"><mo stretchy="false">(</mo></mpadded>"#),
"mathtt" => Token::Transform(MathVariant::Transform(TextTransform::Monospace)),
"max" => Token::Lim("max"),
"measeq" => Token::Operator(ops::MEASURED_BY), // from "stix"
Expand Down
2 changes: 1 addition & 1 deletion latex2mmlc/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ where
}
Token::Ampersand => Node::ColumnSeparator,
Token::NewLine => Node::RowSeparator,
Token::Mathstrut => Node::Mathstrut,
Token::Style(style) => {
let content = self.parse_group(Token::GroupEnd)?;
Node::Row {
Expand Down Expand Up @@ -727,6 +726,7 @@ where
));
}
},
Token::HardcodedMathML(mathml) => Node::HardcodedMathML(mathml),
};
Ok(self.commit(node))
}
Expand Down
3 changes: 1 addition & 2 deletions latex2mmlc/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ pub enum Token<'source> {
Not,
#[strum(serialize = r"\text*")]
Text(Option<TextTransform>),
#[strum(serialize = r"\mathstrut")]
Mathstrut,
Style(Style),
CustomCmd(usize, &'static Node<'static>),
GetCollectedLetters,
HardcodedMathML(&'static str),
UnknownCommand(&'source str),
}

Expand Down

0 comments on commit 942b550

Please sign in to comment.