Discussion:
enumitem: \ref a custom item
(too old to reply)
Alexander Zimmermann
2010-04-14 10:29:57 UTC
Permalink
Hi all,

at one point I want to switch from numbers to custom label in my
enumeration. No problem so far. However, when want to reference the
custom label later on (\ref or \autoref), I get "item (1)" and not
the desired "item (R)". How could I fix it?


Alex
--
\documentclass{article}
\usepackage{enumitem, hyperref}
\pagestyle{empty}
\begin{document}


\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\item[(R)]\label{step:RTO}
Waiting for an retransmission timeout
\item\label{step:2}
If something happen, then goto \autoref{step:ende}, else
\autoref{step:RTO}
\item\label{step:ende}
End
\end{enumerate}
\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Heiko Oberdiek
2010-04-14 11:57:05 UTC
Permalink
Post by Alexander Zimmermann
at one point I want to switch from numbers to custom label in my
enumeration. No problem so far. However, when want to reference the
custom label later on (\ref or \autoref), I get "item (1)" and not
the desired "item (R)". How could I fix it?
\documentclass{article}
\usepackage{enumitem, hyperref}
\pagestyle{empty}
\begin{document}
\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\item[(R)]\label{step:RTO}
Waiting for an retransmission timeout
It's a defiency in LaTeX: \label refers to \refstepcounter, but the
optional argument of \item suppresses the call of \refstepcounter.

Workaround:

\documentclass{article}

\makeatletter
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin\csname phantomsection\endcsname
}%
}%
\***@edef\@currentlabel{#1}
\label{#2}%
\ignorespaces
}
\makeatother

\usepackage{enumitem, hyperref}

\begin{document}
\ref{first}, \ref{foo}, \ref{last}
\begin{enumerate}[
label=(\arabic*),
ref=(\arabic*),
align=left,
font=\bfseries
]
\item \label{first}First
\itemlabel{(foo)}{foo}Foo
\item \label{last}Last
\end{enumerate}
\end{document}
--
Heiko Oberdiek
GL
2010-04-14 13:21:05 UTC
Permalink
Post by Heiko Oberdiek
Post by Alexander Zimmermann
at one point I want to switch from numbers to custom label in my
enumeration. No problem so far. However, when want to reference the
custom label later on (\ref or \autoref), I get "item (1)" and not
the desired "item (R)". How could I fix it?
\documentclass{article}
\usepackage{enumitem, hyperref}
\pagestyle{empty}
\begin{document}
\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\item[(R)]\label{step:RTO}
Waiting for an retransmission timeout
It's a defiency in LaTeX: \label refers to \refstepcounter, but the
optional argument of \item suppresses the call of \refstepcounter.
Yes, but if I edit the pdf, each label is already assigned a name /Names
[ R (Item.1) ... R (Item.2) ... R (Item.3) ... ]

in a sequence. Is this possible just to change the destination name ?
Or duplicate it with another user-friendly name ?

If I had time to look at hyperref log, I'm sure I would find a way to do
that...

Yours sincerely.
Heiko Oberdiek
2010-04-14 14:44:52 UTC
Permalink
Post by GL
Yes, but if I edit the pdf, each label is already assigned a name /Names
[ R (Item.1) ... R (Item.2) ... R (Item.3) ... ]
No, they are created by \refstepcounter.
Post by GL
in a sequence. Is this possible just to change the destination name ?
Or duplicate it with another user-friendly name ?
I don't see, how this is related to \ref.
--
Heiko Oberdiek
Alexander Zimmermann
2010-04-14 14:49:09 UTC
Permalink
I really don't understand what you do, nevertheless it works :-)

Thanks.
Post by Heiko Oberdiek
Post by Alexander Zimmermann
at one point I want to switch from numbers to custom label in my
enumeration. No problem so far. However, when want to reference the
custom label later on (\ref or \autoref), I get "item (1)" and not
the desired "item (R)". How could I fix it?
\documentclass{article}
\usepackage{enumitem, hyperref}
\pagestyle{empty}
\begin{document}
\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\item[(R)]\label{step:RTO}
Waiting for an retransmission timeout
It's a defiency in LaTeX: \label refers to \refstepcounter, but the
optional argument of \item suppresses the call of \refstepcounter.
\documentclass{article}
\makeatletter
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin\csname phantomsection\endcsname
}%
}%
\label{#2}%
\ignorespaces
}
\makeatother
\usepackage{enumitem, hyperref}
\begin{document}
\ref{first}, \ref{foo}, \ref{last}
\begin{enumerate}[
label=(\arabic*),
ref=(\arabic*),
align=left,
font=\bfseries
]
\item \label{first}First
\itemlabel{(foo)}{foo}Foo
\item \label{last}Last
\end{enumerate}
\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Alexander Zimmermann
2010-04-15 13:44:13 UTC
Permalink
On 14.04.10 13:57, Heiko Oberdiek wrote:

