Suppressing whitespace at end of environment
Use \unskip
before the ]
in the closing part of the environment definition. This will eat up any space characters prior to the ]
.
EDIT to heed Barbara's comment to remove stray space following em-dash. And as she notes, one cannot have a blank line before \end{example}
without automatically introducing a paragraph break.
\documentclass{article}
\newenvironment{example}{[\textit{Example} ---}{\unskip]}
\begin{document}
\begin{example}
This is an example.
\end{example}
\end{document}
Furthermore, if you wish not to have the blank space after the closing ]
, you need \ignorespacesafterend
, as in
\documentclass{article}
\newenvironment{example}{[\textit{Example} ---}{\unskip]\ignorespacesafterend}
\begin{document}
\begin{example}
This is an example.
\end{example}
xxx
\end{document}
I'm not sure you really want an environment for this. However, you can (ab)use environ
.
\documentclass{article}
\usepackage{environ}
\NewEnviron{example}{%
[\textit{Example} --- \BODY]%
}
\begin{document}
\begin{example}
This is an example.
\end{example}
\end{document}