Text Formatting ⇒ Command to substitute words
Command to substitute words
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
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}
Re: Command to substitute words
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.
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
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}
Re: Command to substitute words
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Command to substitute words
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}
Re: Command to substitute words
- Stefan Kottwitz
- Site Admin
- Posts: 10360
- Joined: Mon Mar 10, 2008 9:44 pm
Command to substitute words
soul
and the censor
package. I would use 
Stefan