我有以下两个宏,用于向我的乳胶文件添加某种“修订”:
\newcommand\rem[2][1]{
\ifdefined\revision
\ifnum \revision = 0
\textcolor{red}{\sout{#2}}
\else
\ifnum \revision < #1 #2 \fi
\ifnum \revision = #1 \textcolor{red}{\sout{#2}} \fi
\fi
\fi
}
\newcommand\remb[2][1]{
\ifdefined\revision
\ifnum \revision = #1 #2 \fi
\ifnum \revision < #1 #2 \fi
\fi
}
基本上,\rem
用于指示已被删除的内容,并\remb
用于删除无法删除的代码块\rem
,典型用法(有效):
% Code that works
\remb[2]{ % In revision 2, the whole list was removed.
\begin{itemize}
\item \rem[2]{A}
\remb[1]{ % In revision 1, the two last items were removed.
\item \rem[1]{B}
\item \rem[1]{C}
}
\end{itemize}
}
我想在align
环境中使用上述方法删除部分方程式,但是它不起作用:
\begin{subequations}
\begin{align}
\remb{A & B\\} % Small code that does not work
& G
\end{align}
\end{subequations}
\begin{subequations} % "Complete" code
\begin{align}
\remb{
\rem{A} & \rem{B}\\
\rem{C}
} & D\\
\remb{
& \rem{E}\\
& \rem{F}\\
}
& G
\end{align}
\end{subequations}
如果and宏中没有\ifdefined
and (例如通过条件定义宏),它也可以工作。有没有办法让它在有条件语句的情况下工作?\ifnum
\rem
\remb
使用上述代码时出现错误:
! Incomplete \ifnum; all text was ignored after line 51.
<inserted text>
\fi
l.51 \end{align}
完整代码:
\documentclass{article}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
% Works only if revision is 1
\def\revision{2}
\newcommand\remb[2][1]{
\ifdefined\revision
\ifnum\revision=#1 #2\fi
\ifnum\revision<#1 #2\fi
\fi
}
\begin{document}
\begin{subequations}
\begin{align}
\remb{A & B\\}
& G
\end{align}
\end{subequations}
\end{document}
答案1
在条件语句中以这种方式使用条件总是有风险的并且通常不起作用,因为条件语句不能跨越单元格。
隐藏条件直到最后一刻。
\documentclass{article}
\usepackage{amsmath,amsthm,amsfonts,amssymb}
\makeatletter
\newcommand{\revisionTF}[2]{%
\ifdefined\revision
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#1}{#2}%
}
\newcommand{\revisionT}[1]{\revisionTF{#1}{}}
\newcommand{\revisionF}[1]{\revisionTF{}{#1}}
\newcommand{\revisioncompareTF}[3]{%
\ifnum\revision#1\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{#2}{#3}%
}
\newcommand\remb[2][1]{%
\revisionTF
{%
\revisioncompareTF{=#1}
{EQUAL #2}
{\revisioncompareTF{<#1}{LESS #2}{}%
}%
}%
{NO REV}
}
\begin{document}
Revision is undefined:
\begin{align}
\remb{A & B\\}
& G
\end{align}
\def\revision{1}
Revision is 1:
\begin{align}
\remb{A & B\\}
& G
\end{align}
\def\revision{2}
Revision is 2:
\begin{align}
\remb{A & B\\}
& G
\end{align}
\def\revision{2}
Revision is 2:
\begin{align}
\remb[3]{A & B\\}
& G
\end{align}
\end{document}