SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-10-01 09:14
[forum:48222]
My understanding so far is that we are using magick::image_read() as intended and that it stopped working due to potential upstream conflicts between magick and ImageMagick. Hence, I'm still hoping that Jeroen, the magick maintainer, or Dirk, the ImageMagick maintainer, will be able to resolve this problem upstream.

As a workaround while we wait, you can resort to SVG instead of PNG graphics.

And just for reference:

The upstream discussion is in magick's GitHub issues:
https://github.com/ropensci/magick/issues/272

And there is also a related discussion on StackOverflow started by the R/exams user that first posted in the GitHub issues:
https://stackoverflow.com/questions/64142760/unable-to-generate-exam-with-exams2moodle-when-including-tikz-picture

RE: Issue in a template using include_tikz() [ Reply ]
By: Stefan Etschberger on 2020-10-01 09:06
[forum:48221]
With a minimal example, I had a reproducible crash in RStudio as well. Could be, that pdf files (generated with include_tikz()) resulting in more than 1 page are causing the problem (as in my case).

My workaround is to generate a pdf file via

filename.pdf = include_tikz(tex, format = "pdf")

and do the png manually (reading only the firt page of the pdf):

tikzpicture.magick = magick::image_read_pdf(filename.pdf, pages=1)
filename.png = filename.pdf %>% str_replace("\\.pdf", "\\.png")
magick::image_write(tikzpicture.magick, path=filename.png)

Stefan

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-30 21:43
[forum:48220]
Thanks for checking, that's at least something. Hopefully Jeroen will figure out the problem with magick::image_read().

RE: Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-30 21:23
[forum:48219]
Hello,

exams2html("automaton.Rnw", svg = TRUE)
that works, thanks a lot.

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-30 20:56
[forum:48218]
Another workaround you could try is to use SVG instead of PNG for the TikZ output, simply use

exams2html("automaton.Rnw", svg = TRUE)

or exams2moodle instead of exams2html. This needs pdf2svg to be available, though, instead of Ghostscript.

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-30 19:16
[forum:48217]
Sorry, not at the moment. Even for an option I would have to add a "Suggests" dependency - all of which increase the maintenance load of the package.

RE: Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-30 16:51
[forum:48216]
Thanks Brett, that was the problem on the linux side. The windows installation of Image-magick has a file called policy.xml, but nothing in there suggests any restriction to ghostscript.

Thanks Achim, I will keep trying to get ghostscript work with R here. By the way ghostscript here is version 9.53.2.

Just one try: is it a bad idea to pass an option between gs and pdftools somewhere? Sorry.

Thanks

RE: Issue in a template using include_tikz() [ Reply ]
By: Brett Presnell on 2020-09-30 16:32
[forum:48215]
I had this problem in some other context I think. In any case, it was solved (in Ubuntu 20.04) by editing /etc/ImageMagick-6/policy.xml as root (sudo) and making the following change to the last few lines of the file:

<!-- disable ghostscript format types -->
<!-- not needed as of Ghostscript 9.24 -->
<!-- all changed to "read | write" Presnell (2020-09-16) -->
<policy domain="coder" rights="read | write" pattern="PS" />
<policy domain="coder" rights="read | write" pattern="PS2" />
<policy domain="coder" rights="read | write" pattern="PS3" />
<policy domain="coder" rights="read | write" pattern="EPS" />
<policy domain="coder" rights="read | write" pattern="PDF" />
<policy domain="coder" rights="read | write" pattern="XPS" />

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-30 15:38
[forum:48214]
Pedro, thanks for investigating this so carefully and reporting back here.

The decision to use magick::image_read() was a conscious decision in order not to depend on yet another application ("pdftools" is based on the "poppler" library). But we might change this in the future if we also decide to switch from PDFTk to poppler for processing scanned PDF images in exams2nops/nops_scan.

RE: Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-30 14:15
[forum:48213]
Hello,

this is just to give a feedback on how far I could progress with this issue.

1) In the machine running Ubuntu 20.04, the issues were gone after following the suggestion in the mentioned SO thread. This appeared when ghostscript comes into play.

2) In the Windows machine although, the issue persists, and it is in fact a problem relating magick package, and ghostscript:
magick::image_read("file.pdf") gives an error in W10! and do the job in Linux!
magick::image_read_pdf("file.pdf") worked in both systems.
The first function pass through ghostscript. It should, probably, work but don't work at my Windows, and I'm lost here! The second function is the recommend way to work according the developer of "magick" (Jeroen Ooms). It relies on another package "pdftools".

3) Back to exams package: In conclusion to all of described above, the issues I had in windows emerged from the function exams::tex2image(), where in the line 140 magick::image_read() was used to process a PDF file. Maybe could the developer team consider changing this function to magick::image_read_pdf(). :) I have tested it locally and it worked.

I see that someone opened an issue at magick dev site that would be corrected with this also.

https://github.com/ropensci/magick/issues/272

Thanks for all.

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-27 15:51
[forum:48183]
OK, that confirms my suspicion from the previous post that magick is the source of the problems. On Windows you should be able to get the magick binaries which should hopefully run. On Ubuntu you need to install libmagick++-dev on the system (i.e., "apt-get install libmagick++-dev") before installing the R package "magick".

As for the security policy: I haven't seen this before but this StackOverflow post appears to be related.

https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion

RE: Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-27 15:41
[forum:48182]
Hello,
Sorry, but I want to update with my experience on the linux machine. It runs ubuntu 20.04 with KDE. The R version is 3.6.3.

1. There I repeat the tests with include_tikz(circulo, name="testxyz", format="xyz"), and again with xyz = pdf||svg test was passed, and
xyz=png give me trouble.

Troubles were:
a. magick and curl packages were required and demanded c++ compilation.
I remember that was the case also in windows!

b. running the teste I got this:
> include_tikz(c, name="circulopng", format="png")
Loading required namespace: tinytex
Error in magick_image_readpath(enc2native(path), density, depth, strip, :
R: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408

Seems I'm not dealing with the "magick package" in the proper way.

thanks again

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-27 15:32
[forum:48181]
OK, that suggests that the problem is with the "magick" package. Could you try whether the following work?

example("image_read", package = "magick")
example("image_write", package = "magick")

Possibly re-installing the "magick" package solves the problem...

RE: Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-27 13:10
[forum:48180]

1. exams2html("automaton.Rnw") -> This Crashed as the previous examples.

2. exams2moodle("boxplots.Rnw") -> This runs smoothly an generate the xml file with the "png" embedded.

3. Further tests indicates that the function tikzpicture with the format png is creating my troubles:

<<>>=
> circulo <- "\\begin{tikzpicture} \\draw (0,0) circle (2cm); \\end{tikzpicture}"
> include_tikz(circulo, name= "zirkpdfa", format= "pdf")
\includegraphics{zirkpdfa.pdf}
>
@

This first example worked as I expected. It generates correctly the file \textit{zirkpdfa.pdf}

<<>>=
> include_tikz(circulo, name= "zirksvga", format= "svg")
## \includegraphics{zirksvga.svg}
@

this worked too. The file \textit{zirksvga} is there.

Now I expected a fail with the PNG format!

<<>>=
> include_tikz(circulo, name= "zirkpnga", format= "png")
@

Indeed this last command terminated abruptly the R-session

4. Well, I will try later in a linux plataform, than you for your time and appreciate any other suggestion!

RE: Issue in a template using include_tikz() [ Reply ]
By: Achim Zeileis on 2020-09-27 02:14
[forum:48167]
I cannot replicate this. For Does

exams2html("automaton.Rnw")

work for you? Does

exams2moodle("boxplots.Rnw")

work for you?

I would suspect that at least one of these should also fail which would mean that the problem is not specific to Moodle or to TikZ...

Issue in a template using include_tikz() [ Reply ]
By: Pedro Aladar Tonelli on 2020-09-26 14:31
[forum:48164]
Hello,

I'm starting trying to get tikz to make the moodle quizes. I started looking at the examples automaton.Rnw and .Rmd but:
I run in an R terminal in Windows 10:
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
then:
> exams2pdf("automaton.Rnw",n=1,name="testetikza")
Loading required namespace: tinytex
> ##^^^^
was ok, but
> exams2moodle("automaton.Rnw", n=1, name="testetikzb")
Loading required namespace: rmarkdown
PS C:\Users\paton\moodle> :(
crashed the R-session !

I reinstalled the new version of "exams" already. Had anybody else the same problem?

Thanks to:
Vienna University of Economics and Business Powered By FusionForge