summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/censor/censor.sty
blob: 7afa369ddfdb2600fc87ad6f8dc435b8ffa7328b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% censor.sty
% Copyright Steven B. Segletes
\ProvidesPackage{censor}
[2009/12/07 v1.00
 Provides capability for redaction of sensitive information]

% CHOOSE MODE OF OPERATION:
% 1) IF .tex FILE IS CREATED IN PRIVATE (SECURE) ENVIRONMENT:
%  a) To produce censored document, censor individual words with
%     \censor{word}
%  b) To produce uncensored document, place \StopCensoring in preamble 
%  c) To produced a mixed document with some redaction, but elsewhere
%     turned off, place \StopCensoring and/or \RestartCensoring in
%     various document locations as needed.
%
% DISCLAIMER: Don't \censor whitespace (i.e., phrases), or justifications
% could get fouled up.  If space-laden phrase needs repeated censoring,
% I suggest typesetting according to the following example:
% \def\CodeName{\censor{Little} \censor{Bo} \censor{Peep}}
% In the text, refer to {\CodeName} as often as needed.
%
% 2) IF .tex FILE IS INITIALLY CREATED IN PUBLIC (UNSECURE) ENVIRONMENT:
%  a) To produce censored document, define (in the document preamble)
%     placeholders for all censored phrases, like:
%     \def\ProjectName{\censor*{7}}
%     In document, refer to {\ProjectName} as needed.  The "7" refers
%     to the approximate width (in ex's) of the censored word.
%  b) Use of \StopCensoring in preamble will merely turn censored
%     black rectangles into underlined blank spaces, since uncensored
%     word is not known to the public source (.tex) document.
%  c) To produce uncensored document, the source code must be moved
%     to a private (secure) working environment.  At that point, the
%     uncensored document may be created merely by editing the document
%     preamble and redefining the censored placeholders, so that
%     \def\ProjectName{\censor*{7}} becomes \def\ProjectName{Liberty},
%     for example.  Note that line justification could be affected, since
%     censored placeholders are not exactly the same width as the
%     actual word, in Mode 2 operation.
%  d) To produced (in the private/secure environment) a mixed document
%     with some redaction, but elsewhere turned off, place \StopCensoring
%     and/or \RestartCensoring in various document locations as needed.
%
% DISCLAIMER: Don't \censor whitespace (i.e., phrases), or justifications
% could get fouled up.  I suggest typesetting multi-word phrases according
% to the following example:
% \def\CodeName{\censor*{6} \censor*{2} \censor*{4}}
% In the text, refer to {\CodeName} as often as needed.
%
% NOTE: For both modes of operation, placeholders are placed in curly
% braces, so that surrounding white space and/or punctuation is properly
% handled.

\usepackage{pbox}

\newcommand\censor{\@ifstar{\@cenlen}{\@cenword}}
  \newcommand\@cenlen[1]{\protect\rule[-.3ex]{#1 ex}{2.1ex}}
  \newcommand\@cenword[1]{%
              \protect\rule[-.3ex]{\widthofpbox{#1}}{2.1ex}}

\newcommand\un@censor{\@ifstar{\un@cenlen}{\un@cenword}}
  \newcommand\un@cenlen[1]{\protect\underline{\hspace{#1 ex}}}
  \newcommand\un@cenword[1]{#1}

\newcommand\StopCensoring{\let\censor\un@censor}
\newcommand\RestartCensoring{%
           \renewcommand\censor{\@ifstar{\@cenlen}{\@cenword}}}

\endinput