0

Good evening, everybody. After having read lots of your formidable Q&A's (thank you for the insights) I am struggling hard with this problem and would like to pose a question:

What I intend to do is derive from the content of a part (which functions as a book title in a collection of handbooks) only a special substring (which can be derived by cropping after a " - " and (apart from outputting it) make an entry to the index.

This works "by hand" using the following MWE (problematic part commented out):

\documentclass[a4paper,11pt,parskip=full]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage{xstring}
\usepackage{nameref}
\usepackage{imakeidx}
\usepackage{hyperref}

\makeindex

\newtoks\VATemp{}

\makeatletter
\newcommand{\getnamereftext}[1]{%
  \@ifundefined{r@#1}{}{%
    \unexpanded\expandafter\expandafter\expandafter{%
      \expandafter\expandafter\expandafter\@thirdoffive\csname r@#1\endcsname
    }%
  }%
}
\makeatother

\newcommand{\VA}[1]{
    \StrBehind{\getnamereftext{VA #1-Start}}{ - }[\VATemp]
    \index{VA #1 - \VATemp}%
}

\begin{document}
\part{Verfahrensanweisung 145-1.8 - Just a Test}% ä to test for Umlaut
\label{VA 145-1.8-Start}

\VA{145-1.8}

\printindex

\end{document}

EDIT: When I use an "ä" in the title of a part, I don't get any index entry (or so it seems). To be exact, main.idx contains the following:

\indexentry{VA 145-1.8 - Just \unhbox \voidb@x \bgroup \U@D 1ex{\setbox \z@ \hbox {\char 127}\dimen@ -.45ex\advance \dimen@ \ht \z@ \fontdimen 5\font \dimen@ }\accent 127\fontdimen 5\font \U@D a\egroup Test|hyperpage}{1}

which means, that the Umlaut is expanded very strangely (and leads to an error concerning UTF-8 in Overleaf).

Does anybody know a way around this? Will I have to look at the extraction of thepartname by nameref or rather at the indexing process...? Or did I miss any Options in inputenc / imakeidx or any other package?

1

1 Answer 1

1

The problem can be solved by using \noexpandarg so the string is not subject to full expansion, which would remove the \unexpanded protecting it.

However, one further expansion step is needed in order to remove \@thirdoffive.

Instead of the standard \expandarg used by xstring, a single \edef that will remove \unexpanded, but not doing further expansion, is used.

\documentclass[a4paper,11pt,parskip=full]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage{xstring}
\usepackage{nameref}
\usepackage{imakeidx}
\usepackage{hyperref}

\makeindex

\makeatletter
\newcommand{\getnamereftext}[1]{%
  \@ifundefined{r@#1}{}{%
    \unexpanded\expandafter
    \expandafter\expandafter\expandafter
    \expandafter\expandafter\expandafter
      {%
       \expandafter\expandafter\expandafter\@thirdoffive\csname r@#1\endcsname
      }%
  }%
}
\makeatother

\newcommand{\VA}[1]{%
  \begingroup\noexpandarg
  \begingroup\edef\x{\endgroup
    \noexpand\StrBehind
    {\getnamereftext{VA #1-Start}}}%
  \x{ - }[\VATemp]%
  \index{VA #1 - \VATemp}%
  \endgroup
}

\begin{document}
\part{Verfährensanweisung 145-1.8 - Just a Test}% ä to test for Umlaut
\label{VA 145-1.8-Start}

\VA{145-1.8}

\printindex

\end{document}
1
  • Thank you so much! I will edit my first post so the space will be saved (sorry for that)! You saved me a lot of headache!
    – Nils
    Feb 28, 2020 at 15:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .