I am trying to use includegraphics
in a TikZ picture in quarto. The following example does not work, I get the error:
LaTeX Warning: File `figTest.png' not found on input line 7.
! Package luatex.def Error: File `figTest.png' not found: using draft setting.
despite the file figTest.png
is located in the same folder as my quarto example:
---
title: "A tikz test"
pdf-engine: lualatex
keep-tex: true
filters:
- diagram
diagram:
engine:
tikz:
execpath: lualatex
header-includes:
\usepackage{graphicx}
format:
pdf:
include-in-header:
- text: |
\usepackage{graphicx}
\usepackage{tikz}
---
## Test section
See @fig-test below.
::: {#fig-test}
```tikz
\begin{tikzpicture}
\node (orig) at (0, 0) {\includegraphics{figTest.png}};
\end{tikzpicture}
```
A test figure
:::
Note that to run this example you need the lua filter diagram which can be installed via:
quarto install extension pandoc-ext/diagram
Yes, the pandoc-ext/diagram filter builds its TeX in a temp directory. Therefore, relative links do not work.
My workaround has been to adapt the filter and symlink to the project directory from the temp one in the compile
function:
os.execute('ln -s $QUARTO_PROJECT_DIR '.. tmpdir .. '/PROJECT')
This way, I can e.g. \input{PROJECT/macros.tex}
in my TikZ pictures.
In your example, one could write \includegraphics{PROJECT/figTest.png}
.
(Would also love to hear if someone found a more elegant way where one doe not need to mess with the filter script...)