pandoc

Pandoc --resource-path not finding assets


I am using the pandoc/latex docker container and having some issues with --resource-path. My project is using a latex template which references an image, and I cannot get latex to find the image.

My file tree looks like this:

/app/tmp/
├── 42
│   ├── galley.md
│   └── img
│       ├── 1.jpg
│       ├── 5.jpg
│       ├── 7.jpg
│       └── 9.jpg

And I have user data dirs like this:

/home/worker/.pandoc
├── assets
│   └── logo.png
└── templates
    └── sow.latex 

The command I'm using looks like

pandoc --from markdown --to latex /app/tmp/42/galley.md --output=/app/tmp/42/2/out.pdf --template sow.latex --resource-path=.:/home/worker/.pandoc/assets

As mentioned the latex template does make a reference to logo.png:

\includegraphics[width=0.75\textwidth]{logo.png}\par\vspace{1cm}

Whenever I run pandoc I get the following error:

! Package pdftex.def Error: File `logo.png' not found: using draft setting.

If I comment out the reference to logo.png then everything works fine including the other images referenced within galley.md. Likewise if I copy logo.png into the directory with galley.md everything works fine; as a workaround that is fine, but it feels quite clangy so I would rather sort out how to reference logo.png from where it sits in assets.

Is there something I've missed about how reference-path plays with template?


Solution

  • My understanding is that using --resource-path is not supported with --to latex. From the manual about the --resource-path option:

    Note that this option only has an effect when pandoc itself needs to find an image (e.g., in producing a PDF or docx, or when --embed-resources is used.) It will not cause image paths to be rewritten in other cases (e.g., when pandoc is generating LaTeX or HTML).

    Since you are likely invoking pdflatex directly after generating your latex from Pandoc, a potential solution would be to set the TEXINPUTS environment variable:

    export TEXINPUTS=.:/path/to/the/img/folder//:

    In a Bash script, you could pass the environment variable directly to your invocation of pdflatex if it's not set like:

    TEXINPUTS='${TEXINPUTS:-.:/path/to/the/img/folder//:} pdflatex'
    

    In a Makefile, you could declare the variable if unset like:

    ifndef TEXINPUTS
    export TEXINPUTS = .:/path/to/the/img/folder//:
    endif