| 1 |
% !TeX encoding = UTF-8 |
| 2 |
% !TeX spellcheck = en_US |
| 3 |
% !TEX TS-program = lualatex |
| 4 |
\documentclass{article} |
| 5 |
\usepackage[nostamp]{moodle} |
| 6 |
\ifPDFTeX % FOR LATEX and PDFLATEX |
| 7 |
\usepackage[utf8]{inputenc} % necessary |
| 8 |
\usepackage[T1]{fontenc} % necessary |
| 9 |
\else % assuming XELATEX or LUALATEX |
| 10 |
\usepackage{fontspec} |
| 11 |
\fi |
| 12 |
\usepackage{hyperref,luacode} |
| 13 |
\begin{document} |
| 14 |
|
| 15 |
\section*{Introduction} |
| 16 |
|
| 17 |
This document is intended to check the possibility of generating |
| 18 |
pseudo-calculated questions with the help of Lua scripts. |
| 19 |
|
| 20 |
Inspired by |
| 21 |
\url{https://github.com/avohns/python-latex-moodle-quiz/blob/master/simple-examples-eng/example1_arithmetic.tex} |
| 22 |
|
| 23 |
\begin{quiz}[tags={calculated}]{Example Quiz} |
| 24 |
% THIS DOES NOT REQUIRE LUACODE AND WORKS WITH RECENT LUATEX (2020) |
| 25 |
%\directlua{ |
| 26 |
%function clozenum_print(pair,op,result) |
| 27 |
% tex.print("\\begin{numerical}$"..pair[1].." "..op.." "..pair[2].." |
| 28 |
% =$".."\\item ",result,"\\end{numerical}") |
| 29 |
%end |
| 30 |
%function cloze_print(pair,points) |
| 31 |
% tex.print("\\begin{cloze}[points="..points.."]{Arithmetic Quiz |
| 32 |
% ("..pair[1]..", "..pair[2]..")}Solve the following tasks!\\\\") |
| 33 |
% clozenum_print(pair,"+",pair[1]+pair[2]) |
| 34 |
% clozenum_print(pair,"-",pair[1]-pair[2]) |
| 35 |
% clozenum_print(pair,"*",pair[1]*pair[2]) |
| 36 |
% if pair[1]/pair[2]==math.floor(pair[1]/pair[2]) then |
| 37 |
% clozenum_print(pair,":",math.floor(pair[1]/pair[2])) |
| 38 |
% end |
| 39 |
% tex.print("\\end{cloze}") |
| 40 |
%end |
| 41 |
%for x = 2,4 do |
| 42 |
% for y = 2,4 do |
| 43 |
% if x>y then |
| 44 |
% if x/y==math.floor(x/y) then points=4 else points=3 end |
| 45 |
% cloze_print({x,y},points) |
| 46 |
% end |
| 47 |
% end |
| 48 |
%end |
| 49 |
%} |
| 50 |
% THIS SEEMS TO WORK BETTER WITH EARLIER VERSIONS OF LUATEX |
| 51 |
\begin{luacode*} |
| 52 |
function clozenum_print(pair,op,result) |
| 53 |
tex.print([[\begin{numerical}$]]..pair[1].." "..op.." "..pair[2].. |
| 54 |
" = $"..[[\item ]],result,[[\end{numerical}]]) |
| 55 |
end |
| 56 |
function cloze_print(pair,points) |
| 57 |
tex.print([[\begin{cloze}[points=]]..points.."]{Arithmetic Quiz (".. |
| 58 |
pair[1]..", "..pair[2]..[[)}Solve the following tasks!\\]]) |
| 59 |
clozenum_print(pair,"+",pair[1]+pair[2]) |
| 60 |
clozenum_print(pair,"-",pair[1]-pair[2]) |
| 61 |
clozenum_print(pair,"*",pair[1]*pair[2]) |
| 62 |
if pair[1]/pair[2]==math.floor(pair[1]/pair[2]) then |
| 63 |
clozenum_print(pair,":",math.floor(pair[1]/pair[2])) |
| 64 |
end |
| 65 |
tex.print([[\end{cloze}]]) |
| 66 |
end |
| 67 |
for x = 2,4 do |
| 68 |
for y = 2,4 do |
| 69 |
if x>y then |
| 70 |
if x/y==math.floor(x/y) then points=1 else points=2 end |
| 71 |
cloze_print({x,y},points) |
| 72 |
end |
| 73 |
end |
| 74 |
end |
| 75 |
\end{luacode*} |
| 76 |
\end{quiz} |
| 77 |
\end{document} |