texlive 2014 更新后 @ifnextchar 和 paralist 出现错误

texlive 2014 更新后 @ifnextchar 和 paralist 出现错误

我一直在使用保存/恢复TeX功能来let/def重新定义\@enumerate@来自帕拉利斯特包,以便enumerate环境可以接受第二个可选参数(自动创建的名称newcommand- 用于为以后的事件生成 s \label)。\item\ref

下面是一个 MWE 来说明这个问题。

\documentclass{report}

\usepackage[alwaysadjust,newitem,newenum]{paralist}
\usepackage{suffix,xkeyval,xargs,xifthen}

\makeatletter
\let\mwe@enumerate@\@enumerate@
\def\@enumerate@{\@ifnextchar[{\mwe@enum*{enumerate}[}%
                              {\mwe@enum{enumerate}}}

\newcommandx\mwe@enum[3][2,3=mwe@]{\csname#3#1@\endcsname}
%\newcommandx\mwe@enum[3][2,3=mwe@]{\@nameuse{#3#1@}}
\WithSuffix\newcommand\mwe@enum*[2][2]{\mwe@enum{#1}[\@gobble#2]}

\def\mwe{\@ifnextchar[{\mw@*{k}[}{\mw@{w}}}
\newcommandx\mw@[2][2=q]{#1 / #2\\}
\WithSuffix\newcommandx\mw@*[2][2]{\mw@{#1}[\@gobble#2]}

\makeatother

\title{MWE}
\author{tex.stackexchange.com}

\begin{document}

\maketitle

\noindent\mwe\mwe[x]

\iftrue
\begin{enumerate}[(1)][here]
\item test\label{here:1} % this would be auto-generated
\end{enumerate}
\fi

% further it would be possible to issue \here[1] instead of \ref{here:1}

\end{document}

带星号的\mwe@enum*是对未带星号的间接调用\mwe@enum,并将第二个\@gobble'd 参数传递给它。

虽然与验证命令\@ifnextchar配合得很好,但对于环境来说\@gobble\mweenumerate帕拉利斯特,如果方括号中的第二个参数(“here”)存在,则会出现错误:

! Missing number, treated as zero.
<to be read again> 
                   h
l.41     \item
               test
? h
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

本月初我已将 texlive 更新至 2014。之前,我的代码运行一切正常。现在看来帕拉利斯特2013 年至 2014 年间也进行了升级,从

          [2002/03/18 v2.3b Extended list environments (BS)]

          [2013/06/09 v2.4 Extended list environments]

但区别似乎仅仅在于错误的类型(2002):

! LaTeX Error: Lonely \item--perhaps a missing list environment.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.25 \item t
            est
? h
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

有一个替代包枚举项,但在这种情况下应该为用户保留一种选择。

感谢任何支持。

谢谢。

答案1

\@enumerate@当第一个可选参数已被吸收时,将执行该命令。 你想修补\enumerate,而不是:

\documentclass{report}

\usepackage[alwaysadjust,newitem,newenum]{paralist}

\makeatletter
\let\mwe@enumerate\enumerate
\def\enumerate{%
  \@ifnextchar[{\mwe@enumerate@aux}{\mwe@enumerate}%
}
\def\mwe@enumerate@aux[#1]{%
  \mwe@enumerate[#1]%
  \@ifnextchar[\mwe@getnext{}%
}
\def\mwe@getnext[#1]{%
  % probably something more useful will be here
  \typeout{***The second optional argument is #1***}%
}
\makeatother

\title{MWE}
\author{tex.stackexchange.com}

\begin{document}

\maketitle

\begin{enumerate}[(1)][here]
\item test\label{here:1} % this would be auto-generated
\end{enumerate}

\end{document}

相同之处xparse

\usepackage{xparse}
\let\savedenumerate\enumerate

\RenewDocumentCommand{\enumerate}{ o o }
 {
  \IfNoValueTF{#1}
   {\savedenumerate}
   {%
    \savedenumerate[#1]\IfValueT{#2}{\dosomething{#2}}
   }%
 }

\newcommand{\dosomething}[1]{%
  \typeout{***The second optional argument is #1***}%
}

相关内容