TransWikia.com

Moodlle package: problem with includegraphics and tikzpicture

TeX - LaTeX Asked by kalakay on January 4, 2021

For me, there are still two problems in the XML file as a result of moodle package, when includegraphics command and tikzpicture environment are used. Both of them cannot appear on the moodle site. How to handle it?

I have obtained some clues, as stated in the following document.

documentclass[12pt]{article}
usepackage[margin=3cm]{geometry}
usepackage{fouriernc,sourceserifpro}
usepackage[draft]{moodle}
usepackage{graphicx}
usepackage{xpatch}
makeatletter
defgraphicspath#1{defGinput@path{#1}edefmoodleimgpath{@firstofone#1}}

xpatchcmd{moodle@includegraphics@int@int}%
{opensslotherspace enc -base64 -in #2.jpg -out #2.enc}%
{opensslotherspace enc -base64 -in moodleimgpath#2.jpg -out #2.enc}%
{typeout{patch ok}}%
{typeout{patch failed}}
makeatother

graphicspath{{./gambar/}}
pagestyle{empty}
usepackage{tikz}
newsaveboxpicbox
begin{lrbox}{picbox}%
begin{tikzpicture}
       draw[thick] (0,0) circle(1cm);
end{tikzpicture}
end{lrbox}
begin{document}

begin{quiz}{Pelatihan 1}
  begin{multi}[shuffle=true, points=1]{{em Corona Virus Disease}-19}
    Soal ini berbentuk pilihan berganda.

    includegraphics[width=6cm]{covid-19}

  item* 1
  item 2
end{multi}

begin{numerical}[points=2]{Tentang soal nomor 2}
Soal ini berbentuk numerik dan opsinya berupa {em itemize}.
item 11
end{numerical}

begin{shortanswer}[case sensitive=true]{Tentang soal nomor 3}
Soal ini berbentuk {em case sensitive} dan opsinya berupa {em itemize}.
item Benar
item[fraction=0, feedback={Bukan, Bro!}] Salah
item{fraction=50} Bukan jawaban
end{shortanswer}

begin{multi}[points=3]{Turunan pertama}
Apa turunan pertama dari $x^3$?
item $frac{1}{4} x^4+C$
item* $3x^2$
end{multi}

begin{multi}{Gambar}
Apakah ini sebuah lingkaran?

useboxpicbox

      item* Ya
      item Bukan
    end{multi}
end{quiz}

end{document}

I got the image from here.

One Answer

Well --- this is from my experience (please notice that I do not understand the language in which the test is written, at all. So I do not take responsibility about it) (better use English next time, please!):

  1. moodle.sty patches things in tikz, and I really never managed to make it work. So I normally use an external, standalone file to generate the image and then include it with includegraphics.

  2. Also, graphic paths are tricky --- although there is a patch floating around, I prefer to simply add the image in the same directory and forget it.

  3. You are patching graphicx (I do not know why), and using em which is deprecated since at least 30 years... ;-) --- it has to use emph{text} which is the correct way.

  4. The patch you are applying to the moodle include command is failing: in the log you have:

    ...
    patch failed
    (./testm.aux)
    *geometry* driver: auto-detecting
    ...
    

So, this code here:

documentclass[12pt]{article}
usepackage[margin=3cm]{geometry}
usepackage[]{moodle}
usepackage{graphicx}

begin{document}

begin{quiz}{Pelatihan 1}
  % You can't use commands in the test name!
  begin{multi}[shuffle=true, points=1]{Corona Virus Disease-19}
    Soal ini berbentuk pilihan berganda.

    includegraphics[width=6cm]{covid-19.jpg}

  item* 1
  item 2
end{multi}

begin{numerical}[points=2]{Tentang soal nomor 2}

Soal ini berbentuk numerik dan opsinya berupa emph{itemize}.
item 11
end{numerical}

begin{shortanswer}[case sensitive=true]{Tentang soal nomor 3}
Soal ini berbentuk emph{case sensitive} dan opsinya berupa emph{itemize}.
item Benar
item[fraction=0, feedback={Bukan, Bro!}] Salah
item{fraction=50} Bukan jawaban
end{shortanswer}

begin{multi}[points=3]{Turunan pertama}
Apa turunan pertama dari $x^3$?
item $frac{1}{4} x^4+C$
item* $3x^2$
end{multi}

begin{multi}{Gambar}
Apakah ini sebuah lingkaran?

      item* Ya
      item Bukan
    end{multi}
end{quiz}

end{document}

works correctly if the file covid-19.jpg is in the same directory and compiled with pdflatex -shell-escape testm.sty.

enter image description here

...and the first one:

enter image description here

If you have problems in the inclusion of the image, check that the conversion is working ok in the log file (or in the output); in my case it is:

...
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd)
moodle.sty: Processing includegraphics[width=6cm]{covid-19.jpg} for HTML...
moodle.sty: Converting 'covid-19.jpg' to PNG...
moodle.sty: Converting 'covid-19.jpg.png' to base64...
moodle.sty: Reading base64 file 'covid-19.jpg.enc'...
moodle.sty: <IMG> tag inserted.
...

To help debug graphical problems, you can download this file as moodleshow.tex and then add

input{moodleshow.tex}

in your preamble (after loading moodle package), it will print additional info in the log file like this:

moodle.sty: Processing includegraphics[width=6cm]{covid-19.jpg} for HTML...
moodle.sty: Converting 'covid-19.jpg' to PNG...
command is: convert covid-19.jpg -resize 472 covid-19.jpg.png
command is: openssl enc -base64 -in covid-19.jpg.png -out covid-19.jpg.enc
command is: openssl enc -base64 -in covid-19.jpg.png -out covid-19.jpg.enc
moodle.sty: Reading base64 file 'covid-19.jpg.enc'...
moodle.sty: <IMG> tag inserted.

About the circle image, you can generate a PDF using tikz and the standalone class, and then include it with includegrahics{} as well.

Correct answer by Rmano on January 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP