# Problems with accsupp and microtype

I was building on egreg's solution to this question to provide missing accented characters for my document. I also added accsupp to make sure that the text is searchable.

Unfortunately, there seems to be a problem with accsupp and microtype:

\documentclass{article}
\usepackage{microtype}
\usepackage{fontspec}
\usepackage{newunicodechar}
\usepackage{accsupp}

\makeatletter \let\d\relax \DeclareRobustCommand{\d}[1]
{\hmode@bgroup
\o@lign{\relax#1\crcr\hidewidth\ltx@sh@ft{-1ex}.\hidewidth}\egroup}
\let\.\relax
\makeatother

\newunicodechar{Ḍ}{%
\BeginAccSupp{method=hex,unicode,ActualText=1e0c}%
\d{D}%
\EndAccSupp{}%
}

\begin{document}
Ḍ
\end{document}


Not that the MWE works flawlessy, if microtype is commented out. With microtype enabled, it breaks.

• It breaks also without accsupp. microtype seems not to like a redefined Ḍ when loading the character tables. You can try to delay the redefinition with \AtBeginDocument. – Ulrike Fischer Oct 22 '18 at 10:37
• @UlrikeFischer I have no problems without accsupp. A simple \newunicodechar{Ḍ}{\d{D}} does not seem to bother microtype. \AtBeginDocument does indeed fix the problem though. – Simifilm Oct 22 '18 at 11:04
• I meant that depending on the definition it can also break without accsupp. The problem is that acc supp is not robust. You could also move the accsupp setting inside the definition \d, or define a robust variant. – Ulrike Fischer Oct 22 '18 at 11:19

Adding \protect in front of \BeginAccSup and \EndAccSup reveals the issue, via the warning

Package microtype Warning: Unknown slot number of character
(microtype)                Ḍ (= \BeginAccSupp{method=hex,unicode,ActualText=1e0c}\d {D}\EndAccSupp{})'
(microtype)                in font encoding TU'.
(microtype)                Make sure it's a single character
(microtype)                (or a number) in inheritance list
(microtype)                mt-LatinModernRoman.cfg/105(protrusion)'.


The error without the \protect happens at begin document, where microtype delays some setting.

In order to avoid prematurely redefining Ḍ, use \AtBeginDocument, so the conflict with microtype doesn't happen. This may have some consequences on protrusion, but already doing tricks for coping with missing characters in the font is bound to have typographic consequences.

\documentclass{article}
\usepackage{microtype}
\usepackage{fontspec}
\usepackage{newunicodechar}
\usepackage{accsupp}

\makeatletter
\let\d\relax
\DeclareRobustCommand{\d}[1]{%
\hmode@bgroup
\o@lign{%
\relax#1\crcr
\hidewidth\ltx@sh@ft{-1ex}.\hidewidth
}%
\egroup
}
%\let\.\relax
\makeatother

\AtBeginDocument{%
\newunicodechar{Ḍ}{%
\BeginAccSupp{method=hex,unicode,ActualText=1e0c}%
\d{D}%
\EndAccSupp{}%
}%
}

\begin{document}
Ḍ
\end{document}


I'm not sure about why doing \let\.\relax`, so I commented it out.

• Thanks a lot! The commenting out was a copy/paste problem. – Simifilm Oct 22 '18 at 11:21
• Thanks. After successfully compiling it, I made an interesting discovery. While I can now search for and copy/paste the character Ḍ with macOS's Preview, I can't do this in TeXShop's preview window although they supposedly use the same PDF routines … – Simifilm Oct 22 '18 at 13:41
• @Simifilm Funny. – egreg Oct 22 '18 at 13:50