Pandoc --resource-path not finding assets
Asked Answered
E

1

6

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?

Erdman answered 15/1, 2021 at 13:56 Comment(2)
Absolute paths work as well, so I'll just use those until a more general solution presents itself.Erdman
I am facing the same problem with templates - I am using the anaconda version of pandoc 2.11 and can only get it to work with absolute paths. Following the documentation, I created a folder ~/.pandoc, to no avail. Specifying the directory via --data-dir=/~/.pandoc does also not helpPrague
D
1

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
Drogin answered 8/7 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.