\documentclass[a4paper]{article}
% -------------------------::== package ==::---------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{alltt}
\usepackage{multicol}
\usepackage{amsmath,amssymb}
\usepackage{color}
\usepackage{graphicx}
% Mandatory for conversion
\usepackage[francais,bloc,completemulti]{automultiplechoice}
\usepackage{tikz}
\usepackage{hyperref}
\usepackage{ulem} % strike text
% fp is needed by AMC for numerical question with float. Need to be commented for amc2moodle usage (fp is not yet supported)
\usepackage{fp} 

% -----------------------::== newcommand ==::--------------------------
\newcommand{\feedback}[1]{}
\begin{document}

% -----------------------------------------------------------------------------
\element{moodle2amc}{
  \begin{question}{Essai}\label{q:Essai}   
    Explain in few words the aim of this course.
% It is possible to add more granularity with partially correct answer using \wrongchoice[P]{p}\scoring{0.5}
\AMCOpen{lines=3}{    \correctchoice[OK]{OK}
    \wrongchoice[F]{F}}
  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc}{
  \begin{question}{html layout}\label{q:html layout}   
    a link \href{https://github.com/nennigb/amc2moodle}{here } and an image \includegraphics[]{./Figures/4.png} and an equation \( \int_{2\pi} x^2 \mathrm{d} x \)

\begin{center}
    centered text
\end{center}
flush left text
\begin{flushright}
    flush right text
\end{flushright}
In moodle editor, there is also \textsubscript{exponent} and \textsuperscript{indice} and \sout{that}and svg file \includegraphics[width=100px]{./Figures/dessin.png} 
  \begin{choices}
    \correctchoice{This is the good \underline{underlined} answer.}
    \wrongchoice{This is one \textit{italic} wrong answer.}
    \wrongchoice{This a wrong \textbf{bold} answer.}
    \wrongchoice{This a wrong \textbf{strong} answer.}
    \wrongchoice{This a wrong \emph{emphasis} answer.}

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc}{
  \begin{question}{table}\label{q:table}   
    Test html table conversion to tex


        
\begin{center}
	
  \begin{tabular}{cccc}
  \hline
  


 & weight & width & length\\   

  \hline


sys1 & 1 kg & 0.35 m & 1 m\\   

sys2 & 2 kg & - & 1.5 m\\   

  \hline

	
  \end{tabular}\\
 table legend
\end{center}
 





  \begin{choices}
    \wrongchoice{wrong answer}
    \correctchoice{the good answer is obviously a weird table

        
\begin{center}
	
  \begin{tabular}{cc}
  \hline
  


stuff1 & stuff2\\   

  \hline


\(x^2\) & bold \textbf{text}\\   

  \hline

	
  \end{tabular}\\
 
\end{center}
 
}
    \wrongchoice{an other table, more simple

         
\begin{center}
	
  \begin{tabular}{ccc}
  \hline
  
  Firstname & Lastname & Age\\   

  Jill & Smith & 50\\   

  Eve & Jackson & 94\\   

  \hline
	
  \end{tabular}\\
 
\end{center}
 }

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc}{
  \begin{question}{code}\label{q:code}   
    This is inline code \texttt{x = sqrt(3)} and here and code block

 
\begin{alltt}

a = 2
b = a + 3.14


\end{alltt}

In html, it is generally recommanded to use <code> is an inline tag and <pre><code> tag for blocks.


  \begin{choices}
    \wrongchoice{wrong answer}
    \correctchoice{the good answer}

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc}{
  \begin{question}{ProblemDescription}\label{q:ProblemDescription}   
    \QuestionIndicative
Provide a \textbf{description} of a problem that can be common to several questions. It is useful to define notation, pictures, equations \(\int_0^1 x \mathrm{d} x = 0\)...
  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc-num}{
  \begin{questionmultx}{num:int}\label{q:num:int}   
    Find \(x\) such \(2x-300=0\) ? 
Here \(x\) is an integer, test for \textbf{exact} match, only.

% need \usepackage{fp} for floatting point computation 
\AMCnumericChoices{150}{exact = 0, decimals = 0, sign = false, digits = 3, scoreexact = 1}   

  \end{questionmultx}}

% -----------------------------------------------------------------------------
\element{moodle2amc-num}{
  \begin{questionmultx}{num:float}\label{q:num:float}   
    Give an approximated value for \(\pi\) up to 3 digits?

% need \usepackage{fp} for floatting point computation 
\AMCnumericChoices{3.141592653589793}{exact = 1, decimals = 3, sign = false, digits = 4, scoreexact = 1}   

  \end{questionmultx}}

% -----------------------------------------------------------------------------
\element{moodle2amc-num}{
  \begin{questionmultx}{num:2ans}\label{q:num:2ans}   
    Let \(z=3+2\mathrm{i}\). What is the imaginary part ?

% need \usepackage{fp} for floatting point computation 
\AMCnumericChoices{2}{exact = 0, decimals = 0, sign = false, digits = 1, scoreexact = 1}   

  \end{questionmultx}}

% -----------------------------------------------------------------------------
\element{moodle2amc-num}{
  \begin{questionmultx}{num:2rounding}\label{q:num:2rounding}   
    Give an approximated value for \(\sqrt{2}\) up to 3 digits ?

% need \usepackage{fp} for floatting point computation 
\AMCnumericChoices{1.4142135623730951}{decimals = 3, scoreapprox = 0.5, sign = false, digits = 4, scoreexact = 1, exact = 1, approx = 100}   

  \end{questionmultx}}

% -----------------------------------------------------------------------------
\element{moodle2amc-calculated}{
  \begin{question}{Calculee}\label{q:Calculee}   
    \FPeval{\a}{trunc(1+random*(10-1), 1)} % uniform in [1, 10]
\FPeval{\b}{trunc(1+random*(10-1), 1)} % uniform in [1, 10]
Quelle est l'aire d'un rectangle de longueur \FPprint{\a } et de largeur \FPprint{\b } ?
Formula in the text \FPprint{\FPeval{\out}{clip(\a *\b )}\out}. It is also possible to use float \FPprint{\FPeval{\out}{clip(\a *(\b +2.3)/10.0)}\out}.
Accolade should not be used for number \FPprint{\FPeval{\out}{clip(2.5*2.2)}\out}


  \begin{choices}
    \correctchoice{\FPprint{\FPeval{\out}{clip(\a *\b )}\out}}
    \wrongchoice{\FPprint{\FPeval{\out}{clip(\a +\b )}\out}}

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc-calculated}{
  \begin{question}{CheckComputation}\label{q:CheckComputation}   
    \FPeval{\x}{trunc(1+random*(10-1), 1)} % uniform in [1, 10]
\FPeval{\y}{trunc(1+random*(10-1), 1)} % uniform in [1, 10]
\textbf{Moodle} and \textbf{fp} latex package syntax is not always equivalent. Here some test for pathological cases.
Let \FPprint{\x } and \FPprint{\y } some real number.
 
\begin{itemize}
  \item argument of 'pow' function are in a different order "pow(\FPprint{\x },2)" = \FPprint{\FPeval{\out}{clip(pow(2,\x ))}\out}
  \item the 'sqrt' function doesn't exist, need 'root(nth, x)' in fp, "sqrt((\FPprint{\x }-\FPprint{\y })*(\FPprint{\x }+\FPprint{\y }))" = \FPprint{\FPeval{\out}{clip(root(2, (\x -\y )*(\x +\y )))}\out}
  \item 'pi' is a function in moodle, "sin(1.5*pi())" = \FPprint{\FPeval{\out}{clip(sin(1.5*\FPpi))}\out}
  \item test with '- unary' expression "-\FPprint{\x }+(-\FPprint{\y }+2)" = \FPprint{\FPeval{\out}{clip(neg(\x )+(neg(\y )+2))}\out}
  \item test min-max "max(\FPprint{\x },\FPprint{\y })" = \FPprint{\FPeval{\out}{clip(max(\x ,\y ))}\out}
  \item test nested "log(log(\FPprint{\y }+\FPprint{\x })/log(\FPprint{\y }+\FPprint{\x }))" = \FPprint{\FPeval{\out}{clip(ln(ln(\y +\x )/ln(\y +\x )))}\out}

\end{itemize} 
test formatting on variable \textbf{\FPprint{\x }}

  \begin{choices}
    \correctchoice{\FPprint{\FPeval{\out}{clip(\x )}\out}}
    \wrongchoice{\FPprint{\FPeval{\out}{clip((\y +\x )/(\y +\x ))}\out}}
    \wrongchoice{\FPprint{\FPeval{\out}{clip(ln(\y +\x )/ln(\y +\x ))}\out}}

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc-alternative-format}{
  \begin{question}{markdown}\label{q:markdown}   
    Go to your editor preferences (via the user menu) and select 'Plain text area',
then in the question box, select Markdown format.

{\LARGE\bfseries Main title}

{\Large\bfseries Basic text formatting}

a \emph{single} word
\textbf{\emph{a sequence of words}}
in\textbf{distinguish}able

 
\begin{itemize}

  \item top level bullet one 
\begin{itemize}

  \item sub-bullet  

  \item sub-bullet 2 


\end{itemize} 



  \item top level bullet two


\end{itemize} 

Now numbered list

 
\begin{enumerate}

  \item numbered point one

  \item numbered point two


\end{enumerate} 

{\Large\bfseries More advanced features}

test for link \href{https://docs.moodle.org/310/en/Markdown}{here} 

Are table supported ?

        
\begin{center}
	
  \begin{tabular}{ccc}
  \hline
  

Markdown & Less & Pretty\\   

  \hline


\emph{Still} & \texttt{renders} & \textbf{nicely}\\   

1 & 2 & 3\\   

  \hline

	
  \end{tabular}\\
 
\end{center}
 
\begin{quote}
Blockquotes are very handy in email to emulate reply text.
This line is part of the same quote.

\end{quote}
 
\begin{alltt}
import markdown
markdown.markdown(text, extensions=['extra'])

\end{alltt}

  \begin{choices}
    \wrongchoice{\textbf{yes}}
    \wrongchoice{non}
    \correctchoice{\textbf{perhaps}}

  \end{choices}

  \end{question}}

% -----------------------------------------------------------------------------
\element{moodle2amc-alternative-format}{
  \begin{question}{plain text}\label{q:plain text}   
    Nothing but plain text
  \begin{choices}
    \correctchoice{yes}
    \wrongchoice{\textbf{no}}
    \wrongchoice{no in html}

  \end{choices}

  \end{question}}

% ============================================================================
\exemplaire{1}{    	% nombre de sujet différent

% Replace with your Header
\vspace*{.5cm}
\begin{minipage}{.4\linewidth}
    \centering\large\bf Test
\end{minipage}
\champnom{\fbox{
    \begin{minipage}{.5\linewidth}
Nom et prénom :

\vspace*{.5cm}\dotfill
\vspace*{1mm}
    \end{minipage}}}

\begin{center}
  \Large{\textsc{An AMC quiz generated from moodle XML questions export}}\\
  \normalsize
\end{center}

% mélange et catégorie (groupe dans ACM)
\cleargroup{allquestions}
\copygroup{moodle2amc-calculated}{allquestions}
\copygroup{moodle2amc-alternative-format}{allquestions}
\copygroup{moodle2amc-num}{allquestions}
\copygroup{moodle2amc}{allquestions}
% Shuffling is commented for testing
%\melangegroupe{allquestions}
\restituegroupe{allquestions}}
\end{document}