Is there a way to define some extra kerning around the en-dash – (Unicode) or -- (TeX ligature), when it is surrounded by digits in XeTeX? For – I can use \XeTeXinterchartoks, but this doesn’t work for --.
% !TeX program = xelatex
\documentclass{article}
\usepackage{fontspec}
\XeTeXinterchartokenstate = 1
\newXeTeXintercharclass \enDashCharacterClass
\newXeTeXintercharclass \digitsCharacterClass
\XeTeXcharclass `– \enDashCharacterClass
%\XeTeXcharclass `- \enDashCharacterClass
\XeTeXcharclass `0 \digitsCharacterClass
\XeTeXcharclass `1 \digitsCharacterClass
\XeTeXcharclass `2 \digitsCharacterClass
\XeTeXcharclass `3 \digitsCharacterClass
\XeTeXcharclass `4 \digitsCharacterClass
\XeTeXcharclass `5 \digitsCharacterClass
\XeTeXcharclass `6 \digitsCharacterClass
\XeTeXcharclass `7 \digitsCharacterClass
\XeTeXcharclass `8 \digitsCharacterClass
\XeTeXcharclass `9 \digitsCharacterClass
% adding dots for testing only
\XeTeXinterchartoks \digitsCharacterClass \enDashCharacterClass {.\kern0.05em.}
\XeTeXinterchartoks \enDashCharacterClass \digitsCharacterClass {.\kern0.05em.}
\begin{document}
\textbf{works}
test – test
0 – 0
0–1–2–3–4–5–6–7–8–9–0
\bigskip
\textbf{doesn't work}
test -- test
0 -- 0
0--1--2--3--4--5--6--7--8--9--0
\bigskip
\textbf{should not be kerned}
42-storey building
\end{document}
This gives the following result: Only the en-dashes entered as real en-dashes (–) are kerned, the ones entered as TeX ligature (--) not:
If we uncomment one line in the MWE and ad the hyphen (-) to the en-dash class the ligatures (--) get kerned too. But unfortunately this also affects single hyphens which should not be kerned:
Note: The dots are only for testing.




Presumably to achieve what you want you'll need also to use
– Bruno Le Floch Jul 04 '16 at 10:06\@ifnextchar.