Text Formatting ⇒ Command to substitute words
Command to substitute words
Hello everyone,
I would like to make a document anonymous by substituting for instance XXXX for a specific word. I was not successful in finding the command I was looking for, or a package providing it, either on the Internet or in forums.
Here is the command that I am seeking: \command{firstName lastName}, which would output XXXXXXXXX XXXXXXXX, i.e. a command that substitutes X for each letter.
Before trying to program this command, I wanted to check with you if it was not already existing.
Thank you for your help.
I would like to make a document anonymous by substituting for instance XXXX for a specific word. I was not successful in finding the command I was looking for, or a package providing it, either on the Internet or in forums.
Here is the command that I am seeking: \command{firstName lastName}, which would output XXXXXXXXX XXXXXXXX, i.e. a command that substitutes X for each letter.
Before trying to program this command, I wanted to check with you if it was not already existing.
Thank you for your help.
TeX Live 2012 and Texmaker 4.0.2
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
Hi and welcome,
the most simplest substitution would be a fixed one in my point of view.
Having the exact number of letters of the original name can already give a hint on the person.
the most simplest substitution would be a fixed one in my point of view.
Code: Select all
\newcommand\anonymize[1]{Name anonymized}
Code: Select all
\documentclass{article}
\newcommand{\anonymize}[1]{anonymized name}
\begin{document}
\anonymize{Santa Claus}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Re: Command to substitute words
Thank you Johannes_B for your quick reply and your welcome.
Your idea is good! But I still think I would like X to substitute each letter. As you pointed out, it would give a hint on the person, but it would also keep other words in their original place.
Thank you.
Your idea is good! But I still think I would like X to substitute each letter. As you pointed out, it would give a hint on the person, but it would also keep other words in their original place.
Thank you.
TeX Live 2012 and Texmaker 4.0.2
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
You are missing a simple fact, an X and a i have different widths.
Code: Select all
\documentclass{article}
\newlength{\noname}
\newcommand{\anonymize}[1]{%
\hphantom{#1}
}
\begin{document}
%\anonymize{Santa Claus}
\noindent Santa Claus (5 5) \\
XXXXX XXXXX \\
Heresy \\
XXXXXX \\
Donald Erwin Knuth \\
XXXXXX XXXXX XXXXX \\
Leslie Lamport \\
XXXXXX XXXXXXX \\
Ida Millimi\\
XXX XXXXXXX\\
The works of \anonymize{Santa Claus} describe a process to win
gold from rocks. \anonymize{Ida Millimi} derived a procedure to
not only get gold, but also platinum and rhodium. So she actually
gained 1 kg of gold, 1 kg of platinum and 1 kg of rhodium by
investing only 1 kg of simple feldspar. Incredible. Just
incredible. Others (\anonymize{Heresy} and \anonymize{Santa
Claus}) tried to reproduce the results but failed pretty badly.
All they got was smaller pieces of feldspar.
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Re: Command to substitute words
Yes, you are absolutely right! Thank you for sharing your solution. I appreciate it.
TeX Live 2012 and Texmaker 4.0.2
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
I thought about it over lunch, and the above can't be the solution.
Try out the different versions using a phantom, a rule and especially, look at the original.
Please note the following things, there must be care taken over preceeding character. If it is an opening parenthesis, add no space. If it is a letter, add a space.
Additionally, names can be broken over lines (and worst, hyphenated), so the replacement should consider that too. The first thing that comes too mind when replacing line break stuff is involved is LuaTeX. You can hack the stage right after calculating the paragraph and actually shipping it out. But unfortunately i'm no expert there.
Try out the different versions using a phantom, a rule and especially, look at the original.
Please note the following things, there must be care taken over preceeding character. If it is an opening parenthesis, add no space. If it is a letter, add a space.
Additionally, names can be broken over lines (and worst, hyphenated), so the replacement should consider that too. The first thing that comes too mind when replacing line break stuff is involved is LuaTeX. You can hack the stage right after calculating the paragraph and actually shipping it out. But unfortunately i'm no expert there.
Code: Select all
\documentclass{article}
\newlength{\noname}
\newcommand{\anonymize}[1]{%
\hphantom{#1}
}
\renewcommand{\anonymize}[1]{%
\settowidth{\noname}{#1}%
\rule{\noname}{.6\baselineskip}%
}
\begin{document}
%\anonymize{Santa Claus}
\noindent Santa Claus \\
XXXXX XXXXX \\
Heresy \\
XXXXXX \\
Donald Erwin Knuth \\
XXXXXX XXXXX XXXXX \\
Leslie Lamport \\
XXXXXX XXXXXXX \\
Ida Millimi\\
XXX XXXXXXX\\
The works of \anonymize{Santa Claus} describe a process to win
gold from rocks. \anonymize{Ida Millimi} derived a procedure to
not only get gold, but also platinum and rhodium. So she actually
gained 1 kg of gold, 1 kg of platinum and 1 kg of rhodium by
investing only 1 kg of simple feldspar. Incredible. Just
incredible. Others (\anonymize{Heresy} and \anonymize{Santa
Claus}) tried to reproduce the results but failed pretty badly.
All they got was smaller pieces of feldspar.
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Re: Command to substitute words
Thank you for your reply and help. Yes, anonymizing a document is actually not an easy task. I just found out another thread that could be useful: http://tex.stackexchange.com/questions/ ... a-document
TeX Live 2012 and Texmaker 4.0.2
- Stefan Kottwitz
- Site Admin
- Posts: 10345
- Joined: Mon Mar 10, 2008 9:44 pm
Command to substitute words
I know those possibilities such as
xesearch, where I can specify words in the preamble which will be replaced in the later text. It requires XeLaTeX, but this is often possible without a big change.
Stefan
soul
and the censor
package. I would use 
Stefan
LaTeX.org admin
Re: Command to substitute words
Thank you very much Stefan. The censor package is what I was looking for!
TeX Live 2012 and Texmaker 4.0.2