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

Problem with custom Latex environment inside of custom list environment items #7953

Closed
abenthy opened this issue Mar 9, 2022 · 4 comments
Closed
Labels

Comments

@abenthy
Copy link

abenthy commented Mar 9, 2022

Hello, I'm trying to read a Latex document in Pandoc with the following structure:

\documentclass{article}

\newenvironment{myenumerate}{\begin{enumerate}}{\end{enumerate}}
\newenvironment{myenvironment}{}{}

\begin{document}

\begin{myenumerate}
\item{foo\begin{myenvironment}bar\end{myenvironment}}
\end{myenumerate}

\end{document}

Pandoc v. 2.17.1.1 (pandoc -t json example.tex) gives me the following error

Error at "example.tex" (line 13, column 2):
unexpected end of input
expecting \end{enumerate}

 ^

The document compiles without errors with pdflatex.

What I have tried / observed:

  • The problem seems to be somehow related to the curly brackets after \item. If I replace \item{...} by \item... it works (I don't know why).
  • If I remove the text foo, it works (again, I don't know why).
  • Replacing myenumerate by a list defined with \newlist from the enumitem package doesn't fix the error.
  • If I replace the usage of myenumerate with the standard enumerate environment, it works.
  • If I replace \begin{myenvironment}bar\end{myenvironment} with \begin{center}bar\end{center}, it works.

Does someone know what cause the problem here? I have a document that uses custom lists like above that I would like to convert with Pandoc, if possible without changes to the document. However, changes to the macro definitions would be no problem as a fix for me.

Thanks for your fantastic work on parsing Latex by the way, most of my documents work great!

@abenthy abenthy added the bug label Mar 9, 2022
@abenthy abenthy changed the title Problem with custom environment inside of custom list environment items Problem with custom Latex environment inside of custom list environment items Mar 9, 2022
@jgm
Copy link
Owner

jgm commented Mar 9, 2022

Here's what I note:

  1. If you comment out the definition of newenvironment, then pandoc succeeds, but puts the content of newenvironment in a special div block.
  2. As you note, if you remove the {..} around the list item, pandoc succeeds and you get a list item foobar (which I think is what you want)
  3. As you note, removing foo also works.

I'll have to dig into the code to figure this one out.

@jgm
Copy link
Owner

jgm commented Mar 10, 2022

More experiments:

% pandoc -f latex -t native
\newenvironment{x}{}{}
{foo\begin{x}bar\end{x}}
^D
Error at (line 2, column 24):
unexpected Tok (line 2, column 24) Symbol "}"
expecting end of input
{foo\begin{x}bar\end{x}}
                       ^
% pandoc -f latex -t native
{foo\begin{x}bar\end{x}}
^D
[ Para [ Str "foo" ]
, Div ( "" , [ "x" ] , [] ) [ Para [ Str "bar" ] ]
]
% pandoc -f latex -t native
\newenvironment{x}{}{}
^D
foo\begin{x}bar\end{x}
[ Para [ Str "foobar" ] ]
 % pandoc -f latex -t native
\newenvironment{x}{}{}
{\begin{x}bar\end{x}}
^D
[ Para [ Span ( "" , [] , [] ) [ Str "bar" ] ] ]

@jgm
Copy link
Owner

jgm commented Mar 10, 2022

Even smaller:

{foo\bgroup bar\egroup }

which is how pandoc expands the environment
yields

Error at (line 1, column 24):
unexpected Tok (line 1, column 24) Symbol "}"
expecting end of input
{foo\bgroup bar\egroup }

This is the root issue, I think.

@jgm
Copy link
Owner

jgm commented Mar 10, 2022

However this is fine!

\bgroup foo\bgroup bar \egroup\egroup

@jgm jgm closed this as completed in 581c949 Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants