[Tex/LaTex] How to box every digit of an integer

formatting

What is the LaTeX command for boxing a number like for example 123 as:


|1|2|3|

I have seen it in a book but can't find it anywhere in TeXnicCenter, which I use.

Best Answer

I don't know any packages that provide macros for this, but it can be done easy enough:

\documentclass{article}


\newcommand*{\boxednumber}[1]{%
    \expandafter\readdigit\the\numexpr#1\relax\relax
}
\newcommand*{\readdigit}[1]{%
    \ifx\relax#1\else
        \boxeddigit{#1}%
        \expandafter\readdigit
    \fi
}
% Format macro used for every digit, adjust to your liking:
\newcommand*{\boxeddigit}[1]{\fbox{#1}\hspace{-\fboxrule}}

\begin{document}

\boxednumber{123}

\boxednumber{\thepage}

\end{document}

Image

See also Good way to make \textcircled numbers? for some tips about the formatting of the digits. However it's actual for circles not boxes.

Related Question