diff options
author | Karl Berry <karl@freefriends.org> | 2006-07-15 21:13:25 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-07-15 21:13:25 +0000 |
commit | a75519ac49fb11f564759ef2e7e984e064f18913 (patch) | |
tree | f90f761bbb7d5874ca2368d89f29cfa093e81047 /Master/texmf-dist/tex | |
parent | 92087ec9254485f45be7ef05102d78aca4030ab3 (diff) |
new package randtext replaces switcheml (21mar06)
git-svn-id: svn://tug.org/texlive/trunk@1853 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/randtext/randtext.sty | 143 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/switcheml/switcheml.sty | 90 |
2 files changed, 143 insertions, 90 deletions
diff --git a/Master/texmf-dist/tex/latex/randtext/randtext.sty b/Master/texmf-dist/tex/latex/randtext/randtext.sty new file mode 100644 index 00000000000..0274642c878 --- /dev/null +++ b/Master/texmf-dist/tex/latex/randtext/randtext.sty @@ -0,0 +1,143 @@ +% +% randtext.sty +% +% Charles Duan (2004/12/20) +% +% Provides one useful macro, \randomize{TEXT}. Result is a typeset box that +% looks, on paper, like TEXT, but whose letters have in fact been placed in +% random order so that they are not copiable from the file directly. +% +% In other words, typing: +% +% This is a \randomize{random-text} test. +% +% would produce output that looks like: +% +% This is a random-text test. +% +% but if you tried to copy-paste it from the output file, you would probably get +% +% This is a mdoxt-etnra test. +% +% The function of this odd macro is to obfuscate e-mail addresses, say on a PDF +% document put online, so that the human reader sees the address as expected, +% but e-mail address harvesters and spambots cannot determine the address. Since +% this macro is done entirely using TeX typesetting commands, it requires no +% external image generation or anything, and the typeset result is just as +% high-quality as if no obfuscation had taken place. +% +% This macro does take into account kerning between character pairs, but it does +% not account for ligatures. To make appropriate ligatures, surround the +% ligature characters with braces. +% +% This package supersedes "switcheml.sty", written by the same author. (That is +% the reason that the internal macros begin with "se@". +% +% Requires the file "random.tex", by Donald Arseneau. I believe that this file +% comes as part of a standard TeX distribution. +% +% +\ProvidesPackage{randtext}[2004/12/20 Obfuscate text] +% +% We use the random package to pick random numbers. +\input random +% +% \se@count stores the number of letters/groups to typeset. For instance, +% \randomize{abc{de}fg{hij}kl} +% contains 9 letters/groups. +\newcount\se@count +% +% \se@random is a random number register. +\newcount\se@random +% +% \se@pos is used to store the width of each section of the randomized text. +\newdimen\se@pos +% +% Randomize the text of the argument. +\def\randomize#1{% + % Do nothing for empty argument. + \def\se@tmp{#1}\ifx\se@tmp\@empty\else + % Make our work local + \begingroup + % In case this is the first thing in the paragraph, go to horizontal + % mode + \leavevmode + % Initialize \se@count=1, \se@pos=0pt + \se@count\@ne + \se@pos\z@ + % Now iterate over the argument text. The \relax is put at the end + % as an untypeset token. + \se@randomize#1\relax\@stop + \endgroup + \fi +} +% +% Iterator function for \randomize. Essentially, this function will be executed +% once for each token in the list. +\def\se@randomize#1#2#3\@stop{% + % Define a macro \pos@[\se@count]. Essentially, this makes a unique, + % numbered macro for each letter/group. + \expandafter\edef\csname pos@\the\se@count\endcsname{% + % The macro produces a zero-width box that jumps forward \se@pos and + % then typesets the letter/group. Note the \the\se@pos, to force current + % evaluation of the distance to move forward. + \noexpand\rlap{\hskip\the\se@pos\relax#1}% + }% + % Advance \se@pos forward by the width of the first group and the + % immediately subsequent group, and then backward by the width of the second + % group. The effect is to advance \se@pos by the first group and the kern + % between the first and second groups. + \setbox\z@\hbox{#1#2}\advance\se@pos\wd\z@ + \setbox\z@\hbox{#2}\advance\se@pos-\wd\z@ + % + % If there's nothing left to iterate over, then: + % \se@pos is the width of the whole text + % \se@count is the number of letters/groups, or the highest \pos@[number] + % so we make a box of width \se@pos, place our random letters in it with + % \se@rand@place, and fill up the box for good measure. + % + % Otherwise, increment \se@count and run the function again. + % + % Note two things: + % 1. We put braces around #2 but not #3. Since there's an extra \relax at + % the end of #3 at all times, we don't have the problem of TeX stripping any + % braces from it. + % 2. The other reason we needed that \relax was that, since we read + % letters/groups in pairs, the last letter/group would only be read if there + % was an extra token at the end (i.e., the \relax). + \def\se@tmp{#3}\ifx\se@tmp\@empty \expandafter\@firstoftwo + \else \expandafter\@secondoftwo \fi + {\hb@xt@\se@pos{\se@rand@place\hfill}}% + {\advance\se@count\@ne\se@randomize{#2}#3\@stop}% +} +% +% Now all of our \pos@[number] functions are set, and we just need to randomly +% select and place. +\def\se@rand@place{% + % + % Pick a random number between one and \se@num. (If \se@num>3, then ensure + % that the number is over three. This way, the first two elements will + % always be typeset last, guaranteeing at least some contortion.) + \ifnum\se@count>\z@ + \ifnum\se@count>\thr@@ + \setrannum\se@random\thr@@\se@count + \else + \setrannum\se@random\@ne\se@count + \fi + % Execute \pos@[\se@random]. + \csname pos@\the\se@random\endcsname + % Now replace \pos@[\se@random] with \pos@[\se@count] and decrement + % \se@count. This way, the next random number will be guaranteed to + % typeset an unselected value. + \ifnum\se@random=\se@count\else + \edef\reserved@a{% + \let\expandafter\noexpand\csname pos@\the\se@random\endcsname + \expandafter\noexpand\csname pos@\the\se@count\endcsname + }\reserved@a + \fi + \advance\se@count\m@ne + % Repeat + \expandafter\se@rand@place + \fi +} +\endinput diff --git a/Master/texmf-dist/tex/latex/switcheml/switcheml.sty b/Master/texmf-dist/tex/latex/switcheml/switcheml.sty deleted file mode 100644 index fb409929a0d..00000000000 --- a/Master/texmf-dist/tex/latex/switcheml/switcheml.sty +++ /dev/null @@ -1,90 +0,0 @@ -% -% switcheml.sty -% -% Charles Duan (2004/02/10) -% -% Obfuscates an e-mail address so that it is unreadable by automated document -% crawlers but appears correct when displayed. -% -% Commands provided by this package are: -% -% \switchemail{EMAIL} -% Obfuscates EMAIL by reversing on the @ and . symbols, so -% some@one.place.com -% will be written to the document as: -% com place. one. some@ -% but it will appear properly on the document page. -% -% \switch{DELIM}{TEXT} -% Obfuscates TEXT by reversing values around DELIM, so -% \switch{,}{abc,def,ghi,jkl} -% will be written to the document as: -% jkl ghi, def, abc -% but it will appear on the document page as: -% abc,def,ghi,jkl -% -% \kernhack{A}{B} -% Produces a kern equivalent to the kern that would normally appear between A -% and B. -% -\ProvidesPackage{switcheml}[2004/02/10 Obfuscate e-mail addresses] -% Produce a kern equivalent to the kern between #1 and #2 -\def\kernhack#1#2{% - \begingroup - \setbox\z@\hbox{#1#2}% - \dimen@\wd\z@ - \setbox\z@\hbox{#1{}#2}\advance\dimen@-\wd\z@ - \ifdim\dimen@=\z@\else\kern\dimen@\fi - \endgroup -} -% Given a character to find (e.g., period) and a string of text, obfuscate the -% text so that the last part of the text is placed first, etc., so everything -% comes up in reverse order when you try to copy/paste but it looks fine on -% screen. For instance, -% -% some.domain.com -% -% is rewritten as: -% -% box{com} box{domain.} box{some.} -% -% with each of the boxes placed such that they print out properly. -% -\def\switch#1#2{% - \begingroup - \def\@switch##1#1##2\@nil#1##3\@stop{% - \def\reserved@a{##3}% - \ifx\reserved@a\@empty#2\else - \setbox\z@\hbox{##1#1}% - \setbox\tw@\hbox{\kernhack{#1}{##2}\switch{#1}{##2}}% - \dimen@\wd\tw@\advance\dimen@\wd\z@% - \wd\z@\dimen@% - \rlap{\hb@xt@\dimen@{\hfil\unhbox\tw@}}% - \box\z@ - \fi - }% - \@switch#2\@nil#1\@nil#1\@stop - \endgroup -} -% Given an e-mail address of the form abc@def.ghi.jkl, reverses it to be jkl -% ghi. def. abc@ -\def\switchemail#1{% - \expandafter\@switchemail#1\@stop -} -% Helper function for \switchemail. Note the \copy, because \kernhack will -% destroy the box otherwise. Need to do some funky stuff because of catcodes. -\begingroup - \makeatother - \def\tmp#1#2#3{% - \gdef#1##1@##2#2{% - \begingroup - \setbox#3\hbox{\switch{.}{##2}}% - \switch{@}{##1@\copy#3}% - \endgroup - }% - } - \makeatletter - \tmp\@switchemail\@stop\@tempboxa -\endgroup - -\endinput |