TeX - LaTeX Asked on April 10, 2021
I’m trying to upload a Quiz for the first time to Moodle and I’m generating my files using the package{Moodle}. The problem is the uploaded file doesn’t recognize the matrix environment and displayed the code instead of the matrix form. Is there a solution for that.
documentclass[12pt]{article}
usepackage{amsmath,amsthm, amssymb, latexsym}
makeatletter
renewcommand*env@matrix[1][c]{hskip -arraycolsep
let@ifnextcharnew@ifnextchar
array{*c@MaxMatrixCols #1}}
makeatother
usepackage{moodle}
begin{document}
begin{quiz}{Revisiting Linear Algebra}
begin{multi}[points=2]{Matrix Form of a Linear System}
Consider the following system
begin{center}
$
begin{matrix}[r]
3.0 x_1 &+2.0 x_2 &+2.0 x_3 & -5.0 x_4 & =8 .0
0.6 x_1 &+ 1.5 x_2 &+1.5 x_3 & -5.4 x_4 & =2.7
1.2 x_1 & -0.3 x_2 & -0.3 x_3 & 2.4 x_4 & =2.1 ,
end{matrix}
$
end{center}
which may be written as a single vector equation; i.e, $mathbf{AB}=mathbf{B}$.
The $mathbf{A}$ matrix associated with the system is:
item*
$
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0
0.6 &+ 1.5 &+1.5 & -5.4
1.2 & -0.3 & -0.3 & 2.4 ,
end{bmatrix}
$
item $
begin{bmatrix}[r]
8 .0
2.7
2.1
end{bmatrix}
$
item $
begin{bmatrix}[r]
x_1 &
x_2&
x_3 &
x_4 &
end{bmatrix}
$
item
$
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0 & 8.0
0.6 &+ 1.5 &+1.5 & -5.4 & 2.7
1.2 & -0.3 & -0.3 & 2.4 , & 2.1
end{bmatrix}
$
end{multi}
begin{multi}[points=2]{Matrix Form of a Linear System}
Consider the following system
begin{center}
$
begin{matrix}[r]
3.0 x_1 &+2.0 x_2 &+2.0 x_3 & -5.0 x_4 & =8 .0
0.6 x_1 &+ 1.5 x_2 &+1.5 x_3 & -5.4 x_4 & =2.7
1.2 x_1 & -0.3 x_2 & -0.3 x_3 & 2.4 x_4 & =2.1 ,
end{matrix}
$
end{center}
which may be written as a single vector equation; i.e, $mathbf{AB}=mathbf{B}$.
The $mathbf{B}$ matrix associated with the system is:
item*
$
begin{bmatrix}[r]
8 .0
2.7
2.1
end{bmatrix}
$
item[fraction=0]
$
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0
0.6 &+ 1.5 &+1.5 & -5.4
1.2 & -0.3 & -0.3 & 2.4 ,
end{bmatrix}
$
item[fraction=0]
$
begin{bmatrix}[r]
x_1 &
x_2&
x_3 &
x_4 &
end{bmatrix}
$
item[fraction=0]
$
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0 & 8.0
0.6 &+ 1.5 &+1.5 & -5.4 & 2.7
1.2 & -0.3 & -0.3 & 2.4 , & 2.1
end{bmatrix}
$
end{multi}
end{quiz}
end{document}
The manual for moodle.sty
(page 10) mentions that only four environments are recognized and converted to html: center
, enumerate
, itemize
and tikzpicture
. All other environments, such as matrix
, therefore cannot be used. Quote (emphasis mine):
Be aware that moodle.sty does not know how to convert any other TEX or LATEX commands to HTML. If other sequences are used, they may be passed verbatim to the XML file or may cause unpredicted results.
However, within a tikzpicture
you can use LaTeX code inside of a node
, which allows you to use the matrix
environment. The matrices will be converted to images by Moodle and stored in base64 encoding in the .xml
file, similar to including .png
files for example.
Note that to make this work you may need to call tikzexternalize
explicitly in your quiz source code. Also shell-escape
is required (same as with images).
MWE:
documentclass[12pt]{article}
usepackage{amsmath,amsthm, amssymb, latexsym}
usepackage{tikz}
makeatletter
renewcommand*env@matrix[1][c]{hskip -arraycolsep
let@ifnextcharnew@ifnextchar
array{*c@MaxMatrixCols #1}}
makeatother
usepackage{moodle}
usetikzlibrary{external} % set this
tikzexternalize % explicitly
begin{document}
begin{quiz}{Revisiting Linear Algebra}
begin{multi}[points=2]{Matrix Form of a Linear System}
Consider the following system
begin{tikzpicture} % matrix inside of tikzpicture node
node{
$begin{matrix}[r]
3.0 x_1 &+2.0 x_2 &+2.0 x_3 & -5.0 x_4 & =8 .0
0.6 x_1 &+ 1.5 x_2 &+1.5 x_3 & -5.4 x_4 & =2.7
1.2 x_1 & -0.3 x_2 & -0.3 x_3 & 2.4 x_4 & =2.1 ,
end{matrix}
$};
end{tikzpicture}
which may be written as a single vector equation; i.e, $mathbf{AB}=mathbf{B}$.
The $mathbf{A}$ matrix associated with the system is:
item*
begin{tikzpicture}
node{ $
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0
0.6 &+ 1.5 &+1.5 & -5.4
1.2 & -0.3 & -0.3 & 2.4 ,
end{bmatrix}
$};end{tikzpicture}
itembegin{tikzpicture}
node{ $
begin{bmatrix}[r]
8 .0
2.7
2.1
end{bmatrix}
$};end{tikzpicture}
item begin{tikzpicture}
node{$
begin{bmatrix}[r]
x_1 &
x_2&
x_3 &
x_4 &
end{bmatrix}
$};end{tikzpicture}
item
begin{tikzpicture}
node{$
begin{bmatrix}[r]
3.0 &+2.0 &+2.0 & -5.0 & 8.0
0.6 &+ 1.5 &+1.5 & -5.4 & 2.7
1.2 & -0.3 & -0.3 & 2.4 , & 2.1
end{bmatrix}
$};end{tikzpicture}
end{multi}
end{quiz}
end{document}
Part of the resulting xml:
<questiontext format="html">
<text><![CDATA[<p>Consider the following system </P>
<P><IMG SRC="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAc4AAACOCAYAAAC4 etc.
Answered by Marijn on April 10, 2021
The best practise solution seems to replace matrix
with array
one as proposed by the Moodle manual, as follows:
documentclass[12pt]{article}
usepackage{amsmath}
usepackage{moodle}
begin{document}
begin{quiz}{Revisiting Linear Algebra}
begin{multi}[points=2]{Matrix Form of a Linear System}
Consider the following system
[
left[
begin{array}{ccccc}
3.0 x_1 &+2.0 x_2 &+2.0 x_3 & -5.0 x_4 & =8.0
0.6 x_1 &+ 1.5 x_2 &+1.5 x_3 & -5.4 x_4 & =2.7
1.2 x_1 & -0.3 x_2 & -0.3 x_3 & 2.4 x_4 & =2.1 ,
end{array}right]
]
which may be written as a single vector equation; i.e, $mathbf{AB}=mathbf{B}$.
The $mathbf{A}$ matrix associated with the system is:
item* First answer
[
left[
begin{array}{cccc}
3.0 &+2.0 &+2.0 & -5.0
0.6 &+ 1.5 &+1.5 & -5.4
1.2 & -0.3 & -0.3 & 2.4 ,
end{array}
right]
]
item Second answer
end{multi}
end{quiz}
end{document}
Important note: the currently published moodle
package version 0.5 is outdated and has a bug that does not handle . You have to download the latest version from here. Installation guidelines are here.
Answered by Moshe Gueta on April 10, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP