Here's a quick solution using the customization possibilities of the soul
package. More information on how this works can be found in the package documentation, p. 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}
This solution allows to censor multiple lines and also treats hyphenated words correctly (see "armour-like"). As the characters are completely replaced by whitespace using \phantom
, the censored text isn't written to the resulting PDF at all and therefore can't be extracted.
Not quite a generic solution, as it assumes that the first letter is unique in the operator name. The \relax
are perhaps a bit optional I am always confused about when I should put some or not ;-)
\documentclass{amsart}
\usepackage[english,spanish]{babel}
\makeatletter
\newcommand\Max{\@tempcnta=\mathcode`\m\relax
\mathcode`\m=\mathcode`\M\max\mathcode`\m=\@tempcnta\relax}
\makeatother
\begin{document}
\begin{equation*}
\max_0^\infty = \Max_0^\infty \Max\nolimits_0^\infty m M
\end{equation*}
\selectlanguage{english}
\begin{equation*}
\max_0^\infty = \Max_0^\infty \Max\nolimits_0^\infty m M
\end{equation*}
\end{document}
Thanks to egreg for his comment(s). After having temporarily incorporated his simplification (of the code of my initial proposal) to the extension I am now proposing, I now return to the original thing, but also incorporate the later improvements signaled by egreg
.
The same restriction as above applies (the operator name should contain its initial letter only once).
\documentclass{amsart}
\usepackage[english,spanish]{babel}
\pagestyle{empty}
\makeatletter
\def\Tr@nsmogrify#1#2.{\expandafter\newcommand\csname #1#2\endcsname
{\mathchardef\Tr@ns@temp=\mathcode\lccode`#1\relax
\mathcode\lccode`#1=\mathcode`#1\lowercase{\csname#1#2\endcsname}%
\mathcode\lccode`#1=\Tr@ns@temp\relax}}
\@for\x:=Sin,Cos,Max,Min,Lim,Limsup,Liminf,Inf\do{%
\expandafter\Tr@nsmogrify \x.}
\makeatother
\begin{document}
\thispagestyle{empty}
\noindent
\begin{minipage}{.5\linewidth}
\begin{align*}
\min_0^\infty &= \Min_0^\infty\\
\min\nolimits_0^\infty &= \Min\nolimits_0^\infty\\
\max_0^\infty &= \Max_0^\infty\\
\lim_{x\to\infty} &= \Lim_{x\to\infty}\\
\liminf_{x\to\infty} &= \Liminf_{x\to\infty}\\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
\inf_{x\in A} &= \Inf_{x\in A}\\
\sin^2 x +\cos^2 x &= \Sin^2 x +\Cos^2 x \\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
m,M,l,L&,s,S,c,C
\end{align*}
\end{minipage}
\begin{minipage}{.5\linewidth}
\selectlanguage{english}%
\begin{align*}
\min_0^\infty &= \Min_0^\infty\\
\min\nolimits_0^\infty &= \Min\nolimits_0^\infty\\
\max_0^\infty &= \Max_0^\infty\\
\lim_{x\to\infty} &= \Lim_{x\to\infty}\\
\liminf_{x\to\infty} &= \Liminf_{x\to\infty}\\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
\inf_{x\in A} &= \Inf_{x\in A}\\
\sin^2 x +\cos^2 x &= \Sin^2 x +\Cos^2 x \\
\limsup_{x\to\infty} &= \Limsup_{x\to\infty}\\
m,M,l,L&,s,S,c,C
\end{align*}
\end{minipage}
\end{document}
Here is the result:
Addendum:
The above definitions make \Xyzt
behave like \xyzt
with respect to the positions of limits, in inline as well as display style. But there is a difference: \[\sin\limits_a^b\]
or $\sin\limits_a^b$
do not put the a
and b
in limits positions, whereas \[\Sin\limits_a^b\]
and $\Sin\limits_a^b$
do. I would call this an unintended feature rather than a bug! This is illustrated by the following:
Note the asymmetry of behavior of the amsmath
operators \sin
and \min
. Whereas for the first \limits
does nothing, for the second \nolimits
does work. I will not qualify this as a bug of amsmath
(or rather amsopn.sty
), as there must be reasons beyond me, but I had never realized that until now.
PS: obviously the above image comes from a source with \usepackage[spanish]{babel}
but I checked that the exact same behavior is observed without any loading of babel. Note also that \sin
and \min
in amsopn.sty
are not defined via \DeclareMathOperator
, respectively \DeclareMathOperator*
, but only by some part of the code of these macros, but this is another not relevant detail.
PS2: as a matter of fact the [spanish]{babel}
defined operator names behave differently from the analogous amsmath
provided names with respect to limits.
Best Answer
The answer depends a lot about what you mean by a "character" and how your input looks like (does it e.g. commands). One possibility is to use soul which contains a lot code to analyze text. E.g. you can get your boxes simply by misusing the \so command: