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

tikz plot fails when using includegraphics{} with local file #198

Closed
bbolker opened this issue Nov 30, 2019 · 4 comments · Fixed by #203
Closed

tikz plot fails when using includegraphics{} with local file #198

bbolker opened this issue Nov 30, 2019 · 4 comments · Fixed by #203

Comments

@bbolker
Copy link

bbolker commented Nov 30, 2019

3eb8ad8 made tikz do its processing in a temporary directory. Unfortunately, this breaks my workflow, which used \includegraphics{} to include a local file. I'm trying to think of a workaround (I don't want to give an absolute path name ...) (Proximal problem is in getMetricsFromLatex: maybe you would want to consider expurgating this comment?)

To run this example, save the attached PNG as crown.png in the working directory ...

library(tikzDevice)
tikz("crown.tex")
plot(0:1,0:1,type="n")
text(0.5,0.5,"\\includegraphics[width=15pt]{crown.png}")
dev.off()

crown

This works in tikzDevice 0.12, but not in 0.12.3 ...

@rstub
Copy link
Member

rstub commented Dec 1, 2019

Thanks for a the report. As a workaround you can put the image into a directory where TeX will look for input. Which TeX distribution do you use? I am using TeX Live and putting crown.png into ~/texmf/tex/latex/local made the error go away. I will try to think of a better way to make it work on Windows with long user names.

@bbolker
Copy link
Author

bbolker commented Dec 2, 2019

thanks for considering this. This isn't really a workable workaround for me, as the code I'm fixing is used in a workflow that's being run by people with very different setups - they won't all have the same TeX setup. I'm wondering if there's some way that's not terribly unwieldy to allow an optional argument specifying external resources (files etc.) that will need to be copied to the TeX working directory ... ??

@rstub
Copy link
Member

rstub commented Dec 2, 2019

Such an optional argument should be possible. Downside is that it has to go through the C code for the graphics device. I can think of another TeX based solution, though: Temporarily set TEXINPUTS to include the current working directory:

library(tikzDevice)
tex_inputs <- Sys.getenv("TEXINPUTS")
Sys.setenv(TEXINPUTS = paste(getwd(), tex_inputs, sep = .Platform$path.sep))
tikz("crown.tex")
plot(0:1,0:1,type="n")
text(0.5,0.5,"\\includegraphics[width=15pt]{crown.png}")
dev.off()
Sys.setenv(TEXINPUTS = tex_inputs)

I have tested this on TeX Live and expect it to work on derived distributions (MacTeX, ProTeXt, TinyTeX). And MikTeX seems to support this, too: https://docs.miktex.org/manual/localadditions.html

I will have to do some further testing, but something like this could accompany the wd-changing code in getMetricsFromLatex.

@bbolker
Copy link
Author

bbolker commented Dec 4, 2019

thanks for the workaround, working for me!

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

Successfully merging a pull request may close this issue.

2 participants