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

How to make tikzDevice invoke (pdf|xe|lua)latex with -shell-escape ? #172

Open
EmmanuelCharpentier opened this issue Feb 5, 2018 · 9 comments

Comments

@EmmanuelCharpentier
Copy link

I am stuck with the following problem :

I a .Rnw file, i want to use the minted package, which needs to write files and therefore uses the -shell-escape flag on the latex command line. This is done automagically by my working environment (emacs + AUCTeX).

When knitring a .Rnw file with an R chink generating a figure :

  • tikzDevice builds a .tex file using (most of) the master file's preamble (hence uses \usepackage{minted} if present).
  • tikzDevice calls (pdf|xe|lua)latex on this file, without using the -shell-escape flag

The first invocation of tikz fails with the message :

! Package minted Error: You must invoke LaTeX with the -shell-escape flag.

Quitting from lines 34-35 (/home/charpent/Temporaire/Débourrage tikzDevice/Test1/Test1.Rnw)
Erreur : Failed to compile Fig1-1.tex. See Fig1-1.log for more info.

This log file has :

runsystem(mkdir -p _minted-Fig1-1)...disabled (restricted).

! Package minted Error: You must invoke LaTeX with the -shell-escape flag.

See the minted package documentation for explanation.

tikzDevice currently does not seem to offer a way to add this flag to the (pdf|xe|lua)latex invocation (I checked that this cannot be done by setting tikzDefaultEngine).

It goes without saying that the same .Rnw file without \usepackage{minted} compiles perfectly...

I'm stuck...

@yihui
Copy link
Collaborator

yihui commented Feb 5, 2018

We really need to switch to tinytex::latexmk() in the future when compiling LaTeX files in this package. It is possible to enable -shell-escape in tinytex through an R option.

@EmmanuelCharpentier
Copy link
Author

It is possible to enable -shell-escape in tinytex through an R option.

How ?

> library(tinytex)
> grep("tiny", names(options()), value=TRUE)
character(0)

Apparently, there is no tinytex-specific option. An the doc doesn't say pip about it.

Unless you mean the tikz(L|Xel|Lual)atex options ? I tried to set the tikzDefaultEngine, to no avail. I'll try to modify one of these directlty (but not until a few hours...).

@yihui
Copy link
Collaborator

yihui commented Feb 5, 2018

Note that tikzDevice does not use tinytex at the moment. If it does in the future, the option would be options(tinytex.engine_args = '-shell-escape').

@EmmanuelCharpentier
Copy link
Author

I tried :

options(tikzLatexDefault="/usr/bin/pdflatex -shell-escape")
options(tikzLatex="/usr/bin/pdflatex -shell-escape")

to no avail. Same error :

! Package minted Error: You must invoke LaTeX with the -shell-escape flag.

Ditto for :

options(tikzLatexDefault="/usr/bin/pdflatex --shell-escape")
options(tikzLatex="/usr/bin/pdflatex --shell-escape")

Really stuck...

@yihui
Copy link
Collaborator

yihui commented Feb 5, 2018

You don't need to try anything, because I don't think the current version of tikzDevice supports custom arguments for the LaTeX engine.

@EmmanuelCharpentier
Copy link
Author

Okay. My current conclusion is that tikzDevice and packages (such as minted) needing special LaTeX flags are (currently) mutually incompatible.

One might write shell script calling LaTeX with the needed flag and trying to convince tikzDevice to use that, but that would be 'orribly nonportable and fragile..

IMHO, it's either a design error or a bug. That should be fixed. Even if LaTeX user are scarce...

Since tinytex is now mandatory (a call to tikzDevice (at least from knitr) fails if tinytex is not installed), this problem could be fixed in tinytex.

But I'm not yet convinced of the necessity of such a package. More on this in a future issue, either here or in a tinytex issue : I need to think it over...

BTW : the dependency of tikzDevice on tinytex should be explicitly documented.

@yihui
Copy link
Collaborator

yihui commented Feb 5, 2018

The tikzDevice package does not depend on tinytex (at least currently). The dependency in knitr has been documented: https://github.com/yihui/knitr/releases/tag/v1.19

tinytex is a fairly lightweight R dependency, and I should make it clear that it does not require TinyTeX (the custom LaTeX distribution). You can use whatever your favorite LaTeX distribution is.

I'm not interested in convincing you of the many advantages of tinytex including the possibility of setting -shell-escape (I've said enough about other advantages in the documentation), but I'll be happy to know your counterpoints (i.e., why it is bad).

@EmmanuelCharpentier
Copy link
Author

Two things :

  1. I found a workaround for my shell-escape problem : set the chunk option external to FALSE, and the figure will be compiled during the compilation of the main text, whose options are controlled by AUCTeX. Of course, I lose (part of) the benefit of caching...

  2. About tinytex : I think that it is a great idea, provided that it doesn't try to interfere with an existing (especially systemwide, as in most Linux and some Windows machines) TeX installation. More on this after a bit more exploration (and maybe a more mature version of tinytex).

And again : your work on knitr and tikzDevice is outstanding, and has eased the production of reproducible reports for millions of users. The fact that I'm more fond of \LaTeX than of markdown is also a question of personal preferences and past experience... BTW, I discovered docbook and started to explore it. I'm not yet convinced that this solution is simpler that using \LaTeX for a complex report or book ; however, it has the great advantage of not being "paper-bound", as \LaTeX is ; it has therefore a great potential for not-printed documents, which are becoming more and more prevalent.

So don't take my remarks as gratuitous criticism : I aim to constructive criticism (but my aim might be somewhat shaky...).

Since I still think that tikzDevice should be able to enable shell-escape, I leave this issue open. Feel free to close it if you feel that this need is too marginal or the benefit (caching of compiled figures) too small to bother...

@EmmanuelCharpentier
Copy link
Author

I have proposed a (partial) solution to this annoyance. There remains problems probably attributable to the way knitr invokes its compilers. I consider them a separate issue, since the proposed solution allows a correct compilation using other compiler systems (e. g. AUCTeX...).

HTH,

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

2 participants