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.

enter image description here

marked as duplicate by Werner, Guido, Heiko Oberdiek, Thorsten, lockstep Jul 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
  • 1
    There is probably a smarter way though. – Sean Allred Jul 6 '13 at 0:47
  • 1
    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

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:


\def\dolist{\afterassignment\dodolist\let\next= }
\def\dodolist{\ifx\next\endlist \let\next\relax
\else \\\let\next\dolist \fi
\hrule height#1 depth#2 \kern-#2 }
\advance\dimen0 by#2\vrule width\dimen0}\kern-#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
\def\\{\if\space\next\ % assume that \next is unexpandable
\else \setbox0=\hbox{\next}\maketypebox\fi}


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


enter image description here


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



   } #1%

\boxit{\TeX}  %This wont work ;-(


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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.