I use \,, \thinspace and my own hairspace-command \hrsp all the time, but I don't want to care whether it's used in a pdf-string (often in sectioning- and cite-commands), which is to get rid of Package hyperref Warning: Token not allowed in a PDF string (Unicode): (hyperref) removing \hrsp on input line 334.
I want to (re-)define the command so that they do different things whether used in TeX or PDF string, perhaps by means of \texorpdfstring{}{}.
We don't need a MWE, all we need is:
% -*- mode: latex; TeX-engine: luatex; coding: utf-8; -*-
\usepackage[twothirds]{thinsp}
\NewDocumentCommand{\hrsp}{}{\ifmmode\mskip1mu\else\kern.08333em\fi}
As PDF string \hrsp should do nothing, i.e. insert no space at all, whereas \, should insert an ordinary interword-space when \thinspace is not able to be used.
OK, I added to my preamble
\pdfstringdefDisableCommands{%
\def\,{ }%
\def\hrsp{}%
}
which works fine.
NewExpandableDocumentCommand, but with its limitations. – user202729 Jun 03 '22 at 13:07