Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Publishing pdf manuscripts on the web with emails embedded in the file results in spam.

More generally, I am looking for a way to automate the conversion of a string to an image.

It's quite easy to solve this old problem using \includegraphics an image (more here). The trouble is that you need a distinct file and typesetting run, and you end up with unnecessary image files that you cannot delete carelessly lest you also delete non-generated images.

Can you think of a way to do this on the fly? It's understood that people will have to type the email addresses if they need to message you, but that's the point.

More briefly/concretely...

With what can one replace #1


such that #1 appears as an image?


It would be really nice if the pdf file remains vectorial.

share|improve this question
I think it might be better to do something like joe <at> foo <dot> bar so that people using screen reading software can still email you. If it is an image, there is not much you can do if you can't see it. (Or does PDF have a way to insert this as alternate text in the same way html does? Then you could provide this for screen readers and the image for everyone else.) That said: ctan.org/pkg/randtext will do what you want. –  cfr Feb 14 '14 at 1:56
Actually, randtext doesn't work here. I get no errors, the output is fine but copy-and-paste is not scrambled at all. –  cfr Feb 14 '14 at 2:04
Be careful that for some viewers/printers the text of the image (in this case the email) can look/print very different from the the rest of the text, even if the resolution of the image is high. –  alfC Feb 14 '14 at 3:26
Related: tex.stackexchange.com/questions/150375/…. While it doesn't use an image approach, it makes it so the copy/paste produces a junk email address. –  Steven B. Segletes Feb 14 '14 at 3:44
For the partiucular objective of hiding the email text, there is other approach tex.stackexchange.com/questions/95123/…. (But the question is good in general). –  alfC Feb 14 '14 at 5:58

2 Answers 2

up vote 22 down vote accepted

The following solution does not (anymore) use ImageMagick's convert command as this would always create raster images, which will stand out from the text. Instead, it uses Ghostscript to vectorise the letters so that they appear like normal text but are in fact an uncopyable image. Note that you also have to run pdflatex with the --shell-escape switch enabled, so that the commands from \write18 will indeed be sent to the shell.

The image will be cropped so that it is placed on the base line (with descenders taken into account), and the font will match the one from the context. The temporary files (using a counter to allow more than one image on the same page) will be deleted at the end.

  \global\advance\@emailcount 1
  \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{convert -units PixelsPerInch -density 300 -trim \x.pdf \x.png}% raster
  \immediate\write18{gs -dNOCACHE -sDEVICE=epswrite -dQUIET -o \x.eps \x.pdf}% vector
  \immediate\write18{epstopdf --hires \x.eps}%
    \immediate\write18{rm email-\the\@emailcount.*}%
Email \showasimage{oe@foo.bar} not copyable

\textit{match font and depth: \showasimage{joe@foo.bar}} 


which yields (with the first line selected):

emails as images

share|improve this answer
Slightly more elaborate... Is this the 'microtype' solution? –  jon Feb 14 '14 at 3:34
Nice - I am thinking that the use of convert can be avoided with this idea. The standalone package can make trimmed output. –  Hans-Peter E. Kristiansen Feb 14 '14 at 3:35
@Hans-PeterE.Kristiansen Indeed! I have a hunch that a combination of standalone and either bashful or Robert's write18 (what is that!?) would make it possible to use a vector image. The result would then be indistinguishable from normal text inclusion (and the pdf file will likely be much smaller). –  Calaf Feb 14 '14 at 3:40
@Hans-PeterE.Kristiansen -- standalone uses ImageMagick by default as its conversion program. (Though it can be modified to use something else like Ghostscript.) –  jon Feb 14 '14 at 3:42
@jon 'micrographics', rather ... –  Robert Feb 14 '14 at 4:03

This works for me, but I don't know about your OS, so I'm not sure if it will work for you. Note that the command convert is part of ImageMagick. Compile with -shell-escape enabled.



echo "jon@jon.com" | convert label:@- email.png


That won't work in a \newcommand, however. But this seems to work (still on bash):


\immediate\write18{echo "#1" | convert label:@- #2.png}%



share|improve this answer
What does label:@- mean? man convert tells me that all options start with a -. –  Hans-Peter E. Kristiansen Feb 14 '14 at 2:32
@Hans-PeterE.Kristiansen -- It's to get a label from standard input; see here, at the end of the section. –  jon Feb 14 '14 at 2:42
Ok - I my mistake. Just simpler to write: convert label:#1 #2.png –  Hans-Peter E. Kristiansen Feb 14 '14 at 2:54
@Hans-PeterE.Kristiansen -- Sure. Same number of chars either way :). In TeX, at least. I'm used to thinking of convert mainly in a non-TeX usage... –  jon Feb 14 '14 at 2:58
How nice to discover the bashful package! I'm sure it will come in handy quite often. –  Calaf Feb 14 '14 at 3:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.