我想在 LaTeX 文档中隐藏一条消息。我想通过使用第一段每行的第一个字符来拼出一条消息来实现这一点。
例如,要拼出“Never Gonna Give You Up”,输出文本可以是以下内容。
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, ...
(别让我再说更多废话,但你应该明白我的意思了。)
我怎样才能做到这一点,同时保持文本的对齐(假设每行有足够多的单词)?
我正在使用标准报告格式。
答案1
由于首字母排列对换行有很大影响,因此假设这是手动完成的。因此,我假设您可以\\
在每行末尾添加一个,类似于在 中开始新行的方式tabular
。考虑到这一点,以下内容可能是一个起点:
\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}
上述建议背后的想法是,你将 的每一行都设置tabular
在 内\makebox[<width>][s]{<stuff>}
,因为这将[s]
拉伸单词之间的空间以适合<stuff>
。<width>
被<width>
确定为 内最宽的行里克罗尔。
我们测量最长行的宽度,然后设置文本。因此,我们对内容进行两次处理,这在使用时最简单environ
。
限制:
由于段落设置在 中
tabular
,因此您不能将其跨越页面边界。每个段落必须单独管理。
您可以在同一个 中设置多个段落rickroll
,但 (1) 中的限制相同。设置多个段落需要使用 之类的东西手动设置段落分隔\\[\parskip]
。此外,您还需要\hfill
在不想展开的每一行上设置 。
答案2
虽然这不是你真正想问的问题的答案,但你可以从这个包中获得很多乐趣补充:
\documentclass{article}
\usepackage{accsupp}
\begin{document}
\thispagestyle{empty}
\BeginAccSupp{ActualText={We're no strangers to love ^^J
You know the rules and so do I ^^J
A full commitment's what I'm thinking of ^^J
You wouldn't get this from any other guy ^^J
^^J
I just wanna tell you how I'm feeling ^^J
Gotta make you understand ^^J
^^J
Never gonna give you up ^^J
Never gonna let you down ^^J
Never gonna run around and desert you ^^J
Never gonna make you cry ^^J
Never gonna say goodbye ^^J
Never gonna tell a lie and hurt you}}%
This is a text you for some reason would like to copy. %
Only problem is that this text (and not the secret lyrics) %
is copied if the pdf is opened with sumatraPDF. Acrobat %
reader copies the hidden text but doesn't allow me to mark %
all this dummy text.
\EndAccSupp{}
\end{document}
正如我指出的那样,它并不完美,不同的观众似乎有不同的处理方式。玩得开心:)
答案3
如果要有对齐的换行符,只需使用 命令,\break
而不是更流行的。 前面会显示\\
一个空格,因此在它前面加上 可以取消空格。\break
\unskip
\documentclass[a4paper]{article}
\newcommand{\breakwithjustification}{\unskip\break}
\let\B\breakwithjustification
\begin{document}
\setlength{\parindent}{0pt}
Nobel archers were commissioned by the earl to face an \B
encountered army of likewise seasoned soldiers of \B
very prestigious families. Each archer was known to hit \B
every target with high precision. But in some very \B
rare cases, ...
\end{document}
这在源代码中很明显,输入起来很烦人。因此,让我们将源代码中的换行符转换为输出中的换行符。
我将基于标准命令 进行构建\obeylines
,该命令将源代码中的每个换行符转换为段落分隔符。我们不需要段落分隔符,因为行不会对齐。相反,我们将调用 来换行\breakwithjustification
。
使用\obeylines
,源中的空白换行符将变成输出中的空白行。我将让它改为分段,就像在普通 TeX 排版中一样。
\documentclass[a4paper]{article}
\pagestyle{empty}
\newcommand{\breakwithjustification}{\unskip\break}
\let\B\breakwithjustification
\newenvironment{obeylineswithjustification}{%
\def\par{%
%% Do nothing in vertical mode, i.e. at the beginning of a paragraph
\ifhmode%
%% Have we just had a mandatory line break?
\ifnum\lastpenalty>-10000 %
%% Insert a mandatory line break.
\unskip\break%
\else%
%% We just had a mandatory line break. Cancel it and end the paragraph.
\unpenalty%
\hfil%
\endgraf%
\fi%
\fi}%
\obeylines%
}{%
\par%
}
\begin{document}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}
Ragged-left is casually kept:
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, ...
Rather obtrusive left-right lineup:
Nobel archers were commissioned by the earl to face an \B
encountered army of likewise seasoned soldiers of \B
very prestigious families. Each archer was known to hit \B
every target with high precision. But in some very \B
rare cases, ...
Here's a paragraph that's typeset normally, for comparison. This paragraph is
justified at both margins (except for the last line which is flush left). The
line breaks fall wherever they like. The next paragraphs respect the line
breaks and paragraph breaks in the source.
\begin{obeylineswithjustification}
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, ...
See how in this environment, a line break in the source translates into
a line break in the output. This way you can get
your desired output in a nonobtrusive way.
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, ...
\end{obeylineswithjustification}
The End.
\end{document}