# How to show only the TeX boxes [duplicate]

This question already has an answer here:

I'd like to use a sequence of boxes to show how TeX works. I read some time ago that everything (or almost) in TeX are boxes.

So, how to show only the TeX boxes that surround each character, each line, each paragraph?

I'd like something similar to the image below, not fbox which contains blank space around it.

## marked as duplicate by Werner, Guido, Heiko Oberdiek, Thorsten, lockstepJul 6 '13 at 7:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Isn't there a separation length for fbox? – Sean Allred Jul 6 '13 at 0:34
• There is \fboxsep but I'll need to use \fbox around every character. – Sigur Jul 6 '13 at 0:38
• That can probably be arranged via a recursive solution. I do wish I had my computer these days... – Sean Allred Jul 6 '13 at 0:47
• There is probably a smarter way though. – Sean Allred Jul 6 '13 at 0:47
• For an inspiration, you can see Exercise 11.5 in Chapter 11 Boxes (page 67) of the TeXbook and its solution in Appendix A, pages 310-311. There, Knuth defines a \demobox command. – Gonzalo Medina Jul 6 '13 at 4:03

## 2 Answers

In Exercise 11.5 (Chapter 11 Boxes) on page 67 of the TeXbook Knuth proposes the definition of a \demobox command; in Appendix A, pages 310-311, Knuth presents the solution. The solution is not complete for the problem presented in this question (macros and accented characters, for example, don't behave as expected), but it's an interesting code and valid as a partial answer. Since I simply transcribe it here, I make this answer CW with all credit to D.E. Knuth:

\documentclass{article}
\usepackage[utf8]{inputenc}

\def\dolist{\afterassignment\dodolist\let\next= }
\def\dodolist{\ifx\next\endlist \let\next\relax
\else \\\let\next\dolist \fi
\next}
\def\endlist{\endlist}
\def\hidehrule#1#2{\kern-#1%
\hrule height#1 depth#2 \kern-#2 }
\def\hidevrule#1#2{\kern-#1{\dimen0=#1
\advance\dimen0 by#2\vrule width\dimen0}\kern-#2 }
\def\makeblankbox#1#2{\hbox{\lower\dp0\vbox{\hidehrule{#1}{#2}%
\kern-#1 % overlap the rules at the corners
\hbox to \wd0{\hidevrule{#1}{#2}%
\raise\ht0\vbox to #1{}% set the vrule height
\lower\dp0\vtop to #1{}% set the vrule depth
\hfil\hidevrule{#2}{#1}}%
\kern-#1\hidehrule{#2}{#1}}}}
\def\maketypebox{\makeblankbox{0pt}{1pt}}
\def\makelightbox{\makeblankbox{.2pt}{.2pt}}
\def\\{\if\space\next\ % assume that \next is unexpandable
\else \setbox0=\hbox{\next}\maketypebox\fi}
\def\demobox#1{#1~\setbox0=\hbox{\dolist#1\endlist}%
\leavevmode\copy0\kern-\wd0\makelightbox\par}

\begin{document}

\demobox{Test}
\demobox{Some Other Words}
\demobox{\TeX :-(}% doesn't produce the desired result
%\demobox{Céfiro}% fails

\end{document}


I dont think this is a perfect solution for the question. Since, the question seems to be interesting, one way to achieve it manually:

\documentclass{article}

\begin{document}
\parindent=0pt

\makeatletter
\def\boxit#1{%
\fboxsep=0pt%
\fboxrule=.1pt%
\@tfor\xx:=#1\do{%
\fbox{\phantom{\xx}}%
} #1%
}

\boxit{Grupa}\\
\boxit{U{\.z}ytkownik{\'o}w}\\
\boxit{Systemu}\\
\boxit{\TeX}  %This wont work ;-(

\end{document}


Here, if we pass macros, then it will, for example \boxit{\TeX} will appear in single box rather than in three boxes. Also, for accented characters we need to group it like {\'a} or {\'{a}}. Another problem is that, we need to put the box manually.