fontslatex

How to create invisible, but copiable, text with LaTeX?


I want to produce a .pdf document using LaTeX that has text that would look like:

Here is some example text.

But when that text is highlighted and copied and pasted the result is:

Here is some secret message example text.

I've seen this done using HTML and other means, but wondering if it's possible in LaTeX. The closest I've got is

Here is some\makebox[0pt]{\textcolor{white}{ secret message}} example text.

But this leaves the text looking weird (I think the white text is overlayed on top of the black text).

Thanks!


Solution

  • Instead of a centred makebox, which will overlap half of the text on top of the previous text, you could left align the box.

    Alternatively, you could also change the transparency of the text.

    \documentclass{article}
    
    \usepackage{xcolor}
    \usepackage{transparent}
    
    \begin{document}
    
    Here is some\makebox[0pt][l]{\textcolor{white}{ secret message}} example text.
    
    Here is some\makebox[0pt]{\texttransparent{0}{ secret message}} example text.
    
    \end{document}