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

latex parsing: final item label in theorem environment applied to theorem rather than item #8872

Closed
ultronozm opened this issue May 27, 2023 · 1 comment

Comments

@ultronozm
Copy link

pandoc version 3.1.2 on macOS 12.6, "pandoc test.tex -o test.md"

Input:

\documentclass{amsart}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}\label{thm}
\begin{enumerate}
\item \label{item1} text1
\item \label{item2} text2
\item text3
\end{enumerate}
\end{theorem}
\end{document}

Output:

::: {#item2 .theorem}
**Theorem 1**. *[]{#thm label="thm"}*

1.  *[]{#item1 label="item1"} text1*

2.  *text2*

3.  *text3*
:::

Expected output:

::: {#thm .theorem}
**Theorem 1**.

1.  *[]{#item1 label="item1"} text1*

2.  *[]{#item2 label="item2"} text2*

3.  *text3*
:::

That is to say, the final item label is applied to the enclosing block rather than to the item.

I wasn't able to find related issues in github or pandoc-discuss. I would be happy to try to understand this issue better. Would Text/Pandoc/Readers/LaTeX.hs be the place to look?

@ultronozm ultronozm added the bug label May 27, 2023
@jgm
Copy link
Owner

jgm commented May 29, 2023

T/P/Readers/LaTeX/Math.hs theoremEnvironment.

We currently do something fairly primitive. When we encounter a label, we modify sLastLabel in state. We then check this after parsing a theorem environment.

ibayashi-hikaru added a commit to ibayashi-hikaru/pandoc that referenced this issue Nov 17, 2023
In the current implementation , theorem labels in `theoremEnvironment` are determined by the `LastLabel` in the current state.
This approach works well when the `\label{label_name}` is placed at the end of the theorem body (, which is a standard place to put a label.)

However, when a label is placed at the beginning of the theorem (another common practice) and additional labels follow in the theorem body,
`theoremEnvironment` incorrectly picks the last label (e.g., `\label{item2}` in jgm#8872).

This patch addresses the issue by extracting the label extraction independently of the `LastLabel` state.
@jgm jgm closed this as completed in a3fba6d Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants