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

pandoc-crossref does not work with pandoc --listings #197

Closed
sjackman opened this issue Sep 14, 2018 · 10 comments
Closed

pandoc-crossref does not work with pandoc --listings #197

sjackman opened this issue Sep 14, 2018 · 10 comments

Comments

@sjackman
Copy link
Contributor

❯❯❯ echo '`Hello, world!`' >hello.md
❯❯❯ pandoc --listings -Fpandoc-crossref -o hello.pdf hello.md
Error producing PDF.
! Undefined control sequence.
l.77 \passthrough
@sjackman
Copy link
Contributor Author

Adding codeBlockCaptions: True to the YAML front-matter and removing --listings from the command line resolved my issue.

@lierdakil
Copy link
Owner

You need -Mlistings (or listings: True in metadata block) to let pandoc-crossref know you're using listings. This is mentioned in the manual.

@sjackman
Copy link
Contributor Author

sjackman commented Sep 14, 2018

Found it here http://lierdakil.github.io/pandoc-crossref/#table-style-captions

listings: if True, generate code blocks for listings package. Only relevant for LaTeX output. \usepackage{listings} will be automatically added to header-includes. You need to specify --listings option as well.

http://lierdakil.github.io/pandoc-crossref/#general-options

You need to specify --listings option as well.
This doesn't seem to be true. It works without --listings.

@sjackman
Copy link
Contributor Author

sjackman commented Sep 14, 2018

You may wan to consider changing the linked URL of the GitHub page
from https://hackage.haskell.org/package/pandoc-crossref
to http://lierdakil.github.io/pandoc-crossref/
which is more useful to the user.

@lierdakil
Copy link
Owner

This doesn't seem to be true. It works without --listings.

Probably depends on Pandoc version, but having -Mlistings without --listings can lead to subtle breakage (since the latter actually affects how Pandoc's LaTeX renderer does stuff)

You may wan to consider changing the linked URL

Sounds reasonable.

@sjackman
Copy link
Contributor Author

Thanks for pandoc-crossref! It makes writing academic papers enjoyable. =)

@sjackman
Copy link
Contributor Author

With --listings -Mlistings -McodeBlockCaptions the code is syntax highlighted but without colour, and the spacing between letters and punctuation is weird and not right.
Without --listings -Mlistings and with codeBlockCaptions everything works as expected.

@lierdakil
Copy link
Owner

the code is syntax highlighted but without colour, and the spacing between letters and punctuation is weird and not right.

Well, I don't know what you mean by "weird and not right" exactly, but the "without colour" part is precisely what one would expect with LaTeX listings package. In fact, if you look at raw LaTeX, Pandoc doesn't even attempt highlighting the code with --listings enabled, offloading the task to LaTeX instead:

$ cat test.md
```cpp
#include <stdio.h>
int main() {
    printf("Hello, world!\n");
    return 0;
}
```

$ pandoc -t latex test.md
\begin{Shaded}
\begin{Highlighting}[]
\PreprocessorTok{#include }\ImportTok{<stdio.h>}
\DataTypeTok{int}\NormalTok{ main() \{}
\NormalTok{    printf(}\StringTok{"Hello, world!}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{);}
    \ControlFlowTok{return} \DecValTok{0}\NormalTok{;}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}

$ pandoc -t latex --listings test.md
\begin{lstlisting}[language={C++}]
#include <stdio.h>
int main() {
    printf("Hello, world!\n");
    return 0;
}
\end{lstlisting}

Hope that makes sense.

@ajeep8
Copy link

ajeep8 commented Oct 14, 2021

when I use --listings, the long line can auto break.
But use pandoc-crossref, the long lines can not break line.
Is there any way to break line using pandoc-crossref?

@sdbbs
Copy link

sdbbs commented Mar 30, 2023

Just noting my experience: I have a pandoc.yaml with these contents:

# ...
listings: true
filters:
- ${.}/../scripts/pandoc/my_script.lua
- pandoc-crossref
- citeproc
# ...
metadata:
  link-citations: true
# ...
  header-includes: |
# ...
    \lstset{% for listings
      basicstyle=\ttfamily,
      breaklines=true,
    }
# ...

.... and in my test.md file something like:

<!-- ... -->
See figure [@fig:my_figure].

![This is my figure](my_figure.png){ #fig:my_figure }
<!-- ... -->

With this, it turns out I have to use -Mlistings on the command line, else for some reason, if I enable pandoc-crossref under filters, then \lstset becomes undefined (?!):

$ pandoc --version
pandoc.exe 2.13
Compiled with pandoc-types 1.22, texmath 0.12.2, skylighting 0.10.5,
citeproc 0.3.0.9, ipynb 0.1.0.1

$ pandoc --defaults=pandoc.yaml --pdf-engine-opt=-shell-escape --toc test.md -o test.pdf
Error producing PDF.
! Undefined control sequence.
l.96 \lstset

$ pandoc --defaults=pandoc.yaml --pdf-engine-opt=-shell-escape --listings --toc test.md -o test.pdf
Error producing PDF.
! Undefined control sequence.
l.96 \lstset

$ pandoc --defaults=pandoc.yaml --pdf-engine-opt=-shell-escape -Mlistings --listings --toc test.md -o test.pdf

$ pandoc --defaults=pandoc.yaml --pdf-engine-opt=-shell-escape -Mlistings --toc test.md -o test.pdf

Is there any option I can set in the .yaml file, so I get the same effect as -Mlistings on the command line, without having to use -Mlistings on the command line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants