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

Error creating PDF from markdown with Lua fenced code block #5227

Closed
NDietrich opened this issue Jan 15, 2019 · 5 comments
Closed

Error creating PDF from markdown with Lua fenced code block #5227

NDietrich opened this issue Jan 15, 2019 · 5 comments

Comments

@NDietrich
Copy link

NDietrich commented Jan 15, 2019

There is an issue when generating latex documents from markdown using the listings package for the Lua Language. If you create a PDF directly from markdown there is an issue, but if break the process into two steps (markdown to tex, then tex to pdf there is no issue).

Example markdown code (example.md):

```{.bash firstnumber=100}
echo "this displays corectly with syntax highlighting"
```

```{.Lua firstnumber=100}
print("Also works with Syntax Highlighting")
local function dumphyphens (head)
```

Pandoc is run as follows:

pandoc example.md -o example.tex --listings

the output (example.tex) is as follows:

\begin{lstlisting}[language=bash, firstnumber=100]
echo "this displays corectly with syntax highlighting"
\end{lstlisting}

\begin{lstlisting}[language=Lua, firstnumber=100]
print("Also works with Syntax Highlighting")
local function dumphyphens (head)
\end{lstlisting}

now try creating a PDF from the latex:

pandoc example.tex -o example.pdf

and this generates a PDF with correct color syntax highlighting for the bash code, AND the lua code. Everything is good.

now try again but go straight to PDF from MD:

pandoc example.md -o example.pdf --listings

and you get the following error:

user@computer:~/ $ pandoc example.md -o example.pdf --listings
Error producing PDF.
! Package Listings Error: Couldn't load requested language.

See the Listings package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.65 ...lstlisting}[language=Lua, firstnumber=100]

The tex output by the command is the exact same as in the first case:

\begin{lstlisting}[language=bash, firstnumber=100]
echo "this displays corectly with syntax highlighting"
\end{lstlisting}

\begin{lstlisting}[language=Lua, firstnumber=100]
print("Also works with Syntax Highlighting")
local function dumphyphens (head)
\end{lstlisting}

Running Version 2.5:

user@computer:~/ $ pandoc -v
pandoc 2.5
Compiled with pandoc-types 1.17.5.4, texmath 0.11.1.2, skylighting 0.7.4
@mb21
Copy link
Collaborator

mb21 commented Jan 15, 2019

So you're saying it works without --listings and doesn't with the option? btw. shouldn't it be a lowercase l in .lua, like:

```{.lua firstnumber=100}

@NDietrich
Copy link
Author

You have to use the uppercase Lua in the code fence or it doesn't work (getting lua to work correctly was difficult, and this is what i found worked).

when going straight from markdown to pdf with the following command:

pandoc example.md -o example.pdf --listings

The error i mentioned above is generated.

when going from markdown to tex, and then from tex to pdf the error is not generated, and the pdf is correct (has all the correct syntax highligting for lua and bash):

pandoc example.tex -o example.tex --listings
pandoc example.tex -o example.pdf

However, if you go from .tex to pdf, AND if you add the listings flag at this step, you get the error again:

pandoc example.tex -o example.pdf --listings

@jgm
Copy link
Owner

jgm commented Jan 15, 2019 via email

@jgm
Copy link
Owner

jgm commented Jan 18, 2019

OK, I think the issue here is that Lua has several variants in listings (5.0, 5.1, 5.2).
In cases like this apparently it's necessary to specify the variant or listings gets confused:
https://tex.stackexchange.com/questions/212069/listings-cannot-load-requested-language

Workaround: add this to your header-includes:

\lstset{defaultdialect=[5.2]Lua}

Not sure what change to pandoc would be best, if any. We could add some default dialects to the default template, but these might not be the dialects the user wants...

@jgm
Copy link
Owner

jgm commented Jan 26, 2019

Here are the listings languages that have multiple dialect but no preset default dialect:

Assembler (Motorola68k, x86masm)
Lua (5.0, 5.1, 5.2, 5.3)

So I think we could just add this to the default template under $if(listings)$:

\lstset{defaultdialect=[5.3]Lua}
\lstset{defaultdilaect=[x86masm]Assembler}

@jgm jgm closed this as completed in 7ccaa77 Jan 26, 2019
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

3 participants