[Tex/LaTex] Acrostics in latex (how to hide a message)

charactershorizontal alignmentspacing

I think about hiding a message in a LaTeX document. I would like to do so by using the first characters in each line of the first paragraph to spell out a message.

For example, to spell out "Never Gonna Give You Up", the output text could say the following.

Nobel archers were commissioned by the earl to face an
encountered army of likewise seasoned soldiers of 
very prestigious families. Each archer was known to hit
every target with high precision. But in some very
rare cases, ...

(Spare me to come up with more nonsense, but you get the message.)

How can I do this while maintaining the justification of the text (assuming that I have sufficiently many words per line)?

I am using the standard report format.

Best Answer

Since the first-letter arrangement heavily influences the line-breaking, it is assumed that this is done manually. As such, I'm assuming you're okay with adding a \\ at the end of each line, similar to how one would initiate a new row in a tabular. With this in mind, the following might be a starting point:

enter image description here

\documentclass{article}

\usepackage{collcell,environ}

\newlength{\maxlinewidth}
\newcommand{\stretchcell}[1]{\makebox[\maxlinewidth][s]{#1}}

\NewEnviron{rickroll}[1][\relax]{%
  \settowidth{\maxlinewidth}{%
  \begin{tabular}{@{}l@{}}
    \BODY
  \end{tabular}}%
  \ifx#1\relax\else\setlength{\maxlinewidth}{#1}\fi%
  \begin{tabular}{@{}>{\collectcell\stretchcell}l<{\endcollectcell}@{}}
    \BODY\hfill
  \end{tabular}%
}

\begin{document}

\noindent
\begin{tabular}{@{}l@{}}
Nobel archers were commissioned by the earl to face an \\
encountered army of likewise seasoned soldiers of \\
very prestigious families. Each archer was known to hit \\
every target with high precision. But in some very \\
rare cases, \ldots
\end{tabular}

\noindent
\begin{rickroll}
Nobel archers were commissioned by the earl to face an \\
encountered army of likewise seasoned soldiers of \\
very prestigious families. Each archer was known to hit \\
every target with high precision. But in some very \\
rare cases, \ldots
\end{rickroll}

\end{document}

The idea behind the above suggestion is that you set each row of a tabular inside a \makebox[<width>][s]{<stuff>}, since this will [s]tretch the space between words to fit <stuff> within <width>. The <width> is determined as the widest line within the rickroll.

We measure the width of the longest line and then set the text. As such, we process the contents twice which is easiest when using environ.

Limitations:

  1. Since the paragraph is set in a tabular, you can't break it across the page boundary.

  2. Each paragraph has to be managed separately.

You can set multiple paragraphs in the same rickroll, but the same limitation in (1) would hold. Setting multiple paragraphs would require manually setting the paragraph separation using something like \\[\parskip]. Additionally one would need an \hfill on each line that you don't want to spread out.