Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

A possible solution would be to define a switch that defines whether the command appears in the main text or inside a section heading, and that is called automatically by section headings

\documentclass[12pt,a4paper,twoside]{scrreprt}

\usepackage{etoolbox}

\usepackage{mathspec} %loads fontspec
\setmainfont[Mapping=tex-text]{Times} % for blackletter
\setsansfont[Mapping=tex-text]{Arial} % for headers,
\newfontfamily\antiquafont[Mapping=tex-text]{Optima} %antiqua serif typeface
\newfontfamily\antiquasans[Mapping=tex-text]{Courier} %antiqua sans-serif typeface
\newcommand\antiqua[1]{{\antiquafont #1}} %creates my antiqua-macro
\newcommand\antisans[1]{{\iftoggle{insection}{\antiquasans #1}{\antiquafont #1}}} %creates a similar macro for sans-serif antiqua typing

\newtoggle{insection}

\makeatletter    
\renewcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
  \thispagestyle{\chapterpagestyle}%
  \global\@topnum\z@
  \@afterindentfalse
  \toggletrue{insection}
  \secdef\@chapter\@schapter
}
\renewcommand\section{\@startsection{section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\toggletrue{insection}\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@section}%
}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
  {-3.25ex\@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus .2ex}%
  {\toggletrue{insection}\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
    \setlength{\parfillskip}{\z@ plus 1fil}\fi
    \raggedsection\normalfont\sectfont\nobreak\size@subsection
  }%
}
\makeatother


\begin{document}
\tableofcontents
\chapter{My Blackletter Text about \antisans{NMR}}
So any appearance of the abbreviation \antiqua{NMR,} \textsf{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.

\chapter{Test \antisans{Test}}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\end{document}

Caveat: One has to redefine all section commands (e.g., part, section, subsections ...) and insert the switch in the right place.

share|improve this answer
    
Thanks for this answer. I thought I might add that there are no chapters in my actual document that would require this, only sections and subsections. Just copying the chapter-commands and replacing 'section' where it says 'chapter' doesn't do the job unfortunately. –  Jan Jul 30 '12 at 8:23
add comment

I think that what you need to do is to augment the instruction

\chapter{My Blackletter Text about \antisans{NMR}}

to

\chapter[My Blackletter Text about \antiqua{NMR}]{My 
   Blackletter Text about \antisans{NMR}}

i.e., you need to provide an optional argument which tells (Xe)LaTeX how the chapter header should be typeset in the Table of Contents.

Addendum From some of the follow-up comments I take it that you would like to fully automate this process, i.e., you would rather not to have to write the optional argument(s) of the various sectioning commands. I don't have a clear idea how this might be done, but I suspect that it would require some serious re-coding of the sectioning commands.

share|improve this answer
    
Thanks for the simple answer. Although I would also like an automatic solution, if there is one; since I'm not too keen on copying a (few) two-line-title(s) again just to add the one difference of tag (which occurs a few times in the long IUPAC names of chemicals) … ;) –  Jan Jul 29 '12 at 21:03
    
@Jan - Without access to the fonts to actually execute your MWE, I'm afraid I'm in a position to work out all the programming. Maybe somebody else will come up with an extended solution. Do note that I've managed to simplify the suggested solution (by no longer requiring a \protect instruction). Just how many sectioning headers does your document have that might require attention of the nature implied by your question? –  Mico Jul 29 '12 at 21:21
    
UnifrakturMaguntia can be downloaded [here] (unifraktur.sourceforge.net/maguntia.html), UnifrakturCook is not far down the way. Liberation is standard on Linux environments, so it's probably downloadable somewhere only I don't know where. I don't see any reason though, why it should not work with any combination of two fonts? It's 17 headings, of which three contain quite a few \antisans-tags. –  Jan Jul 29 '12 at 21:35
    
@Jan - thanks for providing the links; I've installed the fonts and was able to verify that my suggested solution indeed does the job. :-) However, as I note in an addendum to the answer, I can't see a way of making your objective of fully automating the process, at least not without some major rewriting of all sectioning commands. In the end, it may be less effort for you to provide the optional arguments of the sectioning commands by hand. This shouldn't be so hard to do anyway, right: You copy the argument of the sectioning command, paste it into [], and then do a search-and-replace. –  Mico Jul 30 '12 at 0:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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