Hi Heiko,

I was to quick. Your solution doesn't work.

a) The indentation is not correct.
b) We break \autoref

See..

\documentclass{article}
\usepackage[english]{babel}

\usepackage{enumitem, hyperref, blindtext}

\makeatletter
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin\csname phantomsection\endcsname
}%
}%
\***@edef\@currentlabel{#1}
\label{#2}%
\ignorespaces
}
\makeatother


\begin{document}

\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\itemlabel{(R)}{step:RTO}
\blindtext
\item\label{step:2}
\autoref{step:init} \quad \autoref{step:RTO}
\end{enumerate}

\end{document}
Post by Alexander Zimmermann
\documentclass{article}
\makeatletter
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin\csname phantomsection\endcsname
}%
}%
\label{#2}%
\ignorespaces
}
\makeatother
\usepackage{enumitem, hyperref}
\begin{document}
\ref{first}, \ref{foo}, \ref{last}
\begin{enumerate}[
label=(\arabic*),
ref=(\arabic*),
align=left,
font=\bfseries
]
\item \label{first}First
\itemlabel{(foo)}{foo}Foo
\item \label{last}Last
\end{enumerate}
\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Heiko Oberdiek
2010-04-15 18:52:29 UTC
Permalink
Post by Alexander Zimmermann
I was to quick. Your solution doesn't work.
a) The indentation is not correct.
b) We break \autoref
See..
\documentclass{article}
\usepackage[english]{babel}
\usepackage{enumitem, hyperref, blindtext}
\makeatletter
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin\csname phantomsection\endcsname
}%
}%
b) We break \autoref
\documentclass{article}
\usepackage[english]{babel}

\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}

\makeatletter
\newcounter{itemlabel}
\newcommand*{\itemlabel}[2]{%
\item[{#1}]%
\leavevmode
\@ifundefined{hypertarget}{}{%
\stepcounter{itemlabel}%
\edef\@currentHref{Item.label.\the\value{itemlabel}}%
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin
\expandafter\hypertarget\expandafter{\@currentHref}{}%
}%
}%
}%
\***@edef\@currentlabel{#1}%
\label{#2}%
\ignorespaces
}
\makeatother

\begin{document}

\begin{enumerate}[label=(\arabic*), ref=(\arabic*),
align=left, font=\bfseries]
\item\label{step:init}
This is step one
\itemlabel{(R)}{step:RTO}
\blindtext
\item\label{step:2}
\autoref{step:init} \quad \autoref{step:RTO}
\end{enumerate}

\end{document}
--
Heiko Oberdiek
Alexander Zimmermann
2010-04-19 16:11:30 UTC
Permalink
Hi Heiko,

thank you very much! It works.

Last but not least, I tried to extend \autoref, so that it will produce
"Step (1)" or "Step (R)". A global
"\newcommand*{\Itemautorefname}{Step}" is not the cleverest solution...

I tried to expand your code. It compiles, however I get a warning

"destination with the same identifier (name{Step.0}) has been already
used, duplicate ignored"

and nevertheless, I have the feeling that the hypertargets are not correct.

Thank you so much,

Alex

--
\documentclass{article}
\usepackage[english]{babel}

\usepackage{enumitem,blindtext,hyperref,ifthen}

\newlist{algorithmenum}{enumerate}{2}
\setlist[algorithmenum,1]{label=(\arabic*), ref={(\arabic*)},
font=\bfseries,
align=left, itemsep=1ex}

\newcommand*{\Stepautorefname}{Step}

\makeatletter
\newcounter{step}
\newcounter{customstep}
\newcommand*{\step}[2][]{%
\ifthenelse{\equal{#1}{\empty}}
{
\item
\leavevmode
\@ifundefined{hypertarget}{}{%
\stepcounter{customstep}%
\edef\@currentHref{Step.\the\value{step}}%
\expandafter\hypertarget\expandafter{\@currentHref}{}%
}%
}
{%
\item[{#1}]%
\leavevmode
\@ifundefined{hypertarget}{}{%
\stepcounter{customstep}%
\edef\@currentHref{Step.\the\value{customstep}}%
\rlap{%
\raisebox{.7\baselineskip}[0pt]{%
\kern-\leftmargin
\expandafter\hypertarget\expandafter{\@currentHref}{}%
}%
}%
}%
\***@edef\@currentlabel{#1}%
}%
\label{#2}%
\ignorespaces
}
\makeatother

\begin{document}

\begin{algorithmenum}
\step{step:init}
\blindtext
\step[(R)]{step:RTO}
\blindtext
\step{step:2}
\autoref{step:init} \quad \autoref{step:RTO}
\end{algorithmenum}

\end{document}
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Heiko Oberdiek
2010-04-19 18:09:54 UTC
Permalink
Post by Alexander Zimmermann
Hi Heiko,
Last but not least, I tried to extend \autoref, so that it will produce
"Step (1)" or "Step (R)". A global
"\newcommand*{\Itemautorefname}{Step}" is not the cleverest solution...
I tried to expand your code. It compiles, however I get a warning
"destination with the same identifier (name{Step.0}) has been already
used, duplicate ignored"
and nevertheless, I have the feeling that the hypertargets are not correct.
\newcounter{step}
\newcounter{customstep}
Drop \newcounter{step}
Post by Alexander Zimmermann
\newcommand*{\step}[2][]{%
\ifthenelse{\equal{#1}{\empty}}
{
\item
\leavevmode
\stepcounter{customstep}%
Use \the\value{customstep}
Post by Alexander Zimmermann
}%
Also the \rlap/\raisebox stuff should be used to place the target more
properly.
--
Heiko Oberdiek
GL
2010-04-19 18:20:40 UTC
Permalink
Post by Alexander Zimmermann
Hi all,
at one point I want to switch from numbers to custom label in my
enumeration. No problem so far. However, when want to reference the
custom label later on (\ref or \autoref), I get "item (1)" and not
the desired "item (R)". How could I fix it?
Alex
I can propose you another solution, closer to "enumitem" (leaving
hyperref gentle then ;-)

The idea is that the item is made using :
\makelabel#1 => \rlap{ \font #1 }\hss

Therefore, it is possible to capture the "argument of \font" (with a
slight modification of \makelabel) :
\makelabel#1 => \rlap{ \font #1\@@} \hss

Then \font will capture the item delimited by \@@ and set the right
label.


Just a problem occurs when label is automatic, but I bypass the problem
as explained after the ECM :

%--------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}

\begin{document}\makeatletter

\renewcommand\***@alignleft{% This is where \makelabel is defined
\def\makelabel##1{\rlap {\***@format ##1\@@}\hss}}


\newrobustcmd\LabelizeItem[1][]{\***@m{#1}}

\def\***@m#1#2\@@{%
\ifx\@itemlabel#2\relax
\***@edef\@currentlabel{#2}%
\***@edef\@currentlabel{%
\expandafter\@firstofone\@currentlabel}% here is the "trick"
\else
\def\@currentlabel{#2}% user defined item : no problem
\fi
%\message{@currentlabelis : \@currentlabel}% debug purpose
\label{#1:\@currentlabel}%
#2% "reinserts" the item
}

\begin{enumerate}[label=(\arabic*),ref=(\arabic*),align=left,
font={\bfseries\LabelizeItem[step]}]% font calls \LabelizeItem
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}

\end{document}\endinput
% ------------------------------------------

If you give the item :
\item[{(R)}]
Then argument of \makelabel's {(R)}

If the item is automatic, it is :
\@itemlabel
which expands (after a chain containing \@arabic here) to : {{(1)}}

Therefore, I had to get out of one level of braket, if order not to have
a final label looking like : "step:{(1)}" which is obviouly tedious.


Well, is this good enough ?
(if align = right, some changes have to be made, but it is seldom the
case...)
GL
2010-04-19 18:51:39 UTC
Permalink
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...

Therefore, you juste have to add :
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.




% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}

\begin{document}\makeatletter

\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\let\totest\makelabel\***@alignleft
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
{\rlap{\***@format\LabelizeItem[{#1}]{####1}\hss}}}%
\else
\def\do{\endgroup\def\makelabel ####1%
{\hss\llap{\***@format\LabelizeItem[{#1}]{####1}}}}%
\fi\do}

\newrobustcmd\LabelizeItem[2][]{%
\ifx\@itemlabel#2\relax
\***@edef\@currentlabel{#2}%
\expandafter\def\expandafter\@currentlabel\@currentlabel%
\else \def\@currentlabel{#2}%
\fi
\label{#1\@currentlabel}%
#2}


\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}


\end{document}\endinput
% -------------------------------------------------------
Alexander Zimmermann
2010-04-20 15:16:20 UTC
Permalink
Merci beaucoup.

Alex
Post by GL
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.
% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}
\begin{document}\makeatletter
\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
\else
\def\do{\endgroup\def\makelabel ####1%
\fi\do}
\newrobustcmd\LabelizeItem[2][]{%
\fi
#2}
\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}
\end{document}\endinput
% -------------------------------------------------------
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
GL
2010-04-20 17:30:41 UTC
Permalink
Post by Alexander Zimmermann
Merci beaucoup.
En français dans le texte !

J'ai continué pour implémenter un schéma générale de référence des
listes, grâce à zref.

Ca devrait être terminé bientôt (question d'interface...)
Post by Alexander Zimmermann
Alex
Post by GL
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.
% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}
\begin{document}\makeatletter
\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
\else
\def\do{\endgroup\def\makelabel ####1%
\fi\do}
\newrobustcmd\LabelizeItem[2][]{%
\fi
#2}
\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}
\end{document}\endinput
% -------------------------------------------------------
Alexander Zimmermann
2010-04-23 11:22:08 UTC
Permalink
Hi,

I like your code. However, it is possible to change the code so that I
get "Step r" and not "item (R)" when I use \autoref{step:(R)}.

Or even better: use the parameter of your \AutoLabelPrefix{} to produce
the label in the \newlabel{...}, so that I can use
\newcommand{\Blaautorefname}{Bla} to produce "Bla (R)"

Alex
Post by GL
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.
% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}
\begin{document}\makeatletter
\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
\else
\def\do{\endgroup\def\makelabel ####1%
\fi\do}
\newrobustcmd\LabelizeItem[2][]{%
\fi
#2}
\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}
\end{document}\endinput
% -------------------------------------------------------
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
GL
2010-04-23 17:15:12 UTC
Permalink
Post by Alexander Zimmermann
Hi,
I like your code. However, it is possible to change the code so that I
get "Step r" and not "item (R)" when I use \autoref{step:(R)}.
Yes you can, but I don't think it is the purpose of \autoref !

Say :
\hyperref[step:(R)]{whatever you wish to be displayed}

I'm on the way with zref and various ways to reference items.
I have still problems to deal properly with(out) duplicate labels.
Post by Alexander Zimmermann
Or even better: use the parameter of your \AutoLabelPrefix{} to produce
the label in the \newlabel{...}, so that I can use
\newcommand{\Blaautorefname}{Bla} to produce "Bla (R)"
Alex
Post by GL
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.
% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}
\begin{document}\makeatletter
\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
\else
\def\do{\endgroup\def\makelabel ####1%
\fi\do}
\newrobustcmd\LabelizeItem[2][]{%
\fi
#2}
\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}
\end{document}\endinput
% -------------------------------------------------------
Alexander Zimmermann
2010-04-26 14:42:35 UTC
Permalink
Post by GL
Post by Alexander Zimmermann
Hi,
I like your code. However, it is possible to change the code so that I
get "Step r" and not "item (R)" when I use \autoref{step:(R)}.
Yes you can, but I don't think it is the purpose of \autoref !
No??? IMO this is exactly the use case for autoref! I don't want to
type every time:

\hyperref[step:(R)]{Step~\begin{NoHyper}\ref{step:(R)}\end{NoHyper}}

You think that this a comfortable method? I have several algorithms in
my document (for which I use the enumeration) with a dozen of references
Post by GL
\hyperref[step:(R)]{whatever you wish to be displayed}
I'm on the way with zref and various ways to reference items.
I have still problems to deal properly with(out) duplicate labels.
Post by Alexander Zimmermann
Or even better: use the parameter of your \AutoLabelPrefix{} to produce
the label in the \newlabel{...}, so that I can use
\newcommand{\Blaautorefname}{Bla} to produce "Bla (R)"
Alex
Post by GL
In the same idea of my post of 20:20, I have a clearner solution, just
using the "before=<code>" key from enumitem, and leaving align=left or
right quiet...
before = \AutoLabelPrefix{step:}
to your keys in order to get the correct (finger crossed) behaviour.
% -----------------------------------------------------------
\documentclass{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}
\usepackage{enumitem,blindtext}
\usepackage[verbose]{hyperref}
\begin{document}\makeatletter
\newrobustcmd\AutoLabelPrefix[1]{\begingroup
\ifx\totest\makelabel
\def\do{\endgroup\def\makelabel ####1%
\else
\def\do{\endgroup\def\makelabel ####1%
\fi\do}
\newrobustcmd\LabelizeItem[2][]{%
\fi
#2}
\begin{enumerate}[label=(\arabic*),align=left,before=\AutoLabelPrefix{step:},ref=(\arabic*),font=\bfseries]
\item
This is step one
\item[{(R)}]
\blindtext
\item
\autoref{step:(1)} \quad \autoref{step:(R)}
\end{enumerate}
\end{document}\endinput
% -------------------------------------------------------
--
//
// Dipl.-Inform. Alexander Zimmermann
// Department of Computer Science, Informatik 4
// RWTH Aachen University
// Ahornstr. 55, 52056 Aachen, Germany
// phone: (49-241) 80-21468, fax: (49-241) 80-22220
// email: ***@cs.rwth-aachen.de
// web: http://www.umic-mesh.net
//
Loading...