2

I am using \foreignlanguage{russian}{#1} command over-and-over in my document and for that I have created a new command \NewDocumentCommand {\ru}{+m}{\foreignlanguage{russian}{#1}}.

Now, as soon as I use this \ru in places like \section, XeLaTeX throws the (in)famous error

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `\ru' on input line XXX.

To fix that, we of course have \texorpdfstring but the issue is that I have to type it so many times, and such a big glob of text makes the whole document unreadable. For example, to get rid of this warning, I have to type \texorpdfstring{\ru{ъ}}{ъ} where a simple \ru{ъ} would have done the trick.

To fix this, I created another command:

\NewDocumentCommand {\sru}{+m}{\texorpdfstring{\foreignlanguage{russian}{#1}}{#1}}

This command, presumably, would have gotten rid of the error. However, now I am getting the error:

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `\sru' on input line XXX.

Is there any way to shorten this whole structure and get rid of the above warning?

2

You can use \NewExpandableDocumentCommand so it expands and the texorpdf switch is seen at the right time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.