2

I'm trying to make an entire document to look like handwrote. For that I tried both the Cthulhu and handlatex.

Both of them require the following usage:

\command{here the text to be applied.}

Which can only be applied at most to a paragraph.

I tried \everypar{\command{\everypar{}}} but it doesn't seemed to work properly.

Is it possible to achieve an automated process, applying the same command to all texts (paragraths, lists, etc.)?

1 Answers1

3

As is frequently the case, there is a distinction between a switch-like command, that provides a setting that applies to the remainder of the document, until changed, and a macro, which operates on an argument. In the case of at least one of the cited answers, \cthulhu must operate as a macro because it reads input and applies a macro (rotational) transformation to each space-delimited piece of input. The random rotation of text would be difficult to accomplish as a declaration.

Nonetheless, the situation can be improved in several ways.

  1. By allowing the transformation to work across paragraph boundaries, larger inputs can be addressed in one fell swoop.

  2. By providing special handling of things like control sequences (macros and such), spaces, and groups, there is at least the hope of tackling more general LaTeX input. In the answer that I will provide, I use a token cycle, in which each token of input is passed to various directives for processing. In this approach, tokens that constitute characters, groups, macros, and spaces can all have different directives applied, which is essential for handling general inputs.

  3. Turn the process from a macro into an environment. While still requiring a termination, the process is freed up from the difficulties of enclosing everything in braced format.

So, now for my approach. Here, I recreate the Cthulhu effect of the referenced answer, but generalize it with a token cycle so that more general content can be handled across paragraphs.

I had to restructure things a bit. Instead of using the recursive \@cthulhu macro provided in the referenced answer (which has no hope of working with an input stream of macros and macro arguments), I cast it in a tokcycle environment, where macros are passed through unaffected and macro arguments can be escaped by surrounding them in | delimiters (see how I do that multiple times in the MWE).

Unfortunately, I found that sectioning content in the aux file did not like the random rotations applied, and so all sectioning has to provide an escaped optional argument, in the form of \section|[blah]|{blah}, so that the toc blah goes without rotational manipulation.

Usage is accomplished with \cthulhu...\endcthulhu. Outside of the pseudo-environment, the baseline document font is restored.

\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}

enter image description here

enter image description here

  • With the exact same example code I got ! Undefined control sequence.l.18 \xtokcycleenvironment\cthulhu. Am I missing something? –  May 19 '21 at 12:43
  • @lygamac You need the latest version of tokcycle: https://ctan.org/pkg/tokcycle from 2021-03-10. The essential files required for compilation are tokcycle.sty and tokcycle.tex. The documentation files are, I hope, useful as well. – Steven B. Segletes May 19 '21 at 12:44
  • All fixed, thanks for such quick response! –  May 19 '21 at 12:50
  • Can you add an example with list (itemize) environment? Thanks in advance! –  May 19 '21 at 12:56
  • @lygamac Just place the words itemize or enumerate between the escape character |, as in \begin{|enumerate|} and \end{|enumerate|}. I have added an example. – Steven B. Segletes May 19 '21 at 13:02
  • Many thanks, is it impossible to redefine these commands/environments with | (so I don't have to tweak the original file)? I got many errors when trying to do so. –  May 19 '21 at 13:50
  • @lygamac This is a fundamental problem. How is the environment to differentiate the word "itemize" as found it I want to itemize my wardrobe or even I wish to \textit{itemize} my wardrobe, both of which you want to be subject to the rotational transformation, from \begin{itemize} where subjecting "itemize" to the transformation destroys it as the name of an environment? In essence, TeX has no automatic way of knowing whether a given token is part of an argument or not. You could with effort build in a test for the phrase itemize, but that is just the tip of the iceberg. – Steven B. Segletes May 19 '21 at 13:56
  • @lygamac To transform an existing file, I would start by placing the \endcthulhu close to the \cthulhu, so that the transformation group was small. Then, progressively move \endcthulhu closer to the end of the document. In this way, you will hopefully find the problems one at a time, rather than be confronted with 37 errors all at once, demanding a fix. – Steven B. Segletes May 19 '21 at 13:58
  • All right! Thanks –  May 19 '21 at 14:26