My environment defined by \NewEnviron macro contains a macro \mymacro. How can to delete the macro \mymacro in the \BODY macro, when it executes?
\documentclass{article}
\NewEnviron{myenviron}{\newcommand\mymacro[2]{\def\textone{##1}}{\def\texttwo{##2}}} \gdef\result{\BODY}}
\begin{document}
\begin{myenviron}
Some text here
\mymacro{Textone}{Texttwo}
\end{myenviron}
\end{document}
How can I delete the \mymacro in the \result macro? I have try by many ways, but I cannot!
Now I want to add more detail my problem so that the experts can help me.
I have a lot of multiple choice questions in of the following structure:
\begin{myenviron}
Question
\choice{\True First answer}{Second answer}{Third answer}{Fourth answer}
\sulution{The detail solution.}
\end{myenviron}
Here \True means that is the correct answer.
I want to convert to the multi environment of the moodle package to upload to my moodle website.
I have tried to do as follows:
\documentclass[12pt,a4paper]{article}
\usepackage[final]{moodle}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{environ}
\usepackage{xstring}
\moodleregisternewcommands
\makeatletter
\newcounter{c@ex}%
\newcounter{ans@wer}%
\newcounter{correct@answer}%
\newcommand{\True}{}%
\newcommand\exname{MC}
%%define the command to hide the text body of the environment.
\newlength{\trashlength}%
\def\hide@text#1{%
\settowidth{\trashlength}{#1}
}
%%define the command to find the correct answer.
\def\begin@ans{@ifnextchar\True
{\setcounter{correct@answer}{\theans@wer}}{\stepcounter{ans@wer}}%
}
\environbodyname@body
\htmlregister@body
\NewEnviron{myenviron}{%
\stepcounter{c@ex}
\setcounter{ans@wer}{1}
}%
\AtEndEnvironment{myenviron}{%
\newcommand{\choice}[4]{
\newcommand{\ansone}{#1}\hide@text{\begin@ans #1}
\newcommand{\anstwo}{#2}\hide@text{\begin@ans #2}
\newcommand{\ansthree}{#3}\hide@text{\begin@ans #3}
\newcommand{\ansfour}{#4}\hide@text{\begin@ans #4}}%
\newcommand{\solution}[1]{\newcommand{\feed@back}{#1}}%
\hide@text{\xa\global\xa\def\xa\result\xa{@body}}
\ifnum\the\value{correct@answer}=1%
\begin{multi}[numbering=ABCD,penalty=0,feedback={\feed@back}]{\exname\thec@ex}
@body
\item* \ansone%
\item \anstwo%
\item \ansthree%
\item \ansfour%
\end{multi}
\else
\ifnum\the\value{correct@answer}=2%
\begin{multi}[numbering=ABCD,penalty=0,feedback={\feed@back}]{\exname\thec@ex}
@body
\item \ansone%
\item* \anstwo%
\item \ansthree%
\item \ansfour%
\end{multi}
\else
\ifnum\the\value{correct@answer}=3
\begin{multi}[numbering=ABCD,penalty=0,feedback={\feed@back}]{\exname\thec@ex}
@body
\item \ansone%
\item \anstwo%
\item* \ansthree%
\item \ansfour%
\end{multi}
\else
\ifnum\the\value{correct@answer}=4
\begin{multi}[numbering=ABCD,penalty=0,feedback={\feed@back}]{\exname\thec@ex}
@body
\item \ansone%
\item \anstwo%
\item \ansthree%
\item* \ansfour%
\end{multi}
\else
\relax
\fi
\fi
\fi
\fi
}%
\makeatother
\begin{document}
\begin{quiz}{My first test}
\begin{myenviron}
This is my question.
\choice
{\True Answer one}
{Answer two}
{Answer three}
{Answer four}
\solution{This is a detail answer.}
\end{myenviron}
\end{quiz}
\end{document}
It work fine and output correctly in pdf file. However, in .xml file, the body contains the \choice and \solution macros. This is the body containing in .xml file:
<text><![CDATA[<p>This is my question. <BR/> \newcommand {Answer one}{Answer one}\hide@text {\begin@ans Answer one} \newcommand {Answer two}{Answer two}\hide@text {\begin@ans Answer two} \newcommand {Answer three}{Answer three}\hide@text {\begin@ans Answer three} \newcommand {Answer four}{Answer four}\hide@text {\begin@ans Answer four} \newcommand {This is a detail answer.}{This is a detail answer.}</p>]]></text>
while I need only This is my question.
\mymacroor all of\mymacro{Textone}{Texttwo}? do you want\textoneand\texttwoto be defined? (they will not be if you delete\mymacro?) – David Carlisle Aug 29 '23 at 14:12\resultafter the environment but it's not at all clear what that definition should be – David Carlisle Aug 29 '23 at 14:43\xdef\result{\BODY}(plus removing some extra braces).\BODYis undefined outside the environment. Note that\textoneand\texttwoare local and wil be lost. – John Kormylo Aug 29 '23 at 14:48myenviron. I want to convert them to another environment or write to a .tex file in subtable structure. So I want theSome text hereof the environment, because it is easy to catch the \textone and \texttwo by set the global macros. – phchon Aug 29 '23 at 15:00\resultto contain only that? What should the output of the actual environment be and what are the other definitions supposed to do? – cfr Aug 29 '23 at 15:06\begin{myenviron} Question.... \choice{first answer}{\True second answer}{third answer}{fourth answer} \solution{The detail solution} \end{myenviron}. I want to convert them to the structure ofmultienvironment of moodle package. – phchon Aug 29 '23 at 15:12myenvironlooks like to begin with and what you would like it to have looked like, given the appropriate processing? – Steven B. Segletes Aug 29 '23 at 15:39