2

I am trying to define a label from a string with blanks to use with hyperref. But I get an error. The example below does not compile if the two lines with comments are uncommented. Is there a remedy for this?

\documentclass{article}
\usepackage{xstring}
\usepackage{color}
\usepackage{hyperref}

\def\animal{zebra with stripes}
\def\mylabel{\StrSubstitute{\animal}{ }{}}
\def\thelabel{zebrawithstripes}

\begin{document}
\hypertarget{\thelabel}{\noindent Here is a zebra.} \\
Go to \hyperlink{\thelabel}{\textcolor{blue}{\animal}}.\\

%\hypertarget{\mylabel}{\noindent Here is a zebra.} \\
%Go to \hyperlink{\mylabel}{\textcolor{blue}{\animal}}.\\

\mylabel

\end{document}
Rasmus
  • 141

1 Answers1

3

The non-expandable macros of package xstring have usually a tailing optional argument for a command that will contain the result:

\StrSubstitute{\animal}{ }{}[\mylabel]
Heiko Oberdiek
  • 271,626