4

I am renaming the "line" label for lines in the algorithmic environment, since I am using the default label for lstlisting environment. As soon as I add define \crefname for it, the counter does not increase.

It's a simple problem, so an example will illustrate it best.

\documentclass{article}
\usepackage{algorithm}
\usepackage{hyperref}
\usepackage{algpseudocode}
\usepackage{cleveref}

\crefname{opC}{operation}{operations}
\Crefname{opC}{Operation}{Operations}

\begin{document}
    \begin{algorithm}[bt]
        \begin{algorithmic}[1]
            \State First line
            \label[opC]{line:1}
            \State Second line
            \label[opC]{line:2}
        \end{algorithmic}
    \end{algorithm}
Refer here to \cref{line:1} and to \cref{line:2}. 
These two work just fine: \cref{line:4} and \cref{line:3}.
    \begin{algorithm}[bt]
        \begin{algorithmic}[1]
            \State Another first line
            \label{line:3}
            \State Another second line
            \label{line:4}
        \end{algorithmic}
    \end{algorithm}
\end{document}

Compiled example

I tried with \newcounter{opC} and \crefalias{opC}{line} to no avail.

Incidentally, \ref returns numbers as it should, as shown for the second algorithm. Also, the hyperref links point to the right location (though hard to check in this MWE), so only the actual label is wrong.

1
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Apr 3, 2015 at 12:10

1 Answer 1

2

After studying the cleveref package documentation further, I stumbled across a warning in section 14.1 Non-bugs. Even though I did not use \label in an optional argument to another command (as the third bullet suggests), it seems that it should be enclosed with curly braces in order to work properly.

Correcting \label[opC]{line:1} into {\label[opC]{line:1}} in the example above fixes the problem.

You must log in to answer this question.

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