The solution to this problem is probably something absurdly simple, but I'm too stupid to see it …
Consider a document written in blackletter. German blackletter typography rules require latin words and uppercase abbreviations to be set in antiqua. I have followed the advice of the fontspec package and created a new font family and a little \antiqua-macro. This works perfectly inside text paragraphs, because I know if I want a serif or a sans-serif typeface. However, I am not able to create something, that would render the antiqua part in sans-serif in the section title itself, while turning the same thing to the corresponding serif typeface in the table of contents … What's the simple solution?
\documentclass[12pt,a4paper,twoside]{scrreprt}
{numerous other packages}
\usepackage{mathspec} %loads fontspec
\setmainfont[Mapping=tex-text]{UnifrakturMaguntia} % for blackletter
\setsansfont[Mapping=tex-text]{UnifrakturCook} % for headers,
\newfontfamily\antiquafont[Mapping=tex-text]{LiberationSerif} %antiqua serif typeface
\newfontfamily\antiquasans[Mapping=tex-text]{LiberationSans} %antiqua sans-serif typeface
\newcommand\antiqua[1]{{\antiquafont #1}} %creates my antiqua-macro
\newcommand\antisans[1]{{\antiquasans #1}} %creates a similar macro for sans-serif antiqua typing
\begin{document}
\tableofcontents
\chapter{My Blackletter Text about \antisans{NMR}}
So any appearance of the abbreviation \antiqua{NMR,} other abbreviations,
other paragraph text \antiqua{etc.} can be set perfectly here, but
the \antiqua{NMR}-part in the table of contents will be sans-serif, which
it mustn't.
\end{document}
If I'm perfectly honest I wouldn't have expected this code to work without flaws, because there is no connection between the serif and the sans-serif part (save the fact that the name starts with the same word). The minimal example can of course be worked with any other combination of two fonts different enough to tell them apart.

pdftexcmds– egreg Sep 11 '16 at 21:41