答案1
通常情况下,转变-like 命令,提供适用于文档其余部分的设置(直到发生更改),以及宏,它对参数进行操作。在至少一个引用的答案的情况下,\cthulhu
必须作为宏运行,因为它读取输入并对每个空格分隔的输入部分应用宏(旋转)转换。文本的随机旋转很难作为声明来实现。
尽管如此,我们仍可以通过多种方式来改善这种情况。
通过允许转换跨段落边界进行,可以一次性处理更大的输入。
通过提供对控制序列(宏等)、空格和组等内容的特殊处理,至少有希望解决更一般的 LaTeX 输入。在我将提供的答案中,我使用了一个标记循环,其中每个输入标记都会传递给各种指令进行处理。在这种方法中,构成字符、组、宏和空格的标记都可以应用不同的指令,这对于处理一般输入至关重要。
将流程从宏转变为环境。虽然仍需要终止,但流程已摆脱将所有内容封装在括号格式中的困难。
那么,现在介绍我的方法。在这里,我重新创建了所引用答案的克苏鲁效果,但使用标记循环将其概括化,以便可以跨段落处理更一般的内容。
我不得不稍微调整一下。我没有使用\@cthulhu
参考答案中提供的递归宏(它无法处理宏和宏参数的输入流),而是将其投射到一个tokcycle
环境中,在这个环境中,宏可以不受影响地传递,宏参数也可以逃脱通过用分隔符包围它们|
(看看我在 MWE 中多次这样做的方式)。
不幸的是,我发现aux
文件中的分段内容并不喜欢应用随机旋转,因此所有分段都必须提供逃脱可选参数,形式为\section|[blah]|{blah}
,这样 tocblah
就无需进行旋转操作。
使用 完成\cthulhu...\endcthulhu
。在伪环境之外,将恢复基线文档字体。
\documentclass[15pt]{extarticle}% This is a document class providing more font size options
\usepackage{tokcycle}[2021-03-10]
\usepackage[svgnames]{xcolor}
\usepackage{emerald}% font package
\usepackage[doublespacing]{setspace}% line spacing
\usepackage[T1]{fontenc}
\makeatletter
% \tc@defx is like \def, but expands the replacement text once prior to assignment
\newcommand\addtomacro[2]{\tc@defx#1{#1#2}}
\makeatother
\newcommand\dumpword{%
\if\relax\detokenize\expandafter{\accumword}\relax\else
\addcytoks[1]{\expandafter\randomrotation\expandafter{\accumword}}%
\fi
\def\accumword{}}
\newcommand\addletter[1]{\addtomacro\accumword{#1}}
\xtokcycleenvironment\cthulhu
{\addletter{##1}}
{\dumpword\groupedcytoks{\processtoks{##1}\dumpword}}
{\dumpword\addcytoks{##1}}
{\dumpword\addcytoks{##1}}
{\renewcommand*{\rmdefault}{fts}\fontfamily{fts}%
\selectfont\stripgroupingtrue\def\accumword{}}
{\dumpword}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% thanks to Bruno Le Floch: https://tex.stackexchange.com/q/9331/4012
% and in his comments to https://tex.stackexchange.com/a/29458/4012
\usepackage{rotating}
\usepackage[first=-6,last=6]{lcg}% you can play around with these values
\makeatletter
\newcommand{\globalrand}{\rand\global\cr@nd\cr@nd}
\makeatother
\newcommand{\randomrotation}[1]{%
\globalrand\turnbox{\value{rand}}{#1}\phantom{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{stackengine}
\begin{document}
\cthulhu
\tableofcontents
\noindent\hrulefill
\section
|[Crazy Stuff]|
{Crazy Stuff}
My Crazy Stuff Manifesto is \fbox{\fbox{forthcoming}}.
\subsection
|[Crazy Stuff iN mY HEAD]|
{Crazy Stuff iN mY HEAD}
Why am I losing it??!! \textcolor{|red|}{\smash{\stackunder
|[4pt]|{So Badly!}{|\rule{6ex}{4pt}|}}}
\subsection
|[Help Me]|
{Help Me}
Strangely, my ability to code \textcolor{|cyan|}{\LaTeX{}}
seems unaffected.
\section
|[My Manifesto]|
{My Manifesto}
Hello, I am crazy. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed. I am a Cthulhu worshipping gibbering madman, unhinged by
the horrors I have witnessed.
\begin{|enumerate|}
\item I
\item I am
\item I am taking
\item I am taking a
\item I am taking a potion.
\end{|enumerate|}
\endcthulhu
The potion seems to have worked!
\end{document}