[Tex/LaTex] Efficient ways to anonymize a document

best practicesjournal-publishing

Many academic journals practice double-blind peer review which means that the author is required to blind their document by removing any references that can reveal the author's identity. How can I take advantage of the power of TeX and friends to blind or anonymize a document? Or more bluntly put: how do people successfully blind their LaTeX documents?

Here are some techniques I can think of:

  • Search and replace terms such as one's name and one's affiliation.
  • Use macros to write sensitive terms, e.g. \newcommand\myname{N.N.}, and replace the definition when blinding.
  • Keep sensitive information in separate documents which are not included into the main document when it is blinded.
  • Use version control so that the blinding changes can easily tracked and reversed.

Answers which goes into detail on how to implement any of the outlined techniques above or their respective merits will also be appreciated.

Best Answer

I modified Antal S-Z's answer to this question to allow text to be completely blinded - i.e. the text to hide will be removed entirely from the document such as to prevent it from showing when marking it with the mouse cursor or using some other tool to analyse the document. However, the layout and appearance of the surrounding text will remain intact (although some slight differences may appear due to changes in hyphenation).

Here is the entire code:

\documentclass{minimal}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\newif\if@anonymize

\@anonymizetrue    % Uncomment to hide text
%\@anonymizefalse  % Uncomment to show text

\if@anonymize
  \newcommand{\highlight@DoHighlight}{
    \fill [outer sep = -15pt, inner sep = 0pt, color=black]
          ($(begin highlight)+(0,8pt)$) rectangle ($(end highlight)+(0,-3pt)$) ;
  }

  \newcommand{\highlight@BeginHighlight}{
    \coordinate (begin highlight) at (0,0) ;
  }

  \newcommand{\highlight@EndHighlight}{
    \coordinate (end highlight) at (0,0) ;
  }

  \newdimen\highlight@previous
  \newdimen\highlight@current
  \newlength{\item@width}

  \DeclareRobustCommand*\anonymize{%
    \SOUL@setup
    \def\SOUL@preamble{%
      \begin{tikzpicture}[overlay, remember picture]
        \highlight@BeginHighlight
        \highlight@EndHighlight
      \end{tikzpicture}%
    }%
    %
    \def\SOUL@postamble{%
      \begin{tikzpicture}[overlay, remember picture]
        \highlight@EndHighlight
        \highlight@DoHighlight
      \end{tikzpicture}%
    }%
    %
    \def\SOUL@everyhyphen{%
      \discretionary{%
        \SOUL@setkern\SOUL@hyphkern
        \SOUL@sethyphenchar
        \tikz[overlay, remember picture] \highlight@EndHighlight ;%
      }{%
      }{%
        \SOUL@setkern\SOUL@charkern
      }%
    }%
    %
    \def\SOUL@everyexhyphen##1{%
      \SOUL@setkern\SOUL@hyphkern
      \settowidth{\item@width}{##1}%
      \makebox[\item@width]{}%
      \discretionary{%
        \tikz[overlay, remember picture] \highlight@EndHighlight ;%
      }{%
      }{%
        \SOUL@setkern\SOUL@charkern
      }%
    }%
    %
    \def\SOUL@everysyllable{%
      \begin{tikzpicture}[overlay, remember picture]
        \path let \p0 = (begin highlight), \p1 = (0,0) in \pgfextra
          \global\highlight@previous=\y0
          \global\highlight@current =\y1
        \endpgfextra (0,0) ;
        \ifdim\highlight@current < \highlight@previous
          \highlight@DoHighlight
          \highlight@BeginHighlight
        \fi
      \end{tikzpicture}%
      \settowidth{\item@width}{\the\SOUL@syllable}%
      \makebox[\item@width]{}%
      \tikz[overlay, remember picture] \highlight@EndHighlight ;%
    }%
    \SOUL@
  }
\else
  \newcommand{\anonymize}[1]{#1}
\fi
\makeatother

\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras sit amet urna
nulla. Nam placerat risus quis elit placerat consectetur a in magna. Ut vitae
urna vitae urna sagittis mollis sed a velit. \anonymize{Phasellus enim tellus,
  dictum nec sagittis sit amet, viverra at leo.} Pellentesque faucibus orci non
urna facilisis sed venenatis lacus ultricies. In in diam ut massa sodales
consequat at ut mi. Mauris pharetra tortor et nunc iaculis aliquet sodales
turpis convallis. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. \anonymize{Morbi vulputate}, risus non
accumsan vulputate, justo mauris pretium lorem, nec rhoncus mi nisl sit amet
lacus. Aenean metus nunc, sagittis in dictum sed, facilisis sit amet ante. Fusce
enim lorem, pharetra non congue a, vehicula id metus. Nam facilisis, velit
condimentum volutpat tristique, elit elit tristique est, a varius nulla purus
non mi. Nam elementum viverra ligula sit amet hendrerit. Aenean sit amet tempus
turpis. Suspendisse at risus quis eros semper cursus.

\anonymize{Nunc eleifend, augue non lacinia sagittis, lorem elit ullamcorper
  libero, non placerat massa lectus vel nisi. Phasellus nunc elit, porttitor
  tempor placerat et, semper sed leo. Integer commodo molestie pretium. Ut eu
  dolor velit. Phasellus sed dui nunc. Donec iaculis est eu felis accumsan
  sodales. Vivamus hendrerit dignissim faucibus.}

In congue condimentum metus in ornare. Etiam at diam vitae mi laoreet
consectetur. \anonymize{Curabitur at turpis commodo nisi tempus tincidunt. Nam
  vestibulum lacinia mi, vitae auctor erat consequat ac.} Phasellus semper
blandit orci ac varius. Praesent et magna a mi faucibus porta a non libero. Cum
sociis natoque penatibus et magnis dis parturient montes, \anonymize{nascetur}
ridiculus mus. Nulla facilisi. Nullam commodo volutpat ante ac ornare. Donec
convallis diam accumsan ipsum porta eu elementum leo lacinia. Cras tincidunt
semper mauris, ut mollis lectus consectetur quis. \anonymize{Pellentesque sem
  urna}, fringilla eget faucibus quis, condimentum nec mi. Quisque odio felis,
fermentum quis feugiat placerat, dapibus vitae massa. \anonymize{Ut semper elit
  eget dolor imperdiet posuere.}
\end{document}

And here is an example showing a text with and without anonymization. The setting can be controlled by simple commenting and uncommenting two lines of code.

With anonymity: Text which has been anonymized

Without anonymity: Original text without anonymity

Related Question