![宏接受多行并输出空行,用于编写推导](https://linux22.com/image/421432/%E5%AE%8F%E6%8E%A5%E5%8F%97%E5%A4%9A%E8%A1%8C%E5%B9%B6%E8%BE%93%E5%87%BA%E7%A9%BA%E8%A1%8C%EF%BC%8C%E7%94%A8%E4%BA%8E%E7%BC%96%E5%86%99%E6%8E%A8%E5%AF%BC.png)
我想输出 n 行“=......”形式的代码。学生必须在每一行上写下推导的一个步骤。我设法让它在 3 行上工作,但我的 n 行宏不起作用。
我的最小工作示例是:
\documentclass[11pt, a4paper, parskip=full]{scrartcl}
\usepackage{pgffor}
\usepackage{amsmath}
\newcommand*{\mystrut}{\rule[-0.05\baselineskip]{0pt}{1.2\baselineskip}}
\newcommand*{\mybox}[1]{\framebox{\mystrut #1}}
\newcommand{\derivblank}[1]{
\begin{align*}
\foreach \line in {1, ..., #1}{%
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
}
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
}
\begin{document}
\section*{Derivation of 3 steps}
Write your derivation below in 3 steps:
\begin{align*}
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
\section*{Fails for arbitrary number of lines}
Write your derivation below in $n$ steps:
%\derivblank{2}
\end{document}
答案1
比对的每个单元都是一个本地组,您在一个单元中启动 pgf 循环,这样一旦插入&
范围结束,循环代码就会中断。
这是一个没有进行任何分配的版本,因此不受单元格范围的影响。
\documentclass[11pt, a4paper, parskip=full]{scrartcl}
\usepackage{pgffor}
\usepackage{amsmath}
\newcommand*{\mystrut}{\rule[-0.05\baselineskip]{0pt}{1.2\baselineskip}}
\newcommand*{\mybox}[1]{\framebox{\mystrut #1}}
\newcommand{\derivblank}[1]{%
\begin{align*}
\xderivblank{#1}%
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
}
\newcommand\xderivblank[1]{%
\ifnum#1=0 \else
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
\xderivblank{\numexpr#1-1}\fi}
\begin{document}
\section*{Derivation of 3 steps}
Write your derivation below in 3 steps:
\begin{align*}
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm}\underline{\mystrut\hspace{3cm}} \\
&= \hspace{0.2cm} \mybox{\underline{ \hspace{3cm}}}
\end{align*}
\section*{Fails for arbitrary number of lines}
Write your derivation below in $n$ steps:
\derivblank{2}
\end{document}