Skip to content

Commit

Permalink
Simplify \#,\&, etc macros, leveraging Unicode data
Browse files Browse the repository at this point in the history
  • Loading branch information
brucemiller committed Nov 29, 2024
1 parent 4c92345 commit 20ecf5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.
28 changes: 10 additions & 18 deletions lib/LaTeXML/Engine/plain.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,20 @@ DefMacro('\brack',
#======================================================================
# Special Characters.
# Try to give them some sense in math...
DefMacroI('\#', undef, '\ifmmode\lx@math@hash\else\lx@text@hash\fi', protected => 1);
DefMacroI('\&', undef, '\ifmmode\lx@math@amp\else\lx@text@amp\fi', protected => 1);
DefMacroI('\%', undef, '\ifmmode\lx@math@percent\else\lx@text@percent\fi', protected => 1);
DefMacroI("\\\$", undef, '\ifmmode\lx@math@dollar\else\lx@text@dollar\fi', protected => 1);
DefMacroI('\_', undef, '\ifmmode\lx@math@underscore\else\lx@text@underscore\fi', protected => 1);
DefPrimitiveI('\lx@text@hash', undef, '#', alias => '\#');
DefPrimitiveI('\lx@text@amp', undef, '&', alias => '\&');
DefPrimitiveI('\lx@text@percent', undef, '%', alias => '\%');
DefPrimitiveI('\lx@text@dollar', undef, "\$", alias => "\\\$");
DefPrimitiveI('\lx@text@underscore', undef, '_', alias => '\_');
DefMathI('\lx@math@hash', undef, '#', alias => '\#');
DefMathI('\lx@math@amp', undef, '&', role => 'ADDOP', meaning => 'and', alias => '\&');
DefMathI('\lx@math@percent', undef, '%', role => 'POSTFIX', meaning => 'percent', alias => '\%');
DefMathI('\lx@math@dollar', undef, "\$", role => 'OPERATOR', meaning => 'currency-dollar',
alias => "\\\$");
DefMathI('\lx@math@underscore', undef, '_', alias => '\_');
DefPrimitive('\#', sub {
Box('#', undef, undef, T_CS('\#')); });
DefPrimitive('\&', sub {
Box('&', undef, undef, T_CS('\&'), role => 'ADDOP', meaning => 'and'); });
DefPrimitive('\%', sub {
Box('%', undef, undef, T_CS('\%'), role => 'POSTFIX', meaning => 'percent'); });
DefPrimitive('\$', sub {
Box('$', undef, undef, T_CS('\$'), role => 'OPERATOR', meaning => 'currency-dollar'); });
DefPrimitive('\_', sub {
Box('_', undef, undef, T_CS('\_')); });

# Discretionary times; just treat as invisible ?
DefMathI('\*', undef, "\x{2062}", role => 'MULOP', name => '', meaning => 'times'); # INVISIBLE TIMES (or MULTIPLICATION SIGN = 00D7)

# These 3 should have some `name' assigned ... but what???

#======================================================================
# If an XMWrap (presumably from \mathop, \mathbin, etc)
# has multiple children, ALL are XMTok, within a restricted set of roles,
Expand Down
44 changes: 23 additions & 21 deletions lib/LaTeXML/Util/Unicode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -340,27 +340,29 @@ our %math_props = (
"8" => { role => 'NUMBER', meaning => 8 },
"9" => { role => 'NUMBER', meaning => 9 },
#======================================================================
'=' => { role => 'RELOP', meaning => 'equals' },
'+' => { role => 'ADDOP', meaning => 'plus' },
'-' => { role => 'ADDOP', meaning => 'minus' },
'*' => { role => 'MULOP', meaning => 'times' },
'/' => { role => 'MULOP', meaning => 'divide' },
'!' => { role => 'POSTFIX', meaning => 'factorial' },
',' => { role => 'PUNCT' },
'.' => { role => 'PERIOD' },
';' => { role => 'PUNCT' },
':' => { role => 'METARELOP', name => 'colon' }, # plausible default?
'|' => { role => 'VERTBAR', stretchy => 'false' },
'<' => { role => 'RELOP', meaning => 'less-than' },
'>' => { role => 'RELOP', meaning => 'greater-than' },
'(' => { role => 'OPEN', stretchy => 'false' },
')' => { role => 'CLOSE', stretchy => 'false' },
'[' => { role => 'OPEN', stretchy => 'false' },
']' => { role => 'CLOSE', stretchy => 'false' },
'{' => { role => 'OPEN', stretchy => 'false' },
'}' => { role => 'CLOSE', stretchy => 'false' },
'&' => { role => 'ADDOP', meaning => 'and' },
## ':' => { role => 'METARELOP' }, # \colon # Seems like good default role
'=' => { role => 'RELOP', meaning => 'equals' },
'+' => { role => 'ADDOP', meaning => 'plus' },
'-' => { role => 'ADDOP', meaning => 'minus' },
'*' => { role => 'MULOP', meaning => 'times' },
'/' => { role => 'MULOP', meaning => 'divide' },
'!' => { role => 'POSTFIX', meaning => 'factorial' },
',' => { role => 'PUNCT' },
'.' => { role => 'PERIOD' },
';' => { role => 'PUNCT' },
':' => { role => 'METARELOP', name => 'colon' }, # plausible default?
'|' => { role => 'VERTBAR', stretchy => 'false' },
'<' => { role => 'RELOP', meaning => 'less-than' },
'>' => { role => 'RELOP', meaning => 'greater-than' },
'(' => { role => 'OPEN', stretchy => 'false' },
')' => { role => 'CLOSE', stretchy => 'false' },
'[' => { role => 'OPEN', stretchy => 'false' },
']' => { role => 'CLOSE', stretchy => 'false' },
'{' => { role => 'OPEN', stretchy => 'false' },
'}' => { role => 'CLOSE', stretchy => 'false' },
'&' => { role => 'ADDOP', meaning => 'and' },
'&amp;' => { role => 'ADDOP', meaning => 'and' },
'%' => { role => 'POSTFIX', meaning => 'percent' },
'$' => { role => 'OPERATOR', meaning => 'currency-dollar' },

#======================================================================
UTF(0x5C) => { role => 'ADDOP', meaning => 'set-minus' }, # \backslash
Expand Down

0 comments on commit 20ecf5a

Please sign in to comment.