It is not fully clear the extent and purpose of your desired output, so I take a stab and will await feedback on what you really want.
What I do here is replace every catcode 11 token with example-image
that is stretched and scaled to take up the same footprint as the original letter.
As to figures, I redefine \includegraphics
to always output a generic image, rather than that which was specified.
Note that certain types of text need to be escaped between |
delimiters, to avoid the substitution, such as environment names and macro arguments. That is up to the user to make sure of.
\documentclass{exam}
\usepackage{tokcycle,graphicx}
\tokcycleenvironment\chickenize
{\tctestifcatnx a##1{%
\setbox0=\hbox{##1}%
\edef\tmp{[width=\the\wd0, height=\the\dimexpr\ht0+\dp0\relax]}%
\addcytoks[1]{\expandafter\raisebox\expandafter{\expandafter-\the\dp0}}%
\addcytoks[1]{\expandafter{%
\expandafter\includegraphics\tmp{example-image-a}}}}{%
\addcytoks{##1}}}
{\processtoks{##1}}
{\addcytoks{##1}}
{\addcytoks{##1}}
\let\svincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{\svincludegraphics[#1]{example-image-c}}
\begin{document}
\chickenize
This is a \textit{test} of descenders yig.
Of a substitute font with math:
|\hspace{.5in}|$y = mx^{2x} + b_{a}$
|\begin{questions}|
\question[7]
some text to be replaced by a dummy one \textsuperscript{super} \textsubscript{sub}.
|\includegraphics[width=0.25\linewidth]{example-image-a}|%
\vspace{\baselineskip}
|\begin{tabular}{c}|
\hline
some text\\
another text\\
\hline
|\end{tabular}|
|\end{questions}|
\endchickenize
\end{document}

If you wanted the output to be text rather than scaled images, here I simply replace every catcode 11 token with an x
. Additionally, I convert every numerical digit to a 0
, while leaving all other punctuation as is.
\documentclass{exam}
\usepackage{tokcycle,graphicx}
\tokcycleenvironment\chickenize
{\tctestifcatnx a##1{%
\addcytoks{x}}{%
\tctestifnum{`##1>`/}{\tctestifnum{`##1<`:}{%
\addcytoks{0}}{\addcytoks{##1}}}{\addcytoks{##1}}}}
{\processtoks{##1}}
{\addcytoks{##1}}
{\addcytoks{##1}}
\let\svincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{\svincludegraphics[#1]{example-image-c}}
\begin{document}
\chickenize
This is a \textit{test} of descenders yig.
Of a substitute font with math:
|\hspace{.5in}|$y = mx^{2x} + b_{5}$
|\begin{questions}|
\question[7]
some text to be replaced by a dummy one \textsuperscript{super} \textsubscript{sub}.
|\includegraphics[width=0.25\linewidth]{example-image-a}|%
\vspace{\baselineskip}
|\begin{tabular}{c}|
\hline
some text\\
another text\\
\hline
|\end{tabular}|
|\end{questions}|
\endchickenize
\end{document}

In comments, the OP was not happy over the notion of having to escape many macro arguments. The problem, of course, is that some macro arguments, like \begin{tabular}
, you don't want to \chickenize
, whereas some, like \textit{test}
, you do. In the end, the user must decide how to proceed, but below I offer an alternative, in which all group content is explicitly omitted from chickenization. Thus, one no longer has to escape \begin{tabular}
, for example.
However, optional macro arguments, delimited with [...]
must still be escaped (such as the \includegraphics
option in the MWE below). Further, if one wishes to selectively, chickenize a macro argument, then it must be re-invoked via nesting (as in the case of \textit{\chickenize test\endchickenize}
).
\documentclass{exam}
\usepackage{tokcycle,graphicx}
\tokcycleenvironment\chickenize
{\tctestifcatnx a##1{%
\addcytoks{x}}{%
\tctestifnum{`##1>`/}{\tctestifnum{`##1<`:}{%
\addcytoks{0}}{\addcytoks{##1}}}{\addcytoks{##1}}}}
{\addcytoks{##1}}
{\addcytoks{##1}}
{\addcytoks{##1}}
\let\svincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{\svincludegraphics[#1]{example-image-c}}
\begin{document}
\chickenize
This is a \textit{\chickenize test\endchickenize} of descenders yig.
Of a substitute font with math:
\hspace{.5in}$y = mx^{\chickenize2x\endchickenize} + b_{\chickenize5\endchickenize}$
\begin{questions}
\question[7]
some text to be replaced by a dummy one \textsuperscript{%
\chickenize super\endchickenize} \textsubscript{\chickenize sub\endchickenize}.
\includegraphics|[width=0.25\linewidth]|{example-image-a}%
\vspace{\baselineskip}
\begin{tabular}{c}
\hline
some text\\
another text\\
\hline
\end{tabular}
\end{questions}
\endchickenize
\end{document}
p.s. For another related answer using this (tokcycle
) package, in the event that you wish to replace each letter with a different letter: LaTeX Uglifier / obfuscator