Skip to content

Instantly share code, notes, and snippets.

@maleadt
Created March 27, 2015 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maleadt/ee1ab7e3127672395ad2 to your computer and use it in GitHub Desktop.
Save maleadt/ee1ab7e3127672395ad2 to your computer and use it in GitHub Desktop.
LaTeX macro to obfuscate text as an image (to prevent selecting, parsing, ...)
\makeatletter
\newcount\@imagecount
\newcommand\showasimage[1]{%
\global\advance\@imagecount 1
\edef\x{image-\the\@imagecount}%
\immediate\write18{echo '\unexpanded{\font\1=}\fontname\font' > \x.tex}%
\immediate\write18{echo '\unexpanded{\1#1\nopagenumbers\bye}' >> \x.tex}%
\immediate\write18{pdftex \x.tex}%
\immediate\write18{pdf2ps -dNoOutputFonts \x.pdf \x.ps}
\immediate\write18{ps2pdf \x.ps \x.pdf}
\immediate\write18{pdfcrop --hires \x.pdf \x.pdf}
\settodepth{\@tempdima}{#1}%
\raisebox{-\the\@tempdima}{\includegraphics{\x.pdf}}%
}
\AtEndDocument{%
\loop
\immediate\write18{rm image-\the\@imagecount.*}%
\advance\@imagecount-1
\ifnum\@imagecount>0\repeat
}
\makeatother
@maleadt
Copy link
Author

maleadt commented Mar 27, 2015

Note that this requires passig --shell-escape to pdflatex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment