如何删除 \NewEnviron 定义的环境的 \BODY 宏中的命令

如何删除 \NewEnviron 定义的环境的 \BODY 宏中的命令

我的宏定义的环境\NewEnviron包含一个宏。当宏执行时,\mymacro如何删除宏\mymacro中的宏?\BODY

\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}

我该如何删除宏\mymacro中的\result?我试了很多方法,但还是不行!

现在我想更详细地说明我的问题,以便专家能够帮助我。

我有很多以下结构的多项选择题:

\begin{myenviron}
Question
\choice{\True First answer}{Second answer}{Third answer}{Fourth answer}
\sulution{The detail solution.}
\end{myenviron}

这里的\True意思是那是正确的答案。

我想要转换成multimoodle包的环境以便上传到我的moodle网站。

我尝试做了如下操作:

\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}

它工作正常,并在 pdf 文件中正确输出。但是,在 .xml 文件中,正文包含\choice\solution宏。这是 .xml 文件中包含的正文:

<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>

而我只需要This is my question

相关内容