1

I am trying to build a controlled dictionary. I used a template where it's defined a command to insert a new entry. I would like to assign a label to each entry so that I can link similar terms with hyperref package. If I insert the label each time it works but it's quite a tedious task. I would like to insert the label with the same name of the entry, directly in the command as shown in my attempt below however it does not work. I studied this question but I could not find a solution to my problem.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[a4paper, margin=20mm]{geometry}
\usepackage{hyperref}  
\newcommand{\entry}[4]{ \scriptsize{\markboth{#1}{#1}\textbf{#1}\ {(#2)}\ \textit{#3}\ $\bullet$\ {#4}}} 
%my atempt
\newcommand{\autoentry}[4]{\label{ter:{#1}}\scriptsize{\markboth{#1}{#1}\textbf{#1}\ {(#2)}\ \textit{#3}\ $\bullet$\ {#4}}} 

\begin{document}
% expected behaviour but slow
\entry{myword}{myword}{ \label{ter:myword} masdfa asldkfj asld}{test}
% my attempt  
\autoentry{myword2}{myword2}{ masdfa asldkfj asld}{test}



\hyperref[ter:myword]{myword}
\hyperref[ter:myword2]{myword2}
\end{document}

The error that I've got is this one:

You have referenced something which has not yet been labelled. If you have labelled it already, make sure that what is written inside \ref{...} is the same as what is written inside \label{...}.

2
  • 1
    Remove the braces in the label: \label{ter:#1}. Apr 9 '20 at 12:00
  • Thanks this solved the problem, if you formalize this in an answer I can close this question.
    – G M
    Apr 9 '20 at 13:23
1

With \label{ter:{#1}} the inner braces are part of the label name. They are stored in aux-file:

\newlabel{ter:{myword2}}{{}{1}{}{Doc-Start}{}}

So either remove them in your definition

\label{ter:#1}

Or add the braces to the reference:

\hyperref[ter:{myword2}]{myword2}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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