0

I have this code:

\documentclass[varwidth,border=10pt]{standalone}
\usepackage{graphicx}
\newcommand{\MyBrand}{%
    \includegraphics[width=3em]{myBrand}%
}
\begin{document}
I always use \MyBrand , it's the best!
\end{document}

Which results in the following pdf:

I always use MyBr👌nd, it’s the best!

I want to be able to copy the complete text from the pdf to a text editor (Notpad, Word, …), including the text in the image.

When I mark the sentence in a pdf-Viewer (Adobe Acrobat) and copy it, I get "I always use , it’s the best!". But I want "I always use MyBr👌nd, it’s the best!".

So added an invisible tikz-layer fitted to the image width, in which I can type my text (because I used the resizebox, the text can even be very long):

\newcommand{\MyBrand}{%
    \includegraphics[width=3em]{myBrand}%
    \hspace*{-3em}%
    \resizebox{3em}{!}{%
        \tikz\node[inner sep=0pt, opacity=0]{myBrand};%
    }%
}

With the added tikz node I get "I always use myBrand, it’s the best!". That is a start, but I want "I always use MyBr👌nd, it’s the best!".

If I change the node to \tikz\node[inner sep=0pt, opacity=0]{myBr👌nd};, I get garbage like "I always use myBr￿nd, it’s the best!" when compiling with XeLaTeX and nothing with pdfLaTeX (inputenc Error).

How can I print ANY utf-8 character (even if the font doesn't have a symbol for it) for the purpose of copying it from the pdf into a text editor (which hopefully has an appropriate font)? Is there a solution for both Xe- and pdfLaTeX?

Again: I don't care if the symbol doesn't show up or shows as a placeholder… as long as it can be copied by marking the text in a pdf-Viewer and pasted to a text editor (where I can chose a font supporting all utf-8 characters).

1 Answer 1

2

You can use the accsupp package. But it won't work in every pdf-viewer, e.g. sumatra doesn't copy it.

\documentclass[]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,accsupp}
\usepackage[unicode]{hyperref}

\newcommand{\MyBrand}{%
\BeginAccSupp{method=pdfstringdef,unicode,ActualText={MyBr👌nd}}%
    \includegraphics[width=3em]{example-image}%
\EndAccSupp{}%    
}
\begin{document}

I always use \MyBrand, it's the best! 

\end{document}

Edit

as discovered in the comments it doesn't work if the picture is a bitmap (e.g. jpg or png). In this case one work-around is to a glyph, e.g.

  \rlap{.}\includegraphics[width=3em]{example-image.png}%
12
  • Thanks for your answer. I tried it with Acrobat Reader XI and it doesn't work (neither compiling with XeLaTeX, nor with pdfLaTeX). It just copy-pasted "I always use , it’s the best!" as if there were only the image. With what pdf-viewer did it work for you?
    – genericFJS
    Oct 23, 2017 at 9:41
  • Adobe reader dc. The example is for pdflatex, with lualatex you need also luatex85, i didn't try with xelatex. Do you have a current tex system? Oct 23, 2017 at 9:44
  • Yes, I have a full texlive 2017 installation (updated just now). I'm compiling with pdflatex -synctex=1 -interaction=nonstopmode -shell-escape %.tex. I tried opening it with Google Chrome and Microsoft Edge too, but it didn't copy anything from the "ActualText".
    – genericFJS
    Oct 23, 2017 at 9:53
  • I just installed Adobe Reader DC and I couldn't copy anything "from" the image as well. Just "I always use , it's the best!", as before :-(
    – genericFJS
    Oct 23, 2017 at 10:13
  • You really should use nonstopmode -- or if you do you should check the log ;-). My code works with a development version of hyperref. But I don't have the time now to check which commit enable the handling of this unicode range. Oct 23, 2017 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .