Open slava-arapov opened 2 months ago
The expected behavior is that inside of math _{}
is parsed as a macro and not a string, so this sounds like a bug. It will be a little bit before I have time to investigate this further.
This issue goes deeper than I thought. The information about whether to parse in a math
environment or a regular
environment isn't propagated trough to groups. Getting this to work correctly will require quite a rework of the parsing algorithm.
Hi Jason.
Thanks for your parsing utilities. We are making a latex formula editor and your work helps us a lot in development.
Unfortunately, I can't find a solution to one problem.
The problem
Superscript and subscript tokens (
^
,_
) are often used in mathematical expressions. They are recognized correctly in math mode but when^
and_
are inside a group or in a deep level (index of index of index), they are treated as text by the parser.It seems that math mode stops being inherited inside a group.
I tried to get some AST trees in the Playground, here are some examples:
$a_{b}$
No groups. Works correctly:${a_b}$
Wrapped in group.a_b
is parsed as string:$a_{b_{c}}$
First level is ok butb_
in subscript argument is parsed as string and it is OK for default_
macro settings:${a_{b_{c}}}$
All the expression is wrapped in group.a_
andb_
are parsed as strings:What I tried
In my project I tried to redefine macros this way:
It helps to handle
$a_{b_{c}}$
case with 3 levels but not$a_{b_{c_d}}$
case with 4+ levels:It also doesn't fix the situation of a group-wrapped expression:
${a_b}$
:Questions
Is this behavior expected?
Is there any options or workarounds to parse
Thank you in advance.