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.

I'm asking for help with the creation of a label inside a command out of a given text. The given text contains spaces and an umlaut. See my MWE, which contains my question:

\documentclass[pagesize, english, fontsize=12pt, parskip=half]{scrartcl}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, xspace, tocbasic}



\newcounter{Anl}
\newcommand{\Anlv}[1]{%
  \refstepcounter{Anl}%
  \textit{attachment \theAnl{}\xspace}%
  \addtocontents{anl}{%
    \mdseries{}Attachment \theAnl{}: #1\newline%{}{}%
  }%
%  \label{ANL:#1}% REMOVE THE FIRST % AND YOU GET AN ERROR
}
\DeclareNewTOC[%
type=anlverz,%
types=anlverzes,%
nonfloat,%
name=Anlagen,%
listname={Attachments:}%
]{anl}



\begin{document}

Above you see a new command which I use to add attachments to my
texts. Often I need to refer to an attachment, e.g. see the Map of Özß
(\Anlv{Map of Özß, map scale 1:2500}).

I'd like to get a label automatically. But as soon as there are spaces
in the name (here: »Map of Özß, map scale 1:2500«) or an umlaut or an
»ß«, I get an error and no label.

Can anybody write a macro which constructs a usefull label out of the
given name of an attachment? Here in my example »Map of Özß, map scale
1:2500« simply the first word (»Map«) as a label (\verb"\label{ANL:Map}")
would be an improvement, but there may be more than one attachment
with a map. So the best solution for my example, if possible, were:
\verb"\label{ANL:Map-of-Oezss}", because you can replace an »Ö« with
»Oe« and an »ß« with »ss«.


\listoftoc{anl}

\end{document} 
share|improve this question
    
My advice is usually "don't rely on automatic generation of labels". Are the arguments of \Anlv always in the form <text>, <attribute> or can they be different? –  egreg Oct 8 '12 at 10:42
    
@egreg They always will be simple text, which aims to be read and understood by the readers of the whole text. –  Keks Dose Oct 8 '12 at 10:54
1  
I'd set up things so that you input \Anlv{Map of Özß, map scale 1:2500}{Map-of-Özß}, using Heiko's answer method for making the second argument into a usable reference key. Using the first argument (possibly truncated at the comma) is sensitive to input, particularly if the phrase is long. –  egreg Oct 8 '12 at 11:02

1 Answer 1

up vote 3 down vote accepted

The following example converts the problematic string to a hexadecimal string that works with \label:

\documentclass[pagesize, english, fontsize=12pt, parskip=half]{scrartcl}
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}
\usepackage{babel, xspace, tocbasic}
\usepackage{pdfescape}

\makeatletter
\newcounter{Anl}
\newcommand*{\MakeAnlLabel}[2]{%
  \begingroup
    \set@display@protect
    \let\IeC\@firstofone
    \EdefEscapeHex\@temp{#2}%
  \edef\@temp{%
    \endgroup
    \def\noexpand#1{\@temp}%
  }%
  \@temp
}
\newcommand*{\Anlv}[1]{%
  \refstepcounter{Anl}%
  \textit{attachment \theAnl}%
  \addtocontents{anl}{%
    \mdseries Attachment \theAnl: #1%
  }%
  \MakeAnlLabel\tmp{#1}%
  \label{ANL:\tmp}%
}
\newcommand*{\anlref}[1]{%
  \MakeAnlLabel\tmp{#1}%
  \ref{ANL:\tmp}%
}
\DeclareNewTOC[%
type=anlverz,%
types=anlverzes,%
nonfloat,%
name=Anlagen,%
listname={Attachments:}%
]{anl}
\makeatother

\begin{document}

Above you see a new command which I use to add attachments (example
for a reference: \anlref{Map of Özß, map scale 1:2500}) to my texts.
Often I need to refer to an attachment, e.g.\@ see the Map of Özß
(\Anlv{Map of Özß, map scale 1:2500}).

\listoftoc{anl}

\end{document}

Result

share|improve this answer

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.