0

EDIT:Fix the typo in the original code

I try to define a new environment called revisions, which is like enumerate, but accept 1 optional parameter and 2 other parameters for \item command. The main part of the code is following:

\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}}

and a test MME looks like:

\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}

The expected out put will looks like:

  1. Page 1: The referree's comments
    Response of the authors
  2. The referree's comments 2
    Response of the authors 2
    a. The item for response
    b. goes here
  3. The referee's comments 3
    with line break
    Response of the authors 3
    with line break

Something more...

QUESTION

The problem is that, although I have add + in the g tag of xparse option parameter, which, from the official's doc, can have line break of the last two parameters, but in the real test, it's just not work. Any ideas?

5
  • 1
    Why don't you make a real minimal example that can be compiled directly? Mar 29, 2018 at 7:12
  • To compile, just copy the definition of the environment(the first code block) and past it at the position marked by % the definition goes here. I want to split the code, because it seems more clear to the reader, what is the key part of the code.
    – user19832
    Mar 29, 2018 at 7:22
  • 2
    I know what I have to do to compile the code (including correcting the wrong command in your code part) -- check my reputation if you don't believe me. But why should I do the work when you can offer a complete document directly? Mar 29, 2018 at 7:24
  • @user19832: It is not our job to provide compilable examples and glueing fragments together -- you're the user that wants the help
    – user31729
    Mar 29, 2018 at 8:22
  • @UlrikeFischer Sorry about the typo, I have fixed it now.
    – user19832
    Mar 29, 2018 at 9:24

1 Answer 1

1

Since the error is Paragraph ended before \text@command was complete. }, I just changed the \IfNoValueF{##3}{\par\textit{\ignorespaces##3}} by \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}
2
  • It works, but why? \textit can't include empty line?
    – user19832
    Mar 29, 2018 at 13:31
  • This last answer is too TeXnical for me :)
    – NBur
    Mar 29, 2018 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .