如果这是一个糟糕的问题,我提前道歉,但我一直在尝试使用 TeX-book 读取 Latex 中的宏,但我就是无法弄清楚为什么它不起作用。
所以我有一个“工作”宏(粘贴在下面),它可以让您\ans{<answer>}
在教程表中环绕答案以将答案保存到各种“数组”中;然后使用数组中的答案通过命令创建答案表\s
。“工作”宏代码:
\titleformat{\section}{\titlerule\vspace{1mm}\normalfont\secfnt\bfseries}{\thesection}{2em}{}
\renewcommand{\thesection}{{\noindent\hrulefill}\\ Problem \arabic{section}.}
%%%%%%%Each problem label generated with \section{}
\newcounter{Questionpart}[section]
\newcommand{\Qpart}{(\stepcounter{Questionpart}\alph{Questionpart})
\global\expandafter\def\csname Prob\the\value{section}\endcsname{\the\value{Questionpart}}
}
%%%An attempt to count the parts in each problem but \csname Prob<number> \endcsname doesnt work with \foreach \y in {1,...,\csname Prob<number> \endcsname}
%%%%%Parts a),b).....e), generated by \Qpart.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%Command of interest%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\long\def\ans#1{
\expandafter\global\expandafter\def\csname ans\the\value{section}\the\value{Questionpart} \endcsname{\item\quad#1}
#1
}%An 'array' structure which names each element as ans<problem_number><problem_part_in_numbers>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\p}[1]{
\csname ans#1 \endcsname
}%lets \s call the elements in the 'array'
\newcommand{\s}{\newpage
\begin{center}
\Large\textbf{Solutions}
\end{center}
\foreach \x in {1,...,\value{section}}
{
\textbf{Problem \x}\par
\begin{enumerate}[label=(\alph*)]
\foreach \y in {1,...,10}
%couln't count the parts in a problem so set to 10 as a general size.
{\p{\x\y}\par
}
\end{enumerate}
}
}
问题:
我想为\ans{}
命令实现一个连接功能,以便将\ans{}
同一问题部分中的每个命令加在一起以创建一个完整的答案。(有时它可能是一个“证明”问题,关键点分散开来)
我尝试了这样的事情(但没有效果):
\makeatletter
\long\def\ans#1{% if \DP@#1 is defined append to it otherwise create it
\if\csname ans\the\value{section}\endcsname
\edef\DP@tmp{\csname ans\the\value{section}\endcsname,#1}%
\else
\edef\DP@tmp{#1}%
\fi
\global\expandafter\let\csname ans\the\value{section}\endcsname\DP@tmp
#1
}
\makeatother
我将非常感谢您的帮助或任何指点。