Como tratar listas como texto normal (em relação ao espaçamento vertical)?

Como tratar listas como texto normal (em relação ao espaçamento vertical)?

Contexto: Quero tratar listas (item, enumerar e descrição) como texto normal no que diz respeito ao espaçamento vertical. Nomeadamente:

  1. Se a lista iniciar um parágrafo, insira uma vertical \parskipde antemão — caso contrário, sem espaçamento vertical;
  2. Sem espaçamento vertical entre os itens da lista;
  3. Se a lista terminar em um parágrafo, insira uma vertical \parskipdepois - caso contrário, sem espaçamento vertical.

Utilizei notavelmente informações encontradas em\topsep, \itemsep, \partopsep e \parsep - o que significa cada um deles.

O requisito nº 1 é resolvido com \setlist{topsep=-\parskip,partopsep=\parskip}.

O requisito nº 2 é resolvido com \setlist{noitemsep}.

Problema: Restam dois problemas com o Requisito nº 3:

  • Um espaço vertical é adicionadodepoisa lista se esta iniciar um parágrafo, mesmo que esta lista sejaimediatamenteseguido de texto. (Ou seja, não existe parbottomsepcomprimento independente).
  • Se umnovoparágrafo começa após a lista, este parágrafonão éprecedido por um \parskip.

Pergunta: Como cumprir o Requisito nº 3?
(Atualmente uso patches manuais – veja MWE abaixo – mas é claro que não é satisfatório.)

insira a descrição da imagem aqui


MWE

\documentclass[parskip=half]{scrartcl}
    \usepackage{enumitem}
    \setlist{%
        topsep=-\parskip,
        partopsep=\parskip,
        noitemsep,
    }
\begin{document}
    This sentence is a paragraph on its own; there is thus a vertical parskip prior next paragraph.

    Following list is \emph{within} a paragraph, with preceding and appended text.
    \begin{itemize}
        \item One,
        \item Two,
        \begin{itemize}
            \item Two and a half;
            \item Almost three.
        \end{itemize}
        \item Three.
    \end{itemize}
    This text is appended to the previous list.
    However, following list starts a new paragraph on its own.

    \begin{enumerate}
        \item Did you notice the vertical spacing preceding this list?
        \item Two,
        \begin{enumerate}
            \item Two and a half;
            \item Almost three.
        \end{enumerate}
        \item Three.
    \end{enumerate}
%   \vspace{-\parskip}                                  %quick and dirty solution
    \textbf{There shouldn't be a vertical spacing here.}
    This text is appended to the previous list too.

    And finally, a list with preceding text only.
    \begin{itemize}
        \item One,
        \item Two,
        \begin{itemize}
            \item Two and a half;
            \item Almost three.
        \end{itemize}
        \item Three.
    \end{itemize}

%   \null\par                                            %quick and dirty solution
    \textbf{There should be a vertical spacing here.}
    This is a new paragraph.
    It should thus be preceded with parskip.
\end{document}

Responder1

Não é menos sujo, mas usa as ferramentas fornecidas por enumitem, brincando com a afterchave:

\documentclass[parskip=half]{scrartcl}
\usepackage{enumitem}
\setlist{%
    topsep=-\parskip,
    partopsep=\parskip,
    noitemsep,
}

\begin{document}

This sentence is a paragraph on its own; there is thus a vertical parskip prior next paragraph.

Following list is \emph{within} a paragraph, with preceding and appended text.
\begin{itemize}
    \item One,
    \item Two,
    \begin{itemize}
        \item Two and a half;
        \item Almost three.
    \end{itemize}
    \item Three.
\end{itemize}
This text is appended to the previous list.
However, following list starts a new paragraph on its own.

\begin{enumerate}[after =\vspace*{-\partopsep}]
    \item Did you notice the vertical spacing preceding this list?
    \item Two,
    \begin{enumerate}
        \item Two and a half;
        \item Almost three.
    \end{enumerate}
    \item Three.
\end{enumerate}
\textbf{There shouldn't be a vertical spacing here.}
This text is appended to the previous list too.

And finally, a list with preceding text only.
\begin{itemize}[after = \vspace*{\partopsep}]
    \item One,
    \item Two,
    \begin{itemize}
        \item Two and a half;
        \item Almost three.
    \end{itemize}
    \item Three.
\end{itemize}


\textbf{There should be a vertical spacing here.}
This is a new paragraph.
It should thus be preceded with parskip.

\end{document} 

insira a descrição da imagem aqui

Responder2

Aqui está uma solução possível usando lua para obter a próxima linha da fonte e verificar se ela está vazia. Claro, só funciona com lualatex. Pode ser necessário um pouco de refinamento para linhas quase vazias (apenas espaços?).

\documentclass{article}

\usepackage{luacode}
\begin{luacode*}
function manageNextLine(s)
  luatexbase.remove_from_callback("process_input_buffer", "manageNextLine")
  if s == "" then
    return "\\leavevmode\\par"
  else
    return s
  end
end
\end{luacode*}

\parskip=10ex  % to see it better

\usepackage{enumitem}
\setlist{noitemsep,
         topsep=-\parskip,
         partopsep=\parskip,
         after=\luadirect{luatexbase.add_to_callback("process_input_buffer", manageNextLine , "manageNextLine")}
  }



\begin{document}
Para

Para2
\begin{itemize}
\item 1
\item 2
\end{itemize}
%
Continuing the same para.

Para3
\begin{itemize}
\item A.
\item B.
\end{itemize}

Suite with vertical spacing.

\end{document}

informação relacionada