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

Generating tikz graphics fails with chunk before preamble #1055

Closed
ClaudiusL opened this issue Jun 8, 2015 · 5 comments
Closed

Generating tikz graphics fails with chunk before preamble #1055

ClaudiusL opened this issue Jun 8, 2015 · 5 comments
Labels
bug Bugs
Milestone

Comments

@ClaudiusL
Copy link
Contributor

The following MWE runs without problems:

\documentclass{article}

<<knitr-setup, echo=FALSE, cache=FALSE, message=FALSE>>=
library(knitr)

opts_chunk$set(
  echo = FALSE,
  dev = "tikz"
)
@

\begin{document}
<<test>>=
plot(1)
@
\end{document}

As soon as the chunk knitr-setup is moved before the preamble, compilation fails with the following error: Error in getMetricsFromLatex(TeXMetrics).

The following code can be used to reproduce the issue:

<<knitr-setup, echo=FALSE, cache=FALSE, message=FALSE>>=
library(knitr)

opts_chunk$set(
  echo = FALSE,
  dev = "tikz"
)
@

\documentclass{article}

\begin{document}
<<test>>=
plot(1)
@
\end{document}

The problem seems to be that the knitr copies whole chunk knitr-setup to test-1.tikz which is invalid TEX code. Therefore I suppose this is a bug in knitr.

@yihui
Copy link
Owner

yihui commented Jun 9, 2015

Yes, it may be a bug. Forgive my laziness, but perhaps it is easier for you to move the code chunk after \documentclass{article}? :)

@ClaudiusL
Copy link
Contributor Author

I would not say that you are lazy – after all you developed knitr. ;) (That's a hidden "thank you").

Of course, moving the code after \documentclass is easy and works. But maybe it would be usefull to mention this somewhere in the documentation. Is the graphics manual the right place for such things? As soon as I have time I could propose an amendment (and as soon as I found out how to make pull requests).
I would also recommend to mention that windows users need to update filehash when using tikz. These two problems drove me crazy before I found out how to easily fix them and it would be a pitty if people didn't use tikz just because of them.

@yihui
Copy link
Owner

yihui commented Jun 12, 2015

It should not be too difficult to fix the bug. I just don't have the time at the moment and it does not sound like a terrible bug.

Re: filehash, I guess the easiest way is to ask @rdpeng to release a new version of filehash to CRAN, and we update the version requirement in tikzDevice.

@yihui yihui added the bug Bugs label Dec 27, 2015
@yihui yihui added this to the v1.12 milestone Dec 27, 2015
@yihui yihui closed this as completed in 5e2c452 Dec 27, 2015
@yihui
Copy link
Owner

yihui commented Dec 27, 2015

Should be fixed now. Thanks!

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

2 participants