重新定义项目环境命令不能有空行

重新定义项目环境命令不能有空行

编辑:修复原代码中的拼写错误

我尝试定义一个名为 的新环境revisions,它类似于枚举,但接受 1 个可选参数和 2 个其他\item命令参数。代码的主要部分如下:

\usepackage{xparse}
\usepackage{enumitem}
\newlist{ritem}{enumerate}{2}
\setlist[ritem, 1]{label=\arabic*., ref=\arabic*}
\setlist[ritem, 2]{label=\arabic{ritemi}.\alph*, ref=\arabic{enumi}.\alph*, before=\raggedright}
\setlist[enumerate,1]{label=\alph*., ref=\alph*}

\newenvironment{revisions}[1][]{
  \begin{ritem}[#1]
    \let\olditem\item %store \item into \olditem
    \RenewDocumentCommand{\item}{o +G{} +g}{
      \olditem\leavevmode %call \olditem
      \IfNoValueF{##1}{\textbf{\ignorespaces##1}:~} %if item has options
      \ignorespaces##2
      \IfNoValueF{##3}{\par\textit{\ignorespaces##3}}
    }
}{\end{ritem}}

测试 MME 如下:

\documentclass{article}
% the definition goes here
\begin{document}
\begin{revisions}
\item[Page 1]{
    The referee's comments
}{
    Response of the authors
}
\item{
    The referee's comments 2
}{
    Response of the authors 2
    %I have to use ritem for nested item
    \begin{enumerate}
      \item The item for response
      \item goes here
    \end{enumerate}
}
% the following code does not work
% since it contains empty lines
%\item{
%    The referee's comment 3
%    
%    with line break
%}{
%    Response of the authors 3
%    
%    with line break
%    
%}
\end{revisions}
Something more...
\end{document}

预期输出将如下所示:

  1. 第 1 页:裁判的评论
    作者的回应
  2. 裁判评论2
    作者的回应 2
    A。响应项目
    b.到此处
  3. 裁判员评语 3
    (带换行符)
    作者的回应 3
    带有换行符

还有更多...

问题

问题是,虽然我添加了选项参数的标签+,根据官方文档,最后两个参数可以换行,但在实际测试中,它不起作用。有什么想法吗?gxparse

答案1

由于错误Paragraph ended before \text@command was complete. },我只是将\IfNoValueF{##3}{\par\textit{\ignorespaces##3}}其更改为\IfNoValueF{##3}{\par{\itshape\ignorespaces##3}}

\documentclass{article}

\usepackage{xparse}
\usepackage{enumitem}
\newlist{ritem}{enumerate}{2}
\setlist[ritem, 1]{label=\arabic*., ref=\arabic*}
\setlist[ritem, 2]{label=\arabic{ritemi}.\alph*, ref=\arabic{enumi}.\alph*, before=\raggedright}
\setlist[enumerate,1]{label=\alph*., ref=\alph*}

\newenvironment{revisions}[1][]{
    \begin{ritem}[#1]
        \let\olditem\item %store \item into \olditem
        \RenewDocumentCommand{\item}{o +G{} +g}{
            \olditem\leavevmode %call \olditem
            \IfNoValueF{##1}{\textbf{\ignorespaces##1}:~} %if item has options
            \ignorespaces##2
            \IfNoValueF{##3}{\par{\itshape\ignorespaces##3}}
        }
    }{\end{ritem}}

\begin{document}
\begin{revisions}
\item[Page 1]{
    The referee's comments
}{
    Response of the authors
}
\item{
    The referee's comments 2
}{
    Response of the authors 2
    %I have to use ritem for nested item
    \begin{enumerate}
      \item The item for response
      \item goes here
    \end{enumerate}
}
% the following code does not work
% since it contains empty lines
\item{
    The referee's comment 3

    with line break
}{
    Response of the authors 3

    with line break

}
\end{revisions}
Something more...
\end{document}

相关内容