What are the best practices regarding `pandoc` when one simply wants a conversion to PDF?

I was trying to quickly convert a CommonMark markdown document to PDF but got into errors (elaborating on these below), but are there any simple instructions somewhere on how to set up Pandoc that just works for the most basic purposes out of the box? (This is kind of subjective, I know.)

Lucked out with trial and error for now, but this method is not ideal (and may not always work). Out of all the manuals (Nix, Nixpkgs, NixOS), only the NixOS one mentions pandoc at all, so it’s not there. The only other thread here that closely related was this but it wasn’t helpful in my case.


$ nix-shell -p pandoc

$ pandoc input.md -o out.pdf
pdflatex not found. Please select a different --pdf-engine or install pdflatex

Not sure how to find which Nix packages offer an arbitrary executable (in this case, pdflatex), so tried this:

$ pdflatex
The program ‘pdflatex’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.texlive.combined.scheme-basic
  nix-env -iA nixos.texlive.combined.scheme-minimal
  nix-env -iA nixos.texlive.combined.scheme-small

So I went through each of these in order:

$ nix-shell -p texlive.combined.scheme-basic

$ pandoc input.md -o out.pdf
Error producing PDF.
! LaTeX Error: File `xcolor.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Enter file name: 
! Emergency stop.
<read *> 
         
l.36 \IfFileExists

$ exit

No luck.

$ nix-shell -p texlive.combined.scheme-minimal

$ pandoc input.md -o out.pdf

kpathsea: Running mktexfmt pdflatex.fmt
mktexfmt: mktexfmt is using the following fmtutil.cnf files (in precedence order):
mktexfmt:   /nix/store/61nxl1s0fkfgjj9s01f1b6kk7f5vvrcg-texlive-combined-minimal-2019/share/texmf/web2c/fmtutil.cnf
mktexfmt: mktexfmt is using the following fmtutil.cnf file for writing changes:
mktexfmt:   /home/toraritte/.texlive2019/texmf-config/web2c/fmtutil.cnf
mktexfmt [INFO]: writing formats under /home/toraritte/.texlive2019/texmf-var/web2c
mktexfmt [INFO]: --- remaking pdflatex with pdftex
mktexfmt [WARNING]: inifile pdflatex.ini for pdflatex/pdftex not found.
mktexfmt [INFO]: disabled formats: 5
mktexfmt [INFO]: not selected formats: 53
mktexfmt [INFO]: failed to build: 1 (pdftex/pdflatex)
mktexfmt [INFO]: total formats: 59
mktexfmt [INFO]: exiting with status 1

kpathsea: Running mktexfmt pdflatex.fmt
mktexfmt: mktexfmt is using the following fmtutil.cnf files (in precedence order):
mktexfmt:   /nix/store/61nxl1s0fkfgjj9s01f1b6kk7f5vvrcg-texlive-combined-minimal-2019/share/texmf/web2c/fmtutil.cnf
mktexfmt: mktexfmt is using the following fmtutil.cnf file for writing changes:
mktexfmt:   /home/toraritte/.texlive2019/texmf-config/web2c/fmtutil.cnf
mktexfmt [INFO]: writing formats under /home/toraritte/.texlive2019/texmf-var/web2c
mktexfmt [INFO]: --- remaking pdflatex with pdftex
mktexfmt [WARNING]: inifile pdflatex.ini for pdflatex/pdftex not found.
mktexfmt [INFO]: disabled formats: 5
mktexfmt [INFO]: not selected formats: 53
mktexfmt [INFO]: failed to build: 1 (pdftex/pdflatex)
mktexfmt [INFO]: total formats: 59
mktexfmt [INFO]: exiting with status 1
Error producing PDF.
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/NixOS.org) (preloaded format=pdflatex)
 restricted \write18 enabled.
I can't find the format file `pdflatex.fmt'!

$ exit

No luck.

$ nix-shell -p texlive.combined.scheme-small

$ pandoc input.md -o out.pdf

Bingo. For the record, it seems as these packages also have pdflatex, so I could’ve gone on, but it would have been very time-consuming (e.g., had to quit installing texlive.combined.scheme-full after 30 minutes as I had to leave…)

$ nix-shell -p texlive.combined.scheme- # TAB TAB
texlive.combined.scheme-basic      texlive.combined.scheme-gust       texlive.combined.scheme-minimal
texlive.combined.scheme-context    texlive.combined.scheme-infraonly  texlive.combined.scheme-small
texlive.combined.scheme-full       texlive.combined.scheme-medium     texlive.combined.scheme-tetex
1 Like

What about:

nix-shell --pure -p pandoc -p texlive.combined.scheme-small --run "pandoc example.md -o example.pdf"

Can you provide an example commonmark file ?

I. e. https://raw.githubusercontent.com/thephpleague/commonmark/latest/tests/benchmark/sample.md works for me.

1 Like

I pretty much always end up having to install pandoc and texlive.combined.scheme-full to convert to pdf, which gets a little annoying when all you want is a simple document converted (I like to write my assignments for classes in Markdown). While using smaller packages is better if texlive.combined.scheme-small will work, wouldn’t it be better to have a dedicated package that is just pandoc + pdflatex like a pandoc-pdflatex package or something?

2 Likes