0

The title is not that descriptive. I try to write a custom remark-style amsthm environment which can take arguments as the header (I don't need referencing functionalities). I wanted to simplify the code by avoiding trivlist. remark-style theorem environments have .5\topsep space before and after the environment. But this looks really weird in list environments like itemize. Here is what I have:

\documentclass{article}
\usepackage{lipsum} % for testing

% paragraph environment, takes one mandatory header text
\newenvironment{para}[1]{
    % add space before environment
    \par\addvspace{.5\topsep}
    % header text 
    \noindent\textit{#1.}%
    % default rubber space after header text and ignore following spaces
    \hspace*{5pt plus 1pt minus 1pt}\ignorespaces
}{
    % add space after environment
    \par\addvspace{.5\topsep}
}

\begin{document}

\lipsum[66]

\begin{para}{Looks good}
    \lipsum[66]
\end{para}

\lipsum[66]

\begin{itemize}
    \item \lipsum[66]

        Compare \verb|\parsep| above and the \verb|\parsep+.5\topsep| below.

        \begin{para}{Looks weird}
            \lipsum[66]
        \end{para}

        \lipsum[66]
\end{itemize}

\end{document}

As you can see, in list environments, the .5\topsep is added to the non-zero \parsep, creating a bigger gap. The original amsthm environments avoid this by employing Latex' mechanisms for lists (setting \@topsep and \@topsepadd to the desired spacing of .5\topsep). Similarly, I would much rather prefer to add no space at all if para is called inside list environments. Is there a way to detect whether one is in a list environment? Or is there a more elegant solution?


Edit: Added picture of compiled file.

enter image description here

3
  • @DavidCarlisle You might be write with the convetion of \parsep and \topsep, but, first of all, I don't use \parsep or \parskip in my definition of para. Moreover, latexdef -c article topsep gives me 8pt plus 2pt minus 4pt, and amsthm.sty also uses \topsep it it's definition. For clarification, I added a picture.
    – Gargantuar
    Commented Dec 30, 2023 at 23:41
  • sorry I misread you using \parsep but the same is true of \topsep you should not use it here. amsthm uses it but amsthm theorem envionments are (like standard theorem environments) a one-item list so you can use list parameters to style them, Using \topsep as here out of a list is wrong. article (actualy size10.clo) does not set topsep globally it sets it separately for each list nest level, the value you show is part of \@listi for first level lists Commented Dec 31, 2023 at 1:09
  • For the specific question of testing for whether you are in a list or not: check the value of \@listdepth; 0 is outside of lists. Commented Dec 31, 2023 at 1:42

1 Answer 1

0

As David Carlisle said, you shouldn't use \topsep to define your environment, since it is set and reset by list environments and your environment will not give a consistent behavior (since it depends on a length that is frequently changed on the fly). You probably want to hard code a value (make it a glue if you want, but I'll just take 4pt as that seems to be the desired amount).

To handle the effect of \parskip which may or may not be present (in a list environment, \parskip is set to be equal to \parsep), you can just cancel it by adding an additional vspace. The following will probably do what you want:

\documentclass{article}
\usepackage{lipsum} % for testing

% paragraph environment, takes one mandatory header text
\newenvironment{para}[1]{
    % add space before environment
    \par\addvspace{4pt}\addvspace{-\parskip}
    % header text 
    \noindent\textit{#1.}%
    % default rubber space after header text and ignore following spaces
    \hspace*{5pt plus 1pt minus 1pt}\ignorespaces
}{
    % add space after environment
    \par\addvspace{4pt}\addvspace{-\parskip}
}

\begin{document}

\lipsum[66]

\begin{para}{Looks good}
    \lipsum[66]
\end{para}

\lipsum[66]

\begin{itemize}
    \item \lipsum[66]

        Compare \verb|\parsep| above and the \verb|\parsep+.5\topsep| below.

        \begin{para}{Looks weird}
            \lipsum[66]
        \end{para}

        \lipsum[66]
\end{itemize}

\end{document}

enter image description here

You must log in to answer this question.

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