4

I know this question looks like this one but the solutions given there won't work for me.

I'm trying to replace the \element{foo}{bar} macro from automultiplechoice to get something like

\begin{qcm}{foo}
    bar
\end{qcm}

I have tried the environ package, the document compiles but the question defined this way is ignored when using \restitutegroup. Here is my MWE:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{environ}
\usepackage{automultiplechoice}
\usepackage{amsmath}
\usepackage{amsfonts}

\NewEnviron{qcm}[1]{\element{#1}{\BODY}}
\begin{document}

\begin{qcm}{test}
  \begin{question}{foo}
    foo
  \end{question}
\end{qcm}

\element{test}{
   \begin{question}{bar}
     bar
   \end{question}
}

\begin{examcopy}[2]
    \insertgroup{test}
    \clearpage
\end{examcopy}
\end{document}

Only the question "bar" is restituted.

Any clue would be greatly appreciated !

3

Within an environment, the scope of definitions are local unless explicitly made \global. So, any definitions made within qcm may be void if not handled appropriately. This is the case with \element - it creates a token list whose definition (or contents) doesn't survive the group.

The example below makes the definition \global, as well as ensuring that \BODY survives the end of qcm.

enter image description here

\documentclass{article}

\usepackage{environ}
% https://github.com/bdemeshev/pr201/blob/master/prob_exams_collection/automultiplechoice.sty
\usepackage{automultiplechoice}

\NewEnviron{qcm}[1]{%
  \def\arg{#1}%
  \expandafter\element\expandafter\arg\expandafter{\BODY}}

\makeatletter
\renewcommand{\element}[2]{%
  \AMC@prepare@element{#1}%
  \global\csname #1@\romannumeral\AMCtok@k\endcsname={#2}%
}
\makeatother

\begin{document}

\begin{qcm}{test}
  \begin{question}{foo}
    foo
  \end{question}
\end{qcm}

\element{test}{%
   \begin{question}{bar}
     bar
   \end{question}
}

\begin{examcopy}[2]
  \insertgroup{test}
  \clearpage
\end{examcopy}

\end{document}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.