3

Is there a way to make text written in LateX look like something in the pdf document, but different if you copy-paste it?

Here is an example of what I would like:
In the pdf document: there is 10 km to the city
when you copy-paste: there is 10 kilometers to the city

added after reply: Thank you all.

However, I also want to do it when writing by using $$.

As an example again, If I write: for water $\rho$ is 997 $kg/m^3$

PDF: for water rho is 997 kg/m^3 copy-paste: for water the density is 997 kilograms per cubic meter

Kevin
  • 73
  • 4

1 Answers1

5

This is doable with the accsupp package however be warned it only works on some PDF viewers. It works for me with Adobe Acrobat Pro, but not with Apple Preview. The general form is \BeginAccSupp{ActualText={what gets pasted}} what gets copied \EndAccSupp{} so we can define a \km command that will do what you want.

\documentclass{article}
\usepackage{accsupp}

\newcommand\km{\BeginAccSupp{ActualText={kilometers}}km \EndAccSupp{}}

\begin{document} there is 10 \km to the city \end{document}

enter image description here

copy/pastes:

there is 10 kilometers to the city

Dan
  • 3,699