# How to define this new environment and avoid the hidden errors?

I want to define a new environment ends with a $\omega$ in newline. But environment like displaymath already start a newline after itself, so I do not start a newline in this case. That is, start a newline only after normal text but not environment. How to make it?

The original definition is as following which starts a newline after environment also.

\newenvironment{note}{%
\noindent
\textsc{Note}
\vskip\medskipamount % or other desired dimension
\leaders\vrule width \textwidth\vskip0.4pt % or other desired thickness
\vskip\medskipamount % ditto
\nointerlineskip
}{\mbox{}~\newline\mbox{} \hfill$\Omega$\newline}


As suggested by Peter Grill, I define a \smartsmallskip. And as suggested by David, I change the \newline to \par.

\def\smartsmallskip{\par
\ifdim\lastskip>0pt \else \smallskip\fi
}

\newenvironment{note}{%
\noindent
\textsc{Note}
\vskip\medskipamount % or other desired dimension
\leaders\vrule width \textwidth\vskip0.4pt % or other desired thickness
\vskip\medskipamount % ditto
\nointerlineskip
}{\smartsmallskip\hfill$\Omega$\par}


Is there still some question I should take care of?

• @PeterGrill Thanks! it does. Should I delete this post? – Eden Harder Feb 26 '14 at 2:02
• why \newline and the blank lines from\mbox{}~ rather than \par and vertical space? or better a definition using \newtheorem or similar? This version will have very strange behaviour near a page break. – David Carlisle Feb 26 '14 at 2:02
• it's better to use a list environment (as used by \newtheorem) as that takes care of things, as is, there is not control over the space before Note the page could break after the heading before the environment contents (or after the leaders) and the spacing between the rule and first line of text is going to be rather variable due to the \nointerlineskip (which means it will be different whether or not there is a capital letter or accent on the first line of content) the final \newline should be a \par (most likely). – David Carlisle Feb 26 '14 at 2:32
• @EdenHarder Don't forget that in LaTeX there is \addvspace, so \addvspace{\smallskipamount} is what you need instead of \smartsmallskip – egreg Feb 26 '14 at 7:54

## 1 Answer

This should do what you want; instead of a \smallskip before the last line, I have used a strut next to the Omega (actually, I think there shouldn't be an additional space and the symbol should go at the end of the last line). The line shouldn't be detached from the heading and the body thanks to \nopagebreak, the same for the last line.

\documentclass{article}
\usepackage{lipsum}

\newenvironment{note}
{\par\vspace{\topsep}%
\noindent\textsc{Note}\par\nopagebreak
\medskip
\hrule
\nopagebreak
\medskip}
{\par\skip0=\lastskip\nopagebreak
\hspace*{\fill}\mbox{\ifdim\skip0>0pt \else\rule{0pt}{2ex}\fi$\Omega$}\par
\vspace{\topsep}}
\begin{document}

\lipsum[1]

\begin{note}
\lipsum*[2]
\end{note}

\lipsum[3]

\end{document}


• Could you explain about \mbox{\ifdim\skip0>0pt \else\rule{0pt}{2ex}? Thanks a lot! – Eden Harder Feb 26 '14 at 12:22
• @EdenHarder That's for adding the strut only if the previous material doesn't end with a skip (such as after a math display). – egreg Feb 26 '14 at 12:45