3

Following-up my previous question, I would like to make the command \chickenize:

  1. apply the draft option of graphicx

  2. convert every word such as Question 1, the text inside the table, super and sub into a dummy one.

enter image description here

\documentclass{exam}
\usepackage{luacode}
\usepackage{graphicx}
\usepackage{chickenize}
\begin{luacode*}
    chickenizefraction = 100000
    chickenstring[1] = "xxxx"
    chickenstring[2] = "x"
    chickenstring[3] = "xx"
    chickenstring[4] = "xxxxx"
\end{luacode*}

\qformat{Question \thequestion\hfill}

\begin{document}

\chickenize

\begin{questions}
    \question[7] 
    some  text  to be replaced by a dummy one \textsuperscript{super} \textsubscript{sub}. 

    \includegraphics[width=0.25\linewidth]{example-image}\vspace{\baselineskip}

    \begin{tabular}{c}
    \hline
    some text\\
    another text\\
    \hline
\end{tabular}
\end{questions}
\end{document}

Update 1

Considering the suggestion in Therese's comment that refers to this question, the following approach (using a conditional \ifPublicPrinter) needs to:

  1. transform all the math text/symbols/numbers

  2. remove the printed path of the draft image

enter image description here

\newif\ifPublicPrinter
\PublicPrintertrue

\ifPublicPrinter
\PassOptionsToPackage{draft}{graphicx}
\fi

\documentclass[addpoints]{exam}
\usepackage{luacode,fontspec}
\usepackage{graphicx}
\usepackage{unicode-math,siunitx}

\ifPublicPrinter
\setmainfont{redacted-script-regular.ttf}
\setmathfont{redacted-script-regular.ttf}
\fi

\qformat{Question \thequestion\ (\totalpoints)\hfill}

\begin{document}

    \begin{questions}
        \question[7] 
        some  text  to be replaced by a dummy one \textsuperscript{super} \textsubscript{sub}. 

        \includegraphics[width=0.25\linewidth]{example-image}\vspace{\baselineskip}

        \underline{$\symbf{\Delta V \leq 5}~ \si{\kilo\m\per\hour}$}

        \[\num{-8e-06}~N_e^2 +  {0.072}~N_e - \beta\]

        \begin{tabular}{c}
            \hline
            some text\\
            another text\\
            \hline
        \end{tabular}
    \end{questions}
\end{document}
5
  • Do any of the options at tex.stackexchange.com/q/266775 help you?
    – Thérèse
    Feb 8, 2020 at 13:58
  • @Thérèse I think it will help, but could you please provide an answer with a single command that transforms both the text and the images simultaneously?
    – Diaa
    Feb 8, 2020 at 15:21
  • @Thérèse Please, consider my last question update.
    – Diaa
    Feb 8, 2020 at 17:18
  • Idea: Switch to an exotic or foreign font, that does not make sense in this context. Feb 18, 2020 at 0:07
  • @Dr.ManuelKuehner that's what I exactly did in my question update. However, I can't make it work perfectly everywhere.
    – Diaa
    Feb 18, 2020 at 4:49

3 Answers 3

4
+50

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}

enter image description here


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}

enter image description here


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

4
  • I aim to have a dummy output while keeping the same page format and layout by only converting the real text and images into dummy ones via a single command (e.g. \chickenize or setting \ifPublicPrinter to true). So, I would be grateful if there is an easier approach to "dummify" the document without having to enclose every single macro/environment with |.
    – Diaa
    Feb 18, 2020 at 6:51
  • @Diaa One problem would be how to differentiate \begin{tabular}, which you would not want to chickenize, from \textit{italic text}, which you would like to chickenize. I can easily turn off the chickenizing of arguments, but that would then overlook the latter case. In addition, optional arguments would still be a problem, as the use of [...] syntax may or may not imply an optional argument, and there is no trivial way I can trap [...] in the same way I can easily trap {...}. Further, my technique would break hyphenization, and so the layout could change. Feb 18, 2020 at 10:49
  • I understand. On the other side, for my question update #1, could you suggest me how to implement alfC's answer in it using lualatex with unicode-math?
    – Diaa
    Feb 18, 2020 at 13:56
  • @Diaa While I am not a lualatex user myself, the approach I provide works just fine in lua, and with unicode-math, I believe. Thus, you could perhaps merge the two answers to better achieve what you are looking for. I will also edit my answer to give some guidance about not processing group content. Feb 18, 2020 at 15:03
1

In your Update, to apply the font to all the math text/symbols/numbers you can add the following setmathfont commands:

\ifPublicPrinter
\setmainfont{redacted-script-regular.ttf}
\setmathfont{redacted-script-regular.ttf}
\setmathfont[range=\mathup/{num}]{redacted-script-regular.ttf}
\setmathfont[range=\mathrm]{redacted-script-regular.ttf}
\setmathfont[range=\mathit]{redacted-script-light.ttf}
\setmathfont[range=\mathbf]{redacted-script-bold.ttf}
\setmathfont[range={"2032}]{redacted-script-regular.ttf}
\fi
1
  • Applying your code, this document doesn't compile and gives errors when compiling using lualatex.
    – Diaa
    Feb 9, 2020 at 17:53
1

Thanks to Steven's inspiring answer, the following is exactly what I need:

enter image description here

\newif\ifPublicPrinter
\PublicPrintertrue

\ifPublicPrinter
\PassOptionsToPackage{draft}{graphicx}
\fi

\documentclass[addpoints]{exam}
\usepackage{luacode,fontspec}
\usepackage{graphicx}
\usepackage{unicode-math,siunitx}

\ifPublicPrinter
\setmainfont{redacted-script-regular.ttf}
\setmathfont{Cambria Math}

\setmathfont{redacted-script-regular.ttf}%
[range = {up , it , bb , bbit , scr , cal , bfcal , frak , tt , sfup ,
    sfit , bfup , bfit , bfscr , bffrak , bfsfup , bfsfit, {"002B}, {"002D}, {"2796}, {"207B}}]

\let\svincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{\svincludegraphics[#1]{example-image}}
\fi

\qformat{Question \thequestion\ (\totalpoints)\hfill}

\begin{document}

    \begin{questions}
        \question[7] 
        some  text  to be replaced by a dummy one \textsuperscript{super} \textsubscript{sub}. 

        \includegraphics[width=0.25\linewidth]{example-image}\vspace{\baselineskip}

        \underline{$\symbf{\Delta V \leq 5}~ \si{\kilo\m\per\hour}$}

        \[\num{-8e-06}~N_e^2 +  {0.072}~N_e - \beta\]

        \begin{tabular}{c}
            \hline
            some text\\
            another text\\
            \hline
        \end{tabular}
    \end{questions}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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