1

The command \descitem below allows an item in an enumerate list to include a description. (Sorry, I cannot find the source of that definition now at tex.stackexchange.) The idea is to allow an optional argument to items in an enumerate list similar to the way one has optional arguments to a theorem or theorem-like environment with amsthm.

After an ordinary \item, a blank line does not immdiately start a new paragraph. Good!

But after a \descitem, a blank line unfortunately does cause a new paragraph to start. Bad! How can this be fixed?

\documentclass{memoir}
\usepackage{enumitem}

\newlist{penum}{enumerate}{2}
\setlist[penum,1]{%
  label= \sffamily\upshape(\arabic*),
  ref={\arabic*}, 
  widest=99,
}
\newcommand\descitem[1][]{\item{\sffamily\MakeUppercase#1. }}

\begin{document}
\begin{penum}

\item

An ordinary item: no new paragraph printed, despite preceding blank line.

\descitem[number two]

An item with a description: blank line causes new paragraph.

\descitem[three]
\label{it:three}

A labeled item with a description: ditto.
 
\end{penum}
\end{document}

enumerate with description

Thus, I'm trying to make the behavior of \descitem the same as \item in this regard: a blank line after the line with the command not creating a new paragraph. So I'm asking how to modify \descitem so as to not to into vertical mode there.

The situation is akin to that with an optional argument to a theorem environment: after \begin{theorem}[something-about-it] a blank line immediately following does not cause a new paragraph to begin.

Why don't I simply avoid the blank line? Because having the blank line after a \descitem[...], like having one after an ordinary \item, makes it much easier to locate items when I'm rewriting or editing source.

11
  • 2
    Don't insert a blank line between\item and the text.
    – Skillmon
    Commented Oct 18, 2023 at 18:23
  • Your \descitem doesn't provide its optional argument as an argument for \item, but as text that should be put there, so naturally after you started a paragraph a \par (or blank line) will start a new paragraph.
    – Skillmon
    Commented Oct 18, 2023 at 18:24
  • I"m trying to make the behavior of \descitem the same as \item in this regard: a blank line after the line with the command not creating a new paragraph. So I'm asking how to modify \descitem so as to not to into vertical mode there.
    – murray
    Commented Oct 18, 2023 at 19:21
  • \@ifnextchar\par{\@gobble}{} could work.
    – Skillmon
    Commented Oct 18, 2023 at 19:46
  • @Skillmon: Alas, that simple fix does not work when there is also a \label, as in the 3rd item I showed.
    – murray
    Commented Oct 18, 2023 at 19:56

2 Answers 2

4

I suggest an obscure solution. We measure the width of the \descitem parameter, then we leave the horizontal mode and return to the vertical mode. The first letter of the next text opens horizontal mode again. The \everypar moves the text to the appropriate horizontal position and the negative \vskips move it to the appropriate vertical position.

\def\descitem[#1]{\par
   \setbox0=\hbox{\sffamily\MakeUppercase#1. }
   \item{\sffamily\MakeUppercase#1. }\par
   \everypar={\hskip\wd0 \everypar={}}
   \nobreak\vskip-\parskip \vskip-\baselineskip
}
0
2

I'd still not recommend doing this, but the following implements the \gobblepar macro from my earlier comment.

\documentclass{memoir}
\usepackage{enumitem}

\makeatletter
\newcommand\gobblepar
  {\@ifnextchar\label{\gobblepar@label}{\@ifnextchar\par{\@gobble}{}}}
\newcommand\gobblepar@label[2]{\label{#2}\gobblepar}
\makeatother

\newlist{penum}{enumerate}{2}
\setlist[penum,1]{%
  label= \sffamily\upshape(\arabic*),
  ref={\arabic*}, 
  widest=99,
}
\newcommand\descitem[1][]{\item{\sffamily\MakeUppercase#1. }\gobblepar}

\begin{document}
\begin{penum}

\item

An ordinary item: no new paragraph printed, despite preceding blank line.

\descitem[number two]

An item with a description: blank line causes new paragraph.

\descitem[three]
\label{it:three}

A labeled item with a description: ditto.
 
\end{penum}
\end{document}

enter image description here

2
  • After the "number two" \descitem and :An item with a description: blank line...." insert an ordinary item: \item [blank line] \textsf{Number two.} An item with a description. and now you'll see, by comparision, there is extra horizontal space after "Number two" in the \descitem
    – murray
    Commented Oct 23, 2023 at 22:04
  • @murray that's the bigger spacefactor after the period that gets additionally stretched because the line is borderline short. If you use a control space after the period instead of a normal space you'll get normal spacing if that's what you're after. Also if you use \descitem{Number two} An item with a description. you'll get the same spacing as in your \item usage. Your line doesn't need stretching, unlike the line with : blank line causes new paragraph. after it.
    – Skillmon
    Commented Oct 24, 2023 at 6:42

You must log in to answer this question.

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