I have an environment that needs to ensure that its body always starts on a new line, but that doesn't add extra blank space when doing that.
What I have works well, except with a few corner cases relating to \paragraph{...} without any text between it and my environment.
\documentclass[12pt]{article}
\begin{document}
\newenvironment{foo}{
\par
}{
}
\section{Foo}
\begin{foo}
OK
\end{foo}
\paragraph{Bar} chart.
\begin{foo}
OK
\end{foo}
\paragraph{Baz}
\begin{foo}
Bad
\end{foo}
\end{document}
I can force that to start a new line by adding a ~\\ in the right spot, but that also adds a blank at the start of all the other uses that were correct.

\leavevmodein order to be the next text in a new paragraph. If TeX is in vertical mode already then next text begins a new paragraph and nothing more is needed (and\parsuggested by OP does nothing). If TeX is in horizontal mode then\leavevmodeis irrelevant.\parshould be sufficient. Why it doesn't in this case of LaTeX macro\paragraphis very interesting question. – wipet Oct 14 '23 at 12:23