# Angle symbols which can be copy and pasted from PDF

I'm looking for a way to use the left and right narrow angle symbols (〈 〉, Unicode #3008, #3009) so that they are not changed when copy and pasted from a PDF.

These symbols are used e.g. by the doc package for \meta{...} and other formatting macros to indicate the content of an argument, e.g.: \command[〈options〉]{〈filename〉} would be written with |\command|\oarg{options}\marg{filename}. This package uses the \langle and \rangle math symbols. The problem with this is that if this code is copied from the generated PDF the symbols are changed to h and i, e.g.:\command[hoptionsi]{hfilenamei}.

Detexify now pointed me to \textlangle and \textrangle from the textcomp package. These angles are copied to ASCII angles < and >, respectively, which is much better already, but I like to have the correct narrow angles instead.

How can I insert this angles so that the can be copied correctly from the PDF? I tried to use [utf8]{inputenc} and insert them as Unicode symbols in VIM manually (CTRL+V u 3008 or 3009, respectively) but got an error that this symbols are not setup for this use. I need this for my ydoc class/package, an alternative to doc and ltxdoc and would like to avoid hassle with fonts and encoding as much as possible. This should work for PDFLaTeX and not just for XeLaTeX or LuaLaTeX.

With

\usepackage{cmap}


the two symbols may be associated to U+27E8 MATHEMATICAL LEFT ANGLE BRACKET and U+27E9 MATHEMATICAL RIGHT ANGLE BRACKET. If you want to input them directly, here it is how it can be done:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{cmap}
\usepackage{textcomp}
\usepackage{newunicodechar}
\newunicodechar{〈}{$\langle$} % U+27E8
\newunicodechar{〉}{$\rangle$} % U+27E9
\begin{document}
\textlangle\textrangle

〈〉
\end{document}


Another choice might be

\newunicodechar{〈}{\textlangle} % U+2329
\newunicodechar{〉}{\textrangle} % U+232A


You can use directly \DeclareUnicodeCharacter, of course, with

\DeclareUnicodeCharacter{2329}{$\langle$}
\DeclareUnicodeCharacter{232A}{$\rangle$}


instead of \newunicodechar.

This should allow to copy and paste the symbol from the PDF viewer, but it seems that the code of the copied character is viewer dependent, when \textlangle and \textrangle are used. :(

Thanks to Martin Scharrer for having suggested improvements to the answer.

• I was about to ask about the spaces around the angle brackets, but then I realized that those glyphs have a generous amount of space built in, at least with the fonts I am viewing this in. – Harald Hanche-Olsen May 13 '11 at 11:24
• You might have mentioned that the newunicodechar package can be found on CTAN. It is not in TeX Live 2010, and so the vast majority (?) of readers probably won't have it in their installations. – Harald Hanche-Olsen May 13 '11 at 11:28
• the newunicodechar package is in my tl2010 (updated yesterday) – wasteofspace May 13 '11 at 11:56
• @Harald: The first version of the package was uploaded to CTAN on February 18, and has been in TeX Live since one or two days later. The space indeed depends on the font the system decides to use for showing the symbol. – egreg May 13 '11 at 12:16
• I get the correct angles in the PDF, but copy and pasting under Ubuntu from Adobe Reader results in normal ASCII angles < >, exactly like with textcomp alone. If I use pdftotext I get Unicode angles. – Martin Scharrer May 13 '11 at 12:40

You can use glyphtounicode. Differently to cmap it will work with virtual fonts too.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\input{glyphtounicode.tex}
\pdfgentounicode=1
\pdfglyphtounicode{less}{3008}
\pdfglyphtounicode{greater}{3009}

\begin{document}

< >

\end{document}


If you compile with pdflatex you can copy the brackets e.g. to notepad. This will work fine, but in an ascii editor (e.g. winedt) the result is not correct.

Edit. I just remembered: Another possibility is accsupp. It work with pdftex, luatex + xetex:

\documentclass{article}
\usepackage{accsupp}
\begin{document}
\BeginAccSupp{method=hex,unicode,ActualText=3008}%
angleleft%
\EndAccSupp{}%

\end{document}