I would like to define a new environment that centers its contents if it can be typeset on a single line, but justifies the contents if it requires multiple lines.
\documentclass{article}
\usepackage{lipsum}
\newenvironment{mycenter}{\noindent}{}
\begin{document}
\begin{mycenter}%
This should be centered since it is a single line
\end{mycenter}
\begin{mycenter}%
This should be justified since it is multiple lines. \lipsum[1]
\end{mycenter}
\end{document}
I have a convoluted idea using the Environ package to capture the contents, then sticking them in a box and trying to check the height of the box. Is there an easier way?

\captionmacro does exactly this. It works, but it may be that you're bound to typeset things more than once. Therefore, you have to be careful if the contents includes counter stepping or perhaps labels. – Werner Feb 6 at 15:10\textwidthor\linewidth? – krlmlr Feb 6 at 15:40\textwidth, since setting it in a box doesn't have any text boundary and would require re-setting if wider than the text block. Thecaptionpackage apparently circumvents this. – Werner Feb 6 at 15:43environis what you're looking for. I'd measure the width, rather than the height. – egreg Feb 6 at 15:55