1

I'm trying to switch to and from a Dingbats font using ucharclasses, and I'm failing to obtain correct results. Here's my MWE:

\documentclass[border=0.2in,varwidth]{standalone}
\usepackage{fontspec}
\usepackage{ucharclasses}

\newfontfamily{\dingbatsfont}{Zapf Dingbats}

\setTransitionTo{Dingbats}{\dingbatsfont}
\setTransitionFrom{Dingbats}{\rmfamily}

\begin{document}
I award you a ✓︎, which is what you deserve.
\end{document}

Here's what I'm getting: Bad result.

It appears that the transition from the Dingbats block isn't happening. I tried changing the \setTransition... code to

\setTransitionTo{Dingbats}{[entering dingbats] \dingbatsfont}
\setTransitionFrom{Dingbats}{\rmfamily [exiting dingbats]}

and obtained Another bad result.

which seems to confirm that this.

2 Answers 2

1

You do not necessarily want to switch to \rmfamily when you transition from a block. The correct behavior would be to switch back to the font you were using before. You can accomplish this by changing the font between a \begingroup and \endgroup.

There are numerous bugs in ucharclasses: not only does the transition from Dingbats never get called, the \setTransitions macro documented in the manual does not exist. However, another workaround is to set the default transitions to \begingroup and \endgroup. The default transition out does (erroneously) get called instead.

This is really iffy, since actually enabling the character class I use breaks it.

\tracinglostchars=2 % Show a warning for missing characters
\documentclass[border=0.2in,varwidth]{standalone}
\usepackage{fontspec}
\usepackage{ucharclasses}

\newfontfamily{\dingbatsfont}{DejaVu Sans}[Scale = MatchUppercase]

\setDefaultTransitions{\begingroup}{\endgroup}
\setTransitionsForSymbols{\begingroup\dingbatsfont}{\endgroup}

\begin{document}
\sffamily I award you a ✓︎, which is what you deserve.
\end{document}

Font sample

Your patch, \XeTeXinterchartoks \DingbatsClass 0 =, also works here.

\tracinglostchars=2 % Show a warning for missing characters
\documentclass[border=0.2in,varwidth]{standalone}
\usepackage{fontspec}
\usepackage[Dingbats]{ucharclasses}

\newfontfamily{\dingbatsfont}{DejaVu Sans}[Scale = MatchUppercase]

\setTransitionTo{Dingbats}{\begingroup\dingbatsfont}
\setTransitionFrom{Dingbats}{\endgroup}
% Workaround for a bug in ucharclasses:
\XeTeXinterchartoks \DingbatsClass 0 = {\endgroup}

\begin{document}
\sffamily I award you a ✓︎, which is what you deserve.
\end{document}
4
  • Thanks; I like your solution better than mine.
    – Derek
    May 19, 2020 at 13:14
  • Glad I could help! That’s why we ask questions.
    – Davislor
    May 19, 2020 at 15:56
  • @Derek And I learned several things from your answer. Although they should probably be reported to the package maintainer as bugs.
    – Davislor
    May 19, 2020 at 15:57
  • As far as I can tell, there isn't a current package maintainer.
    – Derek
    May 19, 2020 at 19:05
0

It turns out that ucharclasses doesn't fully cover this case. Apparently (as far as I can tell), switching out of Dingbats is equivalent to ending a "word", which needs to be handled as special case. The workaround is to add

\XeTeXinterchartoks \DingbatsClass 0 = {\rmfamily [exiting dingbats]}

which produces the expected result:

Fixed!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .