-
Notifications
You must be signed in to change notification settings - Fork 210
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
Fix incorrect handling of user-defined environments introduced in #856 (#1137) #1139
Conversation
… for anything other than that
It turns out we don't need the linked list, just a count of the open user-defined environments, so I've made a commit that changes that. I had originally tried to use the |
Isn't it a bit early for you? But it allowed me to put together quite a number of test cases. Most work with your solution. Here is one, where the error message is not quite what is expected.
But these are quite pathological cases, so I would not be too fuzzed about them. |
Yes, I couldn't sleep, and thought I might as well get some work done.
It sounds like you were doing essentially the same as mine. There have been several times I'd have liked to change the type for EnvList to include more complex objects, I went with the linked list to avoid that. But, as I found out, neither is actually needed for this situation.
I had a similar example as the last one in my pull request description, and I was not so happy with the error message there as well. But actual LaTeX recurses infinitely for this one (and the simpler variants from my PR), so I feel better that we are at least giving a message. Also, LaTeX complains about all three definitions because In any case, if you want to use a different solution, let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
Once merged I will add all the tests we have for it.
Thanks! |
Fix processing of latex attributes for user-defined environments thatwas broken by #1139
This PR fixes the problem with user-defined environments that was reported in #1137 that was introduced by PR #856, that was trying to fix a potential infinite recursion. It changed how the environments end macros were processed by inserting them into the parser string followed by second
\end{...}
macro. Aparser.stack.env
value (processing
) was used to track when the second\end{...}
was processed and skip the insertion of the end macros.The problem with that is that the environment where
processing
was added might be cleared by the ed macros. For the example in #1137, the\begin{array}
in the begin macros and the\end{array}
in the end macros for theboxed
environment means that theprocessing
environment value is in the environment in effect within thearray
environment, and that environment is ended and removed when\end{array}
is processed. So theprocessing
value is also lost, and the end macros are inserted again, leading to a new\hline
being inserted outside thearray
environment, and the associated error about a misplaced\hline
.Because of this, and other similar situations, the
parser.stack.env
value can't be used to track the second\end{...}
. So I've gone back to the original process of parsing the end macros, but needed a new way to avoid the potential recursion that #856 was meant to fix.The infinite recursion was possible when the end macros included
\end{...}
for the user-defined environment. This was a problem because when processing the end macros that contain\end{...}
that\end
would cause the end macros to be inserted again, and then that is related over and over. This is because the testing for a matching\begin{...}
for the\end{...}
isn't done until after the end macros are processed (so that the user-defined environment can include\begin
and\end
as in the example from #1137), when theend
stack item is pushed.The solution introduced here is use the
beginEnv
stack items to form a linked list of the open (user-defined) environments, with the the top-mostbeginEnv
stack item recorded in aparser.stack.global
variable. We only insert the end macro string if there is an activebeginEnv
on the stack, and we remove that from the linked list once we add the end macros the first time. That way, we only add the end macros once for any\begin{...}
that is on the stack, so even if the end macros include\end{...}
, they can't be inserted infinitely, and eventually we get theend
stack item being pushed, producing the mismatched begin/end message.This allows
and also
to work, while having
produce an appropriate error message.
Other test cases include
that should work while
and
and
and
and
and
should all produce errors.
The definitions
should produce
x...yxy
,while
should error.