Fun titles by spliting in letters (or words)

by e_moro   Last Updated May 23, 2020 01:23 AM

I want to display titles using a spelling rutine I have found in this interesting discussion.

The idea is that different simple effects can be easily selected. Unfortunatly this code have some limitations that I have not been able to overcome: It does not accept blank spaces, accents or macros.

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{lcg}

% decoration
\def\efect{}
\def\decorate#1#2{\reinitrand[first=-#1,last=#1]\aux#2\end}
\def\aux#1{%
    \ifx\end#1
    \else
        \efect#1%
        \expandafter\aux
    \fi}

% efects
\newcommand{\jumpingbox}[1]{\rand\raisebox{\therand pt}{\fbox{#1}}}
\newcommand{\rotationbox}[1]{\rand\rotatebox{\therand}{\fbox{#1}}}

\begin{document}
\noindent
\let\efect\jumpingbox
\decorate{2}{The quick brown fox jumps}\\
\let\efect\rotationbox
\decorate{10}{The quick brown fox jumps}\\
\decorate{10}{{{The}}{{quick}}{{brown}}{{fox}}{{jumps}}{{\dots}}}
\end{document}

enter image description here

Notes:

  1. None of the others solutions in the link above support accents (nor utf-8 input encoding, I suppose). Most of them do not support blank spaces either.
  2. Somehow, I also would have the "word by word" feature.
  3. It would be pedagogical for me working over that tex code. It looks like a simple recursive rutine. However, I suspect that it may hide a very dark world within.
  4. My attepmts:

Adding a conditional sentence for whitespaces

\if#1 %
    { }
\else
    \efect#1%
\fi

and an a horrible syntax to call it

\decorate{2}{The{ }quick{ }brown{ }fox{ }jumps{ 
over{ }Mar{{í}}a}\\ % <- note the accentuated 'i'

they can partially solve the problems, but obviously it can't be taken as a definitely solution.



Answers 1


You can make the argument of \aux delimited by a space, so it operates word-by-word, rather than token-by-token (which is why it doesn't work with accented characters: they are made of multiple tokens).

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{lcg}

% decoration
\def\efect{}
\edef\decorate#1#2{%
  \noexpand\reinitrand[first=-#1,last=#1]%
  \noexpand\decorateAUX#2 %
  \noexpand\decorateEND\space}
\def\decorateAUX#1 {%
  \ifx\decorateEND#1%
  \else
    \efect{#1}%
    \expandafter\decorateAUX
  \fi}

% efects
\newcommand{\jumpingbox}[1]{\rand\raisebox{\therand pt}{\fbox{#1}}}
\newcommand{\rotationbox}[1]{\rand\rotatebox{\therand}{\fbox{#1}}}

\begin{document}
\noindent
\let\efect\jumpingbox
\decorate{2}{The quick brown fox jumps}\\
\let\efect\rotationbox
\decorate{10}{The quick brown fox jumps}\\
\decorate{10}{The quick brown fox jumps \dots}\\
\decorate{10}{The quick brown fox jumps over María}
\end{document}

enter image description here

Phelype Oleinik
Phelype Oleinik
May 23, 2020 01:18 AM

Related Questions



Token list of counter values

Updated March 29, 2018 09:23 AM


\centering leads to cascade of errors

Updated October 27, 2018 00:23 AM