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; -*-

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

  \def\,{ }%

which works fine.

  • You're probably looking for NewExpandableDocumentCommand, but with its limitations.
    – user202729
    Commented Jun 3, 2022 at 13:07
  • Not really. I can understand the question without one, but a MWE here helps us quickly confirm that our answer works before we post it.
    – user202729
    Commented Jun 3, 2022 at 13:08
  • 3
    You can redefine macros in pdf strings, see tex.stackexchange.com/a/330980/82917.
    – campa
    Commented Jun 3, 2022 at 13:09
  • I agree with campa, it is super useful to be able to change macros before they are used in pdf strings. Especially providing simpler expandable versions.
    – daleif
    Commented Jun 3, 2022 at 13:15
  • see e.g. tex.stackexchange.com/a/643568/2388 Commented Jun 3, 2022 at 13:23


You must log in to answer this question.

Browse other questions tagged .