3

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

Sigur
  • 37,330

2 Answers2

7

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}

enter image description here

Gonzalo Medina
  • 505,128
2

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.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Jagath
  • 4,287