# Text in squared box

I'd like to bot a square box around some text. I'd like to denote a labelled object of size 1, in combinatorics this is often symbolised by something like \boxed{1}. It would be nicer if the box was a square. Is there an adequate command for this?

-
So even if your text is not "square", you want to place a square box around it? – Werner Jan 26 '12 at 21:08
Short answer: yes. Long answer: You are right, that's a problem for beauty. But the square is used in graph theory for leaves of trees and I want to adopt this. – lumbric Jan 26 '12 at 21:22

Here a solution based on my collectbox package. This makes it support verbatim and other special text.

It doesn't change the baseline of the content, which is what you normally want.

\documentclass{article}

\usepackage{collectbox}

\makeatletter
\newcommand{\sqbox}{%
\collectbox{%
\@tempdima=\dimexpr\width-\totalheight\relax
\ifdim\@tempdima<\z@
\fbox{\hbox{\hspace{-.5\@tempdima}\BOXCONTENT\hspace{-.5\@tempdima}}}%
\else
\ht\collectedbox=\dimexpr\ht\collectedbox+.5\@tempdima\relax
\dp\collectedbox=\dimexpr\dp\collectedbox+.5\@tempdima\relax
\fbox{\BOXCONTENT}%
\fi
}%
}
\makeatother

\usepackage{graphicx}% just for the example text
\begin{document}

\stoptext


which gives

You can add a offset=<dimen> to the \defineframed command to have some offset between the text and the frame.

-