我想审查或隐藏一些文本,同时用适当数量的空白替换它们。替换文本无法搜索。要隐藏的文本通常存在于 LR 模式中。censor
和invisible
包似乎不能很好地处理跨多行的文本。
我认为,一种解决方案是将每个单词变成一个适当大小的框,\makebox[\wordwidth]{}
然后让 TeX(或 LaTeX)处理其余部分,因为\makebox
它被视为一个单词。
我非常\sloppy
,所以问题是希望简化了,因为你不必担心是否会在单词中间放置一个破折号。(尽管该soul
包能够处理这种情况。)
答案1
这是一个快速的解决方案,使用soul
包。有关其工作原理的更多信息,请参见在包装文档中,第 22-25 页。
\documentclass{article}
\usepackage{soul}
\makeatletter
\DeclareRobustCommand*\censor{%
\SOUL@setup%
\def\SOUL@everytoken{\phantom{\the\SOUL@token}}%
\def\SOUL@everyhyphen{%
\discretionary{%
\SOUL@setkern\SOUL@hyphkern%
\phantom{\SOUL@sethyphenchar}%
}{}{}%
}%
\def\SOUL@everyexhyphen##1{%
\SOUL@setkern\SOUL@hyphkern%
\hbox{\phantom{##1}}%
\discretionary{}{}{%
\SOUL@setkern\SOUL@charkern%
}%
}%
\SOUL@%
}
\makeatother
\begin{document}
One morning, when Gregor Samsa woke from troubled dreams, he found himself
transformed in his bed into a horrible vermin. He lay on his armour-like back,
and if he lifted his head a little he could see his brown belly, slightly domed
and divided by arches into stiff sections. The bedding was hardly able to cover
it and seemed ready to slide off any moment. His many legs, pitifully thin
compared with the size of the rest of him, waved about helplessly as he looked.
``What's happened to me?'' he thought. It wasn't a dream. His room, a proper
human room although a little too small, lay peacefully between its four familiar
walls. A collection of textile samples lay spread out on the table -- Samsa was
a travelling salesman -- and above it there hung a picture that he had recently
cut out of an illustrated magazine and housed in a nice, gilded frame.
One morning, when Gregor Samsa woke from troubled dreams, he found himself
transformed in his bed into a horrible vermin. He lay on his
\censor{armour-like} back, and if he lifted his head a little he could see his
brown belly, slightly domed and divided by arches into stiff sections. The
bedding was hardly able to cover it and seemed ready to slide off any moment.
His many legs, pitifully thin compared with the size of the rest of him, waved
about helplessly as he looked. \censor{``What's happened to me?''} he thought.
It wasn't a dream. His room, a proper human room although a little too small,
lay peacefully between its four familiar walls. A collection of textile samples
lay spread out on the table -- \censor{Samsa was a travelling salesman} -- and
above it there hung a picture that he had recently cut out of an illustrated
magazine and housed in a nice, gilded frame.
\end{document}
此解决方案允许审查多行,并正确处理带连字符的单词(参见“armour-like”)。由于使用 ,字符完全被空格替换\phantom
,审查的文本根本不会写入生成的 PDF,因此无法提取。
答案2
可以理解,你希望能够暂时“逃离”到“审查模式”之内段落但仍保留文档的格式。从这个意义上讲,最好提供一个将一些文本作为参数的命令,而不是在中途中断段落以将其翻译到环境中并导致可能的段落中断。
以下内容摘自该帖子并进行了修改将其参数的每个单词作为参数传递给另一个宏的宏?。这个最小工作示例提供了逐字\censor{<stuff>}
解析的命令,将每个单词放在中,从而保留对齐/间距。此处的命令提供了审查功能。可以对其进行修改以适应其他审查方式(例如,更改颜色)。<stuff>
\phantom
\phantom
\documentclass{article}
\begin{document}
\def\censor#1{\censorloopword#1 \nil}
\def\censorloopword#1 #2\nil{%
\phantom{#1} % <- Note the space!
\ifx&% #2 is empty, then & equals &
\let\next\relax
\else
\def\next{\censorloopword#2\nil}% iterate
\fi
\next\ignorespaces}
\def\do#1{#1}
\sloppy
\noindent \textbf{Censored paragraph:} \medskip
\mbox{}\censor{Lorem ipsum dolor} sit amet, consectetur adipiscing elit. Suspendisse \censor{massa} lorem, malesuada
ac imperdiet nec, adipiscing ut lorem. Nunc dignissim nibh erat. Phasellus fermentum lectus
ut mi viverra a pulvinar turpis interdum. Maecenas mollis laoreet consequat. Etiam malesuada
ultrices blandit. Praesent sem felis, consectetur eu consectetur id, tempor id quam. \censor{Cras id
lectus vitae dolor varius} laoreet. Suspendisse nec metus non justo iaculis ultricies quis
vel enim. In \censor{porttitor} dictum orci sit amet feugiat. Praesent pellentesque odio eu orci
interdum pulvinar. Suspendisse potenti. Mauris \censor{lacus} lacus, congue tincidunt condimentum
vitae, elementum quis nibh. Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus. \censor{Nulla venenatis iaculis} mauris, vitae semper neque ullamcorper et.
Integer et sem eu enim egestas pretium. Sed nulla sapien, pretium eget viverra ut, sollicitudin
tempor urna. In accumsan euismod augue at sagittis. Sed \censor{molestie tincidunt} erat \censor{eu} suscipit.
Nullam placerat, ipsum a facilisis venenatis, metus est adipiscing augue, at pharetra enim
dui sit amet metus.
\bigskip
\noindent \textbf{Uncensored paragraph:} \medskip
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse massa lorem, malesuada
ac imperdiet nec, adipiscing ut lorem. Nunc dignissim nibh erat. Phasellus fermentum lectus
ut mi viverra a pulvinar turpis interdum. Maecenas mollis laoreet consequat. Etiam malesuada
ultrices blandit. Praesent sem felis, consectetur eu consectetur id, tempor id quam. Cras id
lectus vitae dolor varius laoreet. Suspendisse nec metus non justo iaculis ultricies quis
vel enim. In porttitor dictum orci sit amet feugiat. Praesent pellentesque odio eu orci
interdum pulvinar. Suspendisse potenti. Mauris lacus lacus, congue tincidunt condimentum
vitae, elementum quis nibh. Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus. Nulla venenatis iaculis mauris, vitae semper neque ullamcorper et.
Integer et sem eu enim egestas pretium. Sed nulla sapien, pretium eget viverra ut, sollicitudin
tempor urna. In accumsan euismod augue at sagittis. Sed molestie tincidunt erat eu suscipit.
Nullam placerat, ipsum a facilisis venenatis, metus est adipiscing augue, at pharetra enim
dui sit amet metus.
\end{document}
作为比较,上述文件在未审查的版本上方打印了部分审查的段落,以展示审查能力:
代码中需要注意以下几点:
- 后面有一个空格,作为逐字
\phantom{#1} %
解析参数的标记。也就是说,假设单词之间用空格分隔。\censor
- 如果您想要审查段落的开头,请在前面添加
\censor{<stuff>}
以\mbox{}
创建该段落的“起点”,否则<stuff>
将被吞噬。 - 的参数
\censor
不能分段。在这种情况下,\censor
跨段落分隔符进行拆分,\mbox{}
在下一个段落的开头使用。 \censor
可以嵌套:\censor{... \censor{...} ...}
。- 谨慎使用空格。例如,
\censor{<stuff> } <more-stuff>
可能会因 而导致问题\ignorespaces
。
答案3
LaTeX 审查包已修订(目前为 2.1 版)。它现在可以处理文档多行的审查和(略有不便)多个段落的审查。此外,它保留未审查文档布局的能力也得到了改进
答案4
通过产生白色间隙进行审查是毫无意义的。这显然只是一种权宜之计。但当我申请\usepackage{censor)
\blackout{...}
将或(如 Steven B. Segletes 先前的回答中所建议的)一起应用\xblackout{...}
以生成黑色多行审查条时,结果令人失望。由于我在序言中使用了很多包,因此存在太多负面交互,多行审查条的结果非常丑陋,非常混乱。以下解决方案由 Ulrike Fischer 在 2007 年提出,通过对\usepackage{soul}
(https://groups.google.com/forum/#!topic/de.comp.text.tex/eDLcK57u7ZQ)仍然产生了漂亮的黑色多线条。(唯一的问题是它与的私人创作不相配\addsubsec
,但这是外围的):
\documentclass{article}
\usepackage{soul, color}
\makeatletter
\def\SOUL@geheimunderline#1{{%
\setbox\z@\hbox{#1}%
\dimen@=\wd\z@
\dimen@i=\SOUL@uloverlap
\advance\dimen@2\dimen@i
\rlap{%
\null
\kern-\dimen@i
\SOUL@ulcolor{\SOUL@ulleaders\hskip\dimen@}%
}%
\phantom{#1}%
}}
\DeclareRobustCommand{\secret}{%
\let\SOUL@ulunderline\SOUL@geheimunderline
\SOUL@hlsetup\SOUL@}
\makeatother
\begin{document}
\sethlcolor{black}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore
\secret{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempo.}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore
\end{document}
(我改变了Ulrike Fischer的命令\geheim{}
英文\secret{}
。)
我认为这是目前对带有非常长的序言的文档制作黑色审查条的最有效的方法。