# On the easier embedding of certain jokes on texts?

I just found the following in a facebook page Called "Academia Obscura":

Which is a piece of the lyrics in Rick Astley: Never Gonna Give You Up.

Obviously, this could be crafted with a wise and patient selection of words and spacings but doing so takes a lot of time. I know that it's possible to build something in LaTeX that could easily do that but I don't know even where to begin (what libraries could/should be used). (The exact thing I'm looking is something that put certain words in the beginning of the text and then fill the rest).

Can you give me some hints? With just a few directions, I could work my way up and never gonna give this project up, never gonna let this project down.

• LaTeX is a document preparation system, it may be possible to use typesetting means to force words to the start of lines, or to get LaTeX to issue error messages if a word moves from the start of a line, but generating meaningful text? with specific words at the start? this is way beyond basic LaTeX, this is full blown AI isn't it? I mean sure LaTeX is Turing Complete, but I wouldn't choose it for that project and it is not something that you should expect to do without a research grant and a few decades, surely? surely i'm not overstating this? – Au101 Jun 26 '16 at 3:02
• @Au101 I don't think that the question is asking about text generation. But, e.g. it would be possible to mark each word you want in the 'secret' with a macro and then figure out a way to have them begin each line (although that might not be so easy.) – Alan Munn Jun 26 '16 at 3:06
• @Au101 Yes. It's what Alan suggested. – Billy Rubina Jun 26 '16 at 3:07
• @AlanMunn Ah! Sorry :) – Au101 Jun 26 '16 at 3:17
• It is easy to write a macro that starts text on a new line, and you can fiddle with things like \emergencystretch and \parfillskip to fill out the line; you could also use boxes to prevent line breaks and stretch out text. But the fact of the matter is that you need to write the text in such a way that it is (at least!) somewhat feasible to break the lines with the words you want. This requirement is not too much different than the basic point that TeX can help you make a document look nice, but it can't write the document or make the document say something meaningful. – jon Jun 26 '16 at 3:35

Here are two methods I had in mind when I made the earlier comment.

\documentclass{article}
\usepackage[T1]{fontenc}

% An environment is good because it keeps these settings local
\newenvironment{jokes}
{\parindent 0pt
\parfillskip 0pt
\setlength{\emergencystretch}{.5\textwidth}
}
{}

% The \secret macro
\makeatletter
\newcommand{\secret}{\@ifstar\@secretnonewline\@secretnewline}
\newcommand{\@secretnewline}[1]{\par\textbf{#1}}
\newcommand{\@secretnonewline}[1]{\textbf{#1}}
\makeatother

%\newcommand{\secretbox}[1]{\newline\makebox[\textwidth][s]{#1}}

\usepackage{graphicx}

\makeatletter
\newcommand{\secretbox}{\@ifstar\@secretboxNNL\@secretboxNL}
\newcommand{\@secretboxNL}[1]{\newline
\resizebox{\textwidth}{\height}{#1}}
\newcommand{\@secretboxNNL}[1]{%
\resizebox{\dimexpr\textwidth - \parindent\relax}{\height}{#1}}
\makeatother

\begin{document}

Obviously, this could be crafted with a wise and patient selection of
words and spacings but doing so takes a lot of time. I know that it's
possible to build something in LaTeX that could easily do that but I
don't know even where to begin (what libraries could/should be
used). (The exact thing I'm looking is something that put certain
words in the beginning of the text and then fill the rest).

Can you give me some hints? With just a few directions, I could work
my way up and never gonna give this project up, never gonna let this
project down.

\bigskip

% This method requires you to craft your paragraph carefully
\begin{jokes}

\secret*{Obviously}, this could be crafted with a wise and patient
selection of words and spacings but doing so takes a lot of time. I
know that \secret{it's} possible to build something in LaTeX that
could easily do that but I don't know even where to begin (what
libraries could/should be used). (The exact thing I'm looking is
\secret{something} that put certain words in the beginning of the
text and then fill the rest).

Can you give me some hints? With just a few directions, I could
\secret{work} my way up and never gonna give this project up, never
gonna let this project down.

\end{jokes}

\bigskip

% This one just stretches or shrinks the words in the box so they fit
% on the line
\secretbox*{Obviously, this could be crafted with a wise and patient
selection of words and} %
\secretbox{spacings but doing so takes a lot of time. I know that it's
possible to} %
\secretbox{build something in LaTeX that could easily do that but I
don't know even} %
\secretbox{where to begin (what libraries could/should be used). (The
exact thing I'm looking is} %
\secretbox{something that put certain words in the beginning of the
text and then fill the rest).  Can you give me some hints? With just
a few directions, I} %
\secretbox{could} %
\secretbox{work my way up and never gonna give this project up, never
gonna let this project down.}

\end{document}


However, I still think the best solution, whatever it might be, means trying to write the text in such a way that the 'secret' acrostic does not make the rest of the text look ridiculous (as it does [by design] above).