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

Compile error when emphasis is used both inside and outside of inline note in same paragraph #447

Closed
nopria opened this issue Jun 10, 2024 · 8 comments · Fixed by #450
Closed
Assignees
Labels
bug conversion output Related to the output format of the Markdown-to-TeX conversion lua Related to the Lua interface and implementation
Milestone

Comments

@nopria
Copy link

nopria commented Jun 10, 2024

The following MWE doesn't compile "Example 2" line.
If you comment such line it compiles regularly.

\documentclass{article}
\usepackage[hybrid, inlineNotes=true]{markdown}

\begin{document}
\begin{markdown}

# MWE emphasis in footnotes with markdown

Example 1 ^[Example *starred*.].

Example 2 with *more* starred ^[Example *starred*.].

\end{markdown}
\end{document}

This issue was not present in some prevoius version (don't know the exact number but I know I was using option inlineFootnotes=true instead of inlineNotes=true as required by current version).

@Witiko
Copy link
Owner

Witiko commented Jun 10, 2024

Hi and sorry to hear about your trouble. Which version of the Markdown package are you using and what happens when the document "doesn't compile"? If you could attach your .log file, that should answer both my questions.

@nopria
Copy link
Author

nopria commented Jun 10, 2024

Sure, here is the log file:

test_emph_in_footnote.log

@Witiko
Copy link
Owner

Witiko commented Jun 11, 2024

According to the log, you use the latest released version v3.6.0 (2024-05-27) of the Markdown package with XeLaTeX from TeX Live 2024 and the error is as follows:

! Missing $ inserted.
<inserted text> 
                $
l.13 \end{markdown}
                   
? x

I tried compiling the document in the same conditions and I successfully reproduced your issue. Enabling the eagerCache option added some context to the error message:

$ xelatex --shell-escape example.tex
! Missing $ inserted.
<inserted text> 
                $
l.5 ...th \markdownRendererEmphasis{more} starred^
                                                  [Example \markdownRenderer...

? x

The issue is that the second inline note is not correctly recognized as an inline note and the character ^ is taken literally by TeX as a superscript character. Here is how your document is parsed:

$ cat ./_markdown_example/8838be0c1fda1485b6ded8c982bd70ba.md.tex
\markdownRendererDocumentBegin
\markdownRendererSectionBegin
\markdownRendererHeadingOne{MWE emphasis in footnotes with markdown}\markdownRendererInterblockSeparator
{}Example 1\markdownRendererNote{Example \markdownRendererEmphasis{starred}.}.\markdownRendererParagraphSeparator
{}Example 2 with \markdownRendererEmphasis{more} starred^[Example \markdownRendererEmphasis{starred}.].
\markdownRendererSectionEnd \markdownRendererDocumentEnd

@lostenderman Would you mind looking at why this fails? It seems to do with how we process emphasis; if I replace Example 2 with *more* starred with Example 2 with more starred or Example 2, the second inline note is correctly parsed. We can make this fully test-driven as usual, i.e. I can create a PR for you with new failing tests that demonstrate the issue and you would look into ways to make the tests pass, how does that sound?

@Witiko Witiko added this to the 3.7.0 milestone Jun 11, 2024
@Witiko Witiko added the bug label Jun 11, 2024
@nopria
Copy link
Author

nopria commented Jun 12, 2024

Maybe the bug isn't related only to the way emphasis it's parsed, in fact from more tests I saw that the same bug shows up with bold too and actually any combination of bold/emphasis inside AND outside a footnote does NOT compile:

\documentclass{article}
\usepackage[hybrid, inlineNotes=true]{markdown}

\begin{document}
\begin{markdown}

# MWE emphasis in footnotes with markdown

Combinations of emphasis/bold inside OR outside footnote compile correctly:

1. Example *emphasis* bold outside footnote^[Example emphasis bold inside footnote.].
1. Example emphasis bold outside footnote^[Example *emphasis* bold inside footnote.].
1. Example emphasis **bold** outside footnote^[Example emphasis bold inside footnote.].
1. Example emphasis bold outside footnote^[Example emphasis **bold** inside footnote.].

% Any combination of emphasis/bold inside AND outside footnote does NOT compile
%1. Example *emphasis* bold outside footnote^[Example *emphasis* bold inside footnote.].
%1. Example emphasis **bold** outside footnote^[Example emphasis **bold** inside footnote.].
%1. Example *emphasis* bold outside footnote^[Example emphasis **bold** inside footnote.].
%1. Example emphasis **bold** outside footnote^[Example *emphasis* bold inside footnote.].

\end{markdown}
\end{document}

N.B. Mixed markdown/latex combinations of emphasis/bold inside and outside footnote compiles correctly.

@Witiko
Copy link
Owner

Witiko commented Jun 12, 2024

Thanks for sharing the additional examples. The issue seems related to the interplay between (strong) emphasis and inline footnotes. Namely, the code that parses (strong) emphasis seems to misparse the inline footnote as regular text while looking around for other possible candidates for emphasis within the same paragraph.

@nopria
Copy link
Author

nopria commented Jun 12, 2024

An additional detail, the issue shows up only if emphasis/bold comes before a footnote containing other emphasis/bold.
If emphasis/bold follows a footnote containing emhasis/bold, the source compiles regularly.

@Witiko Witiko changed the title Compile error when emphasis is used both inside and outside of inline footnote in same paragraph Compile error when emphasis is used both inside and outside of inline note in same paragraph Jun 13, 2024
@Witiko Witiko added lua Related to the Lua interface and implementation conversion output Related to the output format of the Markdown-to-TeX conversion labels Jun 13, 2024
@Witiko
Copy link
Owner

Witiko commented Jun 16, 2024

@nopria: The issue has been fixed by @lostenderman in #450, see also your example document and its output after #450:

\documentclass{article}
\usepackage[hybrid, inlineNotes]{markdown}

\begin{document}
\begin{markdown}

# MWE emphasis in footnotes with markdown

Combinations of emphasis/bold inside OR outside footnote compile correctly:

1. Example *emphasis* bold outside footnote^[Example emphasis bold inside footnote.].
1. Example emphasis bold outside footnote^[Example *emphasis* bold inside footnote.].
1. Example emphasis **bold** outside footnote^[Example emphasis bold inside footnote.].
1. Example emphasis bold outside footnote^[Example emphasis **bold** inside footnote.].

Any combinations of emphasis/bold inside AND outside footnote also compile correctly since #450:

1. Example *emphasis* bold outside footnote^[Example *emphasis* bold inside footnote.].
1. Example emphasis **bold** outside footnote^[Example emphasis **bold** inside footnote.].
1. Example *emphasis* bold outside footnote^[Example emphasis **bold** inside footnote.].
1. Example emphasis **bold** outside footnote^[Example *emphasis* bold inside footnote.].

\end{markdown}
\end{document}

image
image

I also added a regression test, so that any similar issues are caught by our automated tests in the future.

The fix will be part of Markdown 3.7.0, to be released later this month. If you'd like to use the fix earlier, take the following steps:

  1. Uninstall the portable installation of version 2.23.0 from Downgrade markdown version (TexLive) #449.
  2. Download the archive markdown.zip for the latest prerelease of the Markdown package and extract the file markdown.lua.
  3. Place the file markdown.lua to the directory next to your document.

Note that leaving the file markdown.lua in the directory next to your document will eventually cause trouble due to the version mismatch of the file markdown.lua and the rest of the Markdown package from TeX Live. However, it is a good interim solution before Markdown 3.7.0 has been released.

Even after Markdown 3.7.0, using an old file markdown.lua should only prevent you from using new features but should be otherwise fully forward-compatible – at least until Markdown 4, which may change the interface between markdown.lua and the rest of the Markdown package. However, there are currently no plans for Markdown 4 and I don't imagine there would be, at least in the next couple years.

@Witiko
Copy link
Owner

Witiko commented Jun 21, 2024

I released the new version yesterday. In the end, it was not a minor release 3.7.0 but just a bugfix release 3.6.1, since no new features were added since I was busy preparing a TUG 2024 article about the Markdown package. If you have a TeX Live install that is not locked by your operating system to prevent updates, you should be able to update the Markdown package using the command (sudo) tlmgr update markdown or by using the graphical user interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug conversion output Related to the output format of the Markdown-to-TeX conversion lua Related to the Lua interface and implementation
Projects
None yet
3 participants