# How to fix missing or incorrect mappings from glyphtounicode.tex

glyphtounicode.tex has been described as the best solution for generating copy-and-pasteable symbols. However, I find that various symbols that I need to use do not paste as the appropriate Unicode codepoints/characters. How can I fix this?

This is how my macros should be pasting:

• \nSubset: ⋐̸ (U+22D0 U+0338)
• \cong: ≅ (U+2245)
• \ncong: ≇ (U+2247)
• \bigcup: ⋃ (U+22C3)
• \notin: ∉ (U+2209)
• \neq: ≠ (U+2260)
• \llbracket: ⟦ (U+27E6); \rrbracket: ⟧ (U+27E7)
• \llparenthesis: (|; \rrparenthesis: |)
• Update: Unicode offers the symbol pairs ⦇ ⦈ (U+2987/U+2988) and ⦅ ⦆ (U+2985/U+2986), which many might consider a better choice for these macros.
• \coloneqq: ≔ (U+2254)
• \models: ⊧ (U+22A7) [currently |=]
• \Rsh: ↱ (U+21B1)
• \textlengthmark: ː (U+02D0) [currently :]
• \blackdiamond: ⬩ (U+2B29)
• \sqbullet: ▪ (U+25AA)
• \square: ▫ (U+25AB)

(Note: Earlier I erroneously stated that \neg pastes incorrectly as ￢ (U+FFE2) instead of ¬ (U+00AC). This is not correct: \neg pastes correctly; it's Word that replaces this by the other symbol, just as I noticed that Word doesn't copy all accented letters correctly from pdf-files (whereas they paste exactly right into Notepad). I actually don't know whether this is truly a Word issue (if so, it's likely a legacy encoding/font hack) or has to do with pdflatex or maybe the Unicode/non-Unicode clipboard distinction in Windows. Anyone feel free to add (non-ranty) insight into this.)

This is how they currently paste:

>; ; ;
S
; <; ,; J; K; L; M;B; |=;é; :; ˛; ‚; ˝


(The linebreaks before and after \bigcup ("S") are probably caused by it being a big operator, so they're nothing to worry about.)

Here is minimal example code:

\documentclass{article}
\input glyphtounicode % I am using the updated version from http://www.lcdf.org/type/ (lcdf-typetools-2.94.tar.gz).
\pdfgentounicode=1
\usepackage[T3,T1]{fontenc} % The T3-encoding is required by the tipa-package.
\usepackage[noenc,safe]{tipa} % \textlengthmark
\usepackage{txfonts}
\usepackage[only,llbracket,rrbracket,llparenthesis,rrparenthesis]{stmaryrd}
\usepackage[mathb]{mathabx}

\begin{document}

\noindent $$\nSubset; \cong; \ncong; \bigcup; \notin; \neq; \llbracket; \rrbracket; \llparenthesis; \rrparenthesis; \coloneqq; \models; \Rsh; \mbox{\textlengthmark}; \blackdiamond; \sqbullet; \square$$ \\

\noindent $$\nexists$$

\end{document}


The symbol ∄ (\nexists) at the end has been included to demonstrate that glyphtounicode.tex is compatible with my code, because it pastes correctly (and in fact requires a recent version of glyphtounicode.tex, see the comment in my code).

-

You can add your own definitions. Eg. here an example how to copy an "a" as "A":

\documentclass[a4paper,12pt]{article}

\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\input{glyphtounicode}

\pdfglyphtounicode{a}{0041} %0041=A
\pdfgentounicode=1
\begin{document}
aaaaa
\end{document}


The main problem is naturally to find the names of the glyphs you are using. In case you know the font you can find the names in the afm or the pfb. You can also add \pdfcompresslevel=0 to your document and then inspect the pdf. Look for lines starting with /CharSet (there will be more than one if you use more than one font). E.g. if I add \int to the example I will find /CharSet (/integraltext) and integraltext is the name of the glyph.

In case that the symbol is not a single glyph or that its name is not unique or changes from one font family to the next you will probably need to use the accsupp-package. Is it possible to provide alternative text to use when copying text from the PDF?.

-
Thanks, but that's exactly why I'm asking: I have no idea how to find the names of the glyphs that I am using. I also don't know what it means for a name to not be unique, and all of these involve macros I didn't define myself, so I don't actually know how to obviously and effectively use accsup with this (from superficial inspection). So ideally a solution would give me concrete fixes for the above symbols/macros. Also, some of these do have lines in glyphtounicode.tex (\pdfglyphtounicode{approximatelyequal}{2245}), so I am not sure what's going wrong. –  Lover of Structure Aug 8 '12 at 9:51
@user14996 I added some remarks how to find out the names. –  Ulrike Fischer Aug 8 '12 at 10:01
I appreciate your help and efforts, but I am not sure what difference the \pdfcompresslevel would make and what a pfb is. I also do not know how to know which font a given macro from a given package is using. Ideally one solution for each case (from someone) and I'll figure out the rest by myself. Sorry ... this is after looking at this for a couple of hours, and I'm a beginner as far as font matters are concerned. –  Lover of Structure Aug 8 '12 at 10:15
Sorry I didn't mean the pfb but the pdf. If you add \pdfcompresslevel=0 to your document and compile then the pdf is more or less a normal text file and you can open it in your editor. –  Ulrike Fischer Aug 8 '12 at 10:37
If you wrap a mathematical symbol e.g. in braces this "hides" its "math meaning" and so can affect spacing. E.g. $a=b$ has a very different spacing to $a{=}b$ as in the second case the = is not longer a relation. –  Ulrike Fischer Aug 17 '12 at 8:20

The following concrete solution is based on Ulrike Fischer's answer:

Solution, part 1 (using \pdfglyphtounicode): The following lines help with the first batch of symbols:

\pdfglyphtounicode{notsubsetdbl}{22D0 0338}
\pdfglyphtounicode{simequal}{2245}
\pdfglyphtounicode{notsimequal}{2247}
\pdfglyphtounicode{uniontext}{22C3}
\pdfglyphtounicode{nelement}{2209}
\pdfglyphtounicode{nequal}{2260}
\pdfglyphtounicode{llbracket}{27E6}
\pdfglyphtounicode{rrbracket}{27E7}
\pdfglyphtounicode{llparenthesis}{0028 007C}
\pdfglyphtounicode{rrparenthesis}{007C 0029}
\pdfglyphtounicode{colonequal}{2254}


The macros \models, \Rsh, \textlengthmark, \blackdiamond, \sqbullet, \square seem to require the accsupp package. In the pdf-file, they are handled with the following glyphnames respectively: bar + equal, eacute, colon, ogonek, quotesinglbase, hungarumlaut. This explains their pasting behavior; these are names with normally different meanings, namely the ones shown by what's being pasted.

Solution, part 2 (using the package accsupp): The following code creates new "Unicode-compatible" commands. A user will of course need to replace the old commands with these new ones (\models by \Umodels etc.). The math character classes (mathord etc) used here are based on my unique needs.

\RequirePackage{accsupp} % Unicode-pastable versions of symbols
\newcommand*{\Umodels}{\BeginAccSupp{method=hex,unicode,ActualText=22A7}\mathrel{\models}\EndAccSupp{}}
\newcommand*{\URsh}{\BeginAccSupp{method=hex,unicode,ActualText=21B1}\mathord{\Rsh}\EndAccSupp{}}
\newcommand*{\Utextlengthmark}{\BeginAccSupp{method=hex,unicode,ActualText=02D0}\textlengthmark\EndAccSupp{}}
\newcommand*{\Ublackdiamond}{\BeginAccSupp{method=hex,unicode,ActualText=2B29}\mathord{\blackdiamond}\EndAccSupp{}}
\newcommand*{\Usqbullet}{\BeginAccSupp{method=hex,unicode,ActualText=25AA}\mathord{\sqbullet}\EndAccSupp{}}
\newcommand*{\Usquare}{\BeginAccSupp{method=hex,unicode,ActualText=25AB}\mathord{\square}\EndAccSupp{}}


(To those who are wondering, the value of ActualText can also be a space-separated list of hexadecimal UTF-16 values. Note that these are not Unicode codepoints but their UTF-16 representation (these are not identical for characters outside of Unicode's basic multilingual plane, BMP). For more information on how to paste Unicode characters outside of the BMP, see this question/answer.)

Bonus addendum: How to fix existing \pdfglyphtounicode assignments: If you would like to change an existing assignment such as U+25C1 for \lhd (glyphtounicode.tex contains the line \pdfglyphtounicode{triangleleft}{25C1}), simply reinvoke the \pdfglyphtounicode macro after the line \input glyphtounicode; for example you may write \pdfglyphtounicode{triangleleft}{22B2}, which will override the original definition.

-