GeneralHow to display the box of each latex object on the output?

General information and discussion about TeXnicCenter
Post Reply
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

How to display the box of each latex object on the output?

Post by yoyoimut »

hi everyone,

Is it possible to display the box enclosing each latex object on the output?

For example, I have a word "LaTeX" in the input file.
On the output file, each character in the word must be enclosed by a visible box.
Of course I don't want to enclose each character with a \fbox.



You can use the following minimal code:

Code: Select all

\documentclass[a4paper]{article}
\usepackage{amsmath}
\pagestyle{empty}
\begin{document}
\setlength{\fboxsep}{0.3pt}
\setlength{\fboxrule}{0.01pt}
\fbox{\LaTeXe}
\end{document}

Thank you in advance.



Yuko.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to display the box of each latex object on the output?

Post by gmedina »

Try the \demobox macro from Knuth's TeXbook:

Code: Select all

\documentclass{article}

\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{\setbox0=\hbox{\dolist#1\endlist}%
  \leavevmode\copy0\kern-\wd0\makelightbox}

\begin{document}

\demobox{LaTeX}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

Re: How to display the box of each latex object on the outpu

Post by yoyoimut »

Thanks Gmedina for the nice code.

regards,


Yuko
Post Reply