环境中的双符号默认参数。这是一个已知错误吗?

环境中的双符号默认参数。这是一个已知错误吗?

受@gernot在主题中的优雅回答启发而提出的问题 具有虚拟参数的环境

然而,进一步的实验得出了以下结论。确实,这到底是怎么回事?拿一个 @gernot 版本的look-environment 来看看。

\documentclass{article}
\begin{document}

\newenvironment{look}[1][\empty]%
{\begin{trivlist}\item[]\textsc{ThinkOut}% 
\ifx#1\empty\else\ (#1)\fi.\itshape}{\end{trivlist}}

\begin{verbatim}
\begin{look}[some addendum]
Text ...
\end{look}
\end{verbatim}
\begin{look}[some addendum]
Text ...
\end{look}

\begin{verbatim}
\begin{look}[q]
Seems allright? Look below ...
\end{look}
\end{verbatim}
\begin{look}[q]
Seems allright? Look below ...
\end{look}

\begin{verbatim}
\begin{look}[qq]
Double-q disappears. Where parentheses?
\end{look}
\end{verbatim}
\begin{look}[qq]
Double-q disappears. Where parentheses?
\end{look}

\begin{verbatim}
\begin{look}[aaa]
One of three a's survives; no ()'s do.
\end{look}
\end{verbatim}
\begin{look}[aaa]
One of three a's survives; no ()'s do.
\end{look}

\begin{verbatim}
\begin{look}[ qq]
Allright again.
\end{look}
\end{verbatim}
\begin{look}[ qq]
Allright again.
\end{look}

\begin{verbatim}
\begin{look}[{}aa]
Allright too.
\end{look}
\end{verbatim}
\begin{look}[{}aa]
Allright too.
\end{look}

\begin{verbatim}
\begin{look}[==]
Any double symbol disappears.
\end{look}
\end{verbatim}
\begin{look}[==]
Any double symbol disappears.
\end{look}

\end{document}

或者这可能是已知的 LaTeX 错误?

PS. 抱歉,我无法在此处下载 pdf 结果文件。

PPS。我的系统是(来自日志文件的信息)

e-TeX, Version 3.141592-2.1 (MiKTeX 2.3) (preloaded format=latex 2000.11.28)

LaTeX2e <2001/06/01> Document Class: article 2001/04/21 v1.4e

Standard LaTeX document class

答案1

没有任何错误:\begin{look}[qq]测试是

\ifx qq\empty

哪个明显地评估结果为真。

测试应该是

\ifx\empty#1\relax

但我更愿意

\newenvironment{look}[1][]
  {%
   \begin{trivlist}
   \item\relax\textsc{ThinkOut}% 
   \if\relax\detokenize{#1}\relax
   \else
     \ (#1)%
   \fi.
   \itshape
  }
  {\end{trivlist}}

发生了什么你的版本和\begin{look}[ab]

代码确实

\ifx ab\empty\else\ (ab)\fi

由于测试结果为假,因此将遵循假分支。如果你这样做\begin{look}[abcdefg],测试是

\ifx abcdefg\empty\else\ (abcdefg)\fi

c并且从到的标记\empty作为真实分支的一部分消失。如果你尝试\begin{look}[aabbcc],测试是

\ifx aabbcc\empty\else\ (aabbcc)\fi

你会得到bbcc 打印

相关内容