I'm trying to convert a Markdown file into a PDF file using Pandoc.
I have a lot of code blocks in my Markdown. And if I have a line of code that is too long, it will just be cut off in the PDF. How can I make Pandoc to warp lines that are too long?
Here's the line I'm using right now:
pandoc input.md --highlight-style tango -o output.pdf;
Best Answer
(See Update at the end, to get proper colors)
By default pandoc uses its own highlighting engine, but it can be changed to use package
listings
instead. Simply add--listings
option to your pandoc command line.However, the format used by listings does not break long lines either, but you can prepare all the required options in a separate tex file, for example:
And then compile with the line:
Unfortunately, this solution cannot use the
--highlight-style
option too. If you want to get thetango
colorscheme, you have to code it yourself as options for the listing packages, and include them in the\lstset
above.Given the file
test.md
as follows:The result generated by the previous pandoc command line is:
Update
In order to mimic closely the result obtained with
--highlight-style tango
option (and nolistings
package), I ran pandoc asking for the intermediate.tex
file to discover how the colors were defined for that case.I wrote the following setup using
listings
options, which use the same colors (only where applicable, for examplelistings
has no mean to set a specific color for numeric constants or other syntactic elements). In addition I reduced the spacing among chars, which were too far apart with default setup. This is the new setup:Using those settings, i.e. running
pandoc
with options:the following result is obtained:
For reference, compare it with the result without
--listings
but with--highlight-syntax tango
instead:As you can see, the style is very close (except for numeric constants, which are blue using
tango
, but black usinglistings
). Note also how the lines were wrapped withlistings
. I also added line numbers which refer to the original lines (before wrapping).