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.

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.

share|improve this question
    
In theory this could also be fixed using the answer to Is it possible to provide alternative text to use when copying text from the PDF?, For the angles this would be overkill, but it might be good for other symbols. –  Martin Scharrer May 18 '11 at 10:30
add comment

2 Answers

up vote 12 down vote accepted

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.

share|improve this 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
show 9 more comments

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}
share|improve this answer
add comment

Your Answer

 
discard

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.