Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use \includegraphics instead of \pgfimage #205

Open
fueralles opened this issue Mar 9, 2020 · 7 comments
Open

Use \includegraphics instead of \pgfimage #205

fueralles opened this issue Mar 9, 2020 · 7 comments

Comments

@fueralles
Copy link

fueralles commented Mar 9, 2020

I have tried to include a tex file from the tikz output in my latex document. Since I did not put it in my main folder but in a subfolder, I always get confusing error messages. If I add the folder path like \pgfimage{path/tikz.tex} before the file name in the \pgfimage command, I can fix the error messages. So it would be pretty good to add an option to add an optional path for the filenames.
If there is any misbehavior on my part, I would ask for instructions to get a runnable latex file . Thanks a lot

M(N)WE: The problem is the subfolder "./images/". The plot_1.tex contains the critical command "\pgfimage{plot_1_ras1}"

latex file:
`\documentclass[10pt]{article}

\usepackage[pdftex]{graphicx}
\graphicspath{{./images/}}
\usepackage{tikz}

\begin{document}

\begin{figure}
\input{./images/plot_1.tex}
\caption{Sample output from tikzDevice}
\label{plot:test}
\end{figure}
\end{document}`

r file:
tikz(file = ".\\images\\plot_1.tex", width = 10, height = 5) ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) dev.off()

@rstub
Copy link
Member

rstub commented Mar 10, 2020

You could include path in the path used by LaTeX to search for images via the \graphicspath command. Untested, since you do not give a reproducible example.

@fueralles
Copy link
Author

Could you please explain this workaround more in detail. I have added my latex code in the first post. A workaround with the TEXINPUT variable seems to work but is user-unfriendly as I would have to do it for every graphic.

@rstub
Copy link
Member

rstub commented Mar 10, 2020

What do you mean by "as I would have to do it for every graphic"? The TEXINPUTS environment variable would be a good solution. Setting it to ./images:<current-value> should solve the issue, e.g. in a bash like shell

export TEXINPUTS=./images:$TEXINPUTS

BTW, to make you example reproducible it would be nice if you could supply some simple R code that uses \pgfimage when processed with tikzDevice.

@fueralles
Copy link
Author

fueralles commented Mar 10, 2020

Some graphics I produce have several png files and I want to have them in separate folders. Furthermore, depending on my latex main file the graphics folder is labeled different. Therefore, I prefer a different solution.

Edit: It seems that I can limit my problem to a countable number of cases. Thus, I build a small wrapper for the tikz() function which adds the missing path to the tex file. This is the better solution compared to TEXINPUTS at least for me.

@rstub
Copy link
Member

rstub commented Mar 18, 2020

I have now created my own example. R code for producing the image:

library(tikzDevice)

tikz("image.tex", width = 5)
plot(c(100, 150), c(300, 350), type = "n", xlab = "", ylab = "")
image <- as.raster(matrix(rep(c(rep(0:1, 4), rep(1:0, 4)), each = 3), ncol = 6, nrow = 4))
rasterImage(image, 100, 300, 150, 350, interpolate = FALSE)
dev.off()

The resulting files image.tex and image_ras1.png are placed in the sub-directory tikz. Main LaTeX file:

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{./tikz/}}
\usepackage{tikz}
% \let\pgfimage=\includegraphics % un-comment to make it work
\begin{document}
\input{tikz/image.tex}
\end{document}

This reproduces the issue since pgfimage does not use \graphicspath. And there seems to be no analogue to it either. However, the PGF manual actually recommends using \includegraphics instead, as long as you are not using masking (c.f. section 111.1 Overview). Since tikzDevice does not use masking, one can actually replace pgfimage with \includegraphics. If you un-comment the above line the minimal example compiles. I will change the title to make this change within tikzDevice.

For you this requires specifying all the image sub-directories using \graphicspath. That is slightly inconvenient, but currently I do not want to bring additional options into the C code.

@rstub rstub changed the title Path not found of included png Use \includegraphics instead of \pgfimage Mar 18, 2020
@fditraglia
Copy link

This would be a very helpful change to tikzDevice. Setting TEXINPUT works but is a real pain if you need to collaborate with others.

@x1o
Copy link

x1o commented Dec 30, 2022

For some reason,

\graphicspath{{./tikz/}}

does not work using mactex.

\graphicspath{{tikz/}}

does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants