# pasting small circled (\textcircled) letters leads to incorrect (reversed) Unicode codepoint sequence for combining circle

When I try to circle a small letter, compile (using glyphtounicode.tex), and then paste the resulting text, the combining circle (U+20DD) appears before the letter (here: "b") even though it, being a Unicode combining character, should always appear after.

\documentclass{article}
\input glyphtounicode
\pdfgentounicode=1
%\usepackage{accsupp}

%\newcommand*{\textcircledcorrected}[1]{\BeginAccSupp{method=hex,unicode,ActualText=???? 20DD}\textcircled{#1}\EndAccSupp{}}

\begin{document}
a\textcircled{\tiny b}c
%a\textcircledcorrected{\tiny b}c
\end{document}


(This problem does not arise when the letter is of sufficient size.)

When I try to fix this using accsupp (see the commented-out lines above), I run into an impasse: If I use the method=hex and unicode options, I can specify the combining circle (U+20DD) as 20DD, but I'd need to convert the letter argument (#1) to its Unicode codepoint, or I'd need some way of specifying the U+20DD character otherwise (using perhaps the method=pdfstringdef option) while keeping the #1-argument as is.

Unfortunately I cannot use UTF-8 as the input encoding on my system.

Is there a good way of defining a \textcircledcorrected command (using accsupp I suppose) that always pastes the combining circle after the enclosed character?

-

\pdfstringdef supports \textcircled, thus the following works, if #1 contains one symbol:

\documentclass{article}
\input glyphtounicode
\pdfgentounicode=1

\usepackage[pdfencoding=auto]{hyperref}
\usepackage{accsupp}

\newcommand*{\textcircledcorrected}[1]{%
\BeginAccSupp{
method=pdfstringdef,
unicode,
ActualText={\textcircled{#1}},%
}%
\textcircled{#1}%
\EndAccSupp{}%
}

\begin{document}

a\textcircledcorrected{\tiny b}c

\end{document}


BTW, without accsupp the PDF code contains the characters in the right order, #1 comes first, then the circle. Because of the overlapping, the circle is put a little to the left. The amount of the left shift is larger for the letter in \tiny. Thus it depends on the heuristics, how to deal with that in the PDF viewer. Your PDF viewer apparently decided to switch the characters in that case.

-