考试:如何根据需要用虚拟单词替换每个单词?

考试:如何根据需要用虚拟单词替换每个单词?

很多时候,我需要用公共打印机打印试卷以检查其格式和布局。但是,如果有一个开关可以将所有文本替换为虚拟文本,那么考试的保密性就不会受到侵犯,那就太好了。

为了完整性,如果长文本可以用长虚拟文本替换,短问题文本也可以用长虚拟文本替换,那就完美了。换句话说,替换需要以单词为单位进行。

\documentclass{exam}

\begin{document}
\begin{questions}
    \question[7] 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text.
    \begin{parts}
        \part[5] some text to be replaced by a dummy text
        \begin{subparts}
            \subpart[3] to be replaced by a dummy text
            \begin{subsubparts}
                \subsubpart[1] some question to be replaced by a dummy text
            \end{subsubparts}
        \end{subparts}
     \begin{choices}
        \choice a short text to be replaced by a short one.
     \end{choices}
    \end{parts}
\end{questions}
\end{document}

答案1

可以从这里调整一个强力(并且相当慢)的解决方案:如何进行多个字符串替换?

基本上,我定义了一个obfuscate环境,因此每个字母字符都被小写的 X 替换

\documentclass{exam}
\usepackage{xstring}
\usepackage{environ}
\def\obfuscatetext{0}
\newcommand{\xeverywhere}[2]{%
    \expandafter\StrSubstitute\expandafter{\BODY}{#1}{#2}[\BODY]%
}
\NewEnviron{obfuscate}{{%
\ifnum\obfuscatetext=1 
    \expandarg
    \StrSubstitute{\BODY}{a}{x}[\BODY]%
    \xeverywhere{b}{x}%
    \xeverywhere{c}{x}%
    \xeverywhere{d}{x}%
    \xeverywhere{e}{x}%
    \xeverywhere{f}{x}%
    \xeverywhere{g}{x}%
    \xeverywhere{h}{x}%
    \xeverywhere{i}{x}%
    \xeverywhere{j}{x}%
    \xeverywhere{k}{x}%
    \xeverywhere{l}{x}%
    \xeverywhere{m}{x}%
    \xeverywhere{n}{x}%
    \xeverywhere{o}{x}%
    \xeverywhere{p}{x}%
    \xeverywhere{q}{x}%
    \xeverywhere{r}{x}%
    \xeverywhere{s}{x}%
    \xeverywhere{t}{x}%
    \xeverywhere{u}{x}%
    \xeverywhere{v}{x}%
    \xeverywhere{w}{x}%
    \xeverywhere{y}{x}%
    \xeverywhere{z}{x}%
    \xeverywhere{A}{x}%
    \xeverywhere{B}{x}%
    \xeverywhere{C}{x}%
    \xeverywhere{D}{x}%
    \xeverywhere{E}{x}%
    \xeverywhere{F}{x}%
    \xeverywhere{G}{x}%
    \xeverywhere{H}{x}%
    \xeverywhere{I}{x}%
    \xeverywhere{J}{x}%
    \xeverywhere{K}{x}%
    \xeverywhere{L}{x}%
    \xeverywhere{M}{x}%
    \xeverywhere{N}{x}%
    \xeverywhere{O}{x}%
    \xeverywhere{P}{x}%
    \xeverywhere{Q}{x}%
    \xeverywhere{R}{x}%
    \xeverywhere{S}{x}%
    \xeverywhere{T}{x}%
    \xeverywhere{U}{x}%
    \xeverywhere{V}{x}%
    \xeverywhere{W}{x}%
    \xeverywhere{Y}{x}%
    \xeverywhere{X}{x}%
    \xeverywhere{Z}{x}%
    \BODY
\else 
    \BODY
\fi 
}}
\let\oldtextbf\textbf
\let\oldtextit\textit
\let\oldtexttt\texttt
\renewcommand{\textbf}[1]{\oldtextbf{\begin{obfuscate}#1\end{obfuscate}}}
\renewcommand{\textit}[1]{\oldtextit{\begin{obfuscate}#1\end{obfuscate}}}
\renewcommand{\texttt}[1]{\oldtexttt{\begin{obfuscate}#1\end{obfuscate}}}
\newcommand{\ObfuscateON}{%
\renewcommand{\obfuscatetext}{1}
}
\newcommand{\ObfuscateOFF}{%
    \renewcommand{\obfuscatetext}{0}
}
\ObfuscateON
\begin{document}
%If I want normal text, I just delete the next line:
\ObfuscateON
\begin{obfuscate}
\begin{questions}
    \question[7] 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text.
    \begin{parts}
        \part[5] some text to be replaced by a dummy text
        \begin{subparts}
            \subpart[3] to be replaced by a dummy text
            \begin{subsubparts}
                \subsubpart[1] some question to be replaced by a dummy text
            \end{subsubparts}
        \end{subparts}
     \begin{choices}
        \choice a short text to be replaced by a short one.
     \end{choices}
    \end{parts}
\end{questions}
\end{obfuscate}
\end{document}

在此处输入图片描述

可以添加数字和标点符号随意在定义中obfuscate

编辑:我添加了 \ObfuscateON 命令。默认情况下不执行任何操作,因此只有在使用 \ObfuscateON 时才会起作用。我还修补了、obfuscate的定义,因此可以正常工作。\textbf\textit\textttobfuscate

再次编辑:由于我的第一个解决方案有很多错误,所以我想出了一个不错的解决方案,使用lualatexchickenize可以避免与其他包发生冲突。至于图形,使用draft选项就足够了。

%!TEX program = lualatex
\documentclass{exam}
\usepackage{luacode}
\usepackage[draft]{graphicx}
\usepackage{chickenize}
\begin{luacode*}
    chickenizefraction = 100000
    chickenstring[1] = "ayyyy"
    chickenstring[2] = "lol"
    chickenstring[3] = "lmao"
    chickenstring[4] = "haha"
\end{luacode*}
\begin{document}
%Delete chickenize or use \unchickenize to get normal text
\chickenize
\begin{questions}
    \question[7] 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text. 
    some  very long question body to be replaced by a very long dummy text.
    \begin{parts}
        \part[5] some text to be replaced by a dummy text
        \begin{subparts}
            \subpart[3] to be replaced by a dummy text
            \begin{subsubparts}
                \subsubpart[1] some question to be replaced by a dummy text
            \end{subsubparts}
        \end{subparts}
     \begin{choices}
        \choice a short text to be replaced by a short one.
     \end{choices}
    \end{parts}
\end{questions}
\end{document}

一个真正更好的解决方案

相关内容