¿Por qué Cleveref no captura el flotador de pseudo+tcolorbox?

¿Por qué Cleveref no captura el flotador de pseudo+tcolorbox?

Estoy cambiando a pseudopara presentar mis algoritmos. Siguiendo la documentación, lo combiné tcolorboxpara crear un entorno flotante llamado algorithm.

Pero cuando quiero hacer referencia a él \crefdesde cleverefel paquete, el comando no puede capturar el entorno flotante relacionado con él. Por lo tanto obtengo ?? 1en lugar de alg: 1(o algo así).

Aquí hay un MWE:

\documentclass{article} 

\usepackage{tcolorbox} % colored box with a lot of flexibility
    \tcbuselibrary{skins,theorems} % extra lib for pseudo

\usepackage{pseudo} % for pseudocode
    \newtcbtheorem{algorithm}{Algorithm}{pseudo/booktabs, float}{alg} % create a float env for algorithms

\usepackage{cleveref}

\begin{document} 

\begin{algorithm}{Euclid’s algorithm, \pr{Euclid}(a, b)}{euclid}
    \textbf{Input:}  Two positive integers, $a$ and $b$.\\
    \textbf{Output:} The greatest common divisor of $a$ and $b$.
    \begin{pseudo}[label=\small\arabic*, indent-mark]
        while $a \neq b$ \ct{If equal, both are gcd} \\+
            if $a > b$ \ct{ Reduce max with multiple of min} \\+
                    $a = a - b$ \ct{ $a$ is largest} \\-
            else $b = b - a$ \ct{ $b$ is largest} \\-
        return $a$ \ct{ Both are gcd, so return one}
    \end{pseudo}
    The running time is quadratic in the number of bits in the input.
\end{algorithm}

A sentence with a clever reference \cref{alg:euclid}.

\end{document}

¿Cómo podría solucionar este problema?

Respuesta1

Simplemente configure el tipo de etiqueta para su nuevo tcolorbox con label type=algorithm:

\documentclass{article}

\usepackage{tcolorbox} % colored box with a lot of flexibility
\tcbuselibrary{skins,theorems} % extra lib for pseudo

\usepackage{pseudo} % for pseudocode

\usepackage{cleveref}

\newtcbtheorem{algorithm}{Algorithm}{label type=algorithm,pseudo/booktabs, float}{alg} % create a float env for algorithms

\begin{document}

\begin{algorithm}{Euclid’s algorithm, \pr{Euclid}(a, b)}{euclid}
    \textbf{Input:}  Two positive integers, $a$ and $b$.\\
    \textbf{Output:} The greatest common divisor of $a$ and $b$.
    \begin{pseudo}[label=\small\arabic*, indent-mark]
        while $a \neq b$ \ct{If equal, both are gcd} \\+
            if $a > b$ \ct{ Reduce max with multiple of min} \\+
                    $a = a - b$ \ct{ $a$ is largest} \\-
            else $b = b - a$ \ct{ $b$ is largest} \\-
        return $a$ \ct{ Both are gcd, so return one}
    \end{pseudo}
    The running time is quadratic in the number of bits in the input.
\end{algorithm}

A sentence with a clever reference \cref{alg:euclid}.

\end{document}

ingrese la descripción de la imagen aquí

Esto es ligeramente mejor/más fácil que configurar \crefnameel contador tcb interno, como lo sugiere @egreg, ya que no necesita lidiar con el nombre del contador interno y ya lo hace \Crefnametambién, dependiendo de sus opciones de mayúsculas.

Alternativamente, si prefiere o necesita configurar crefname, puede hacerlo usando tcolorboxla opción correspondiente (este es más o menos el ejemplo del pseudomanual del usuario):

\documentclass{article}

\usepackage{tcolorbox} % colored box with a lot of flexibility
\tcbuselibrary{skins,theorems} % extra lib for pseudo

\usepackage{pseudo} % for pseudocode

\usepackage{cleveref}

\newtcbtheorem[crefname = {algorithm}{algorithms}]{algorithm}{Algorithm}{pseudo/booktabs, float}{alg} % create a float env for algorithms

\begin{document}

\begin{algorithm}{Euclid’s algorithm, \pr{Euclid}(a, b)}{euclid}
    \textbf{Input:}  Two positive integers, $a$ and $b$.\\
    \textbf{Output:} The greatest common divisor of $a$ and $b$.
    \begin{pseudo}[label=\small\arabic*, indent-mark]
        while $a \neq b$ \ct{If equal, both are gcd} \\+
            if $a > b$ \ct{ Reduce max with multiple of min} \\+
                    $a = a - b$ \ct{ $a$ is largest} \\-
            else $b = b - a$ \ct{ $b$ is largest} \\-
        return $a$ \ct{ Both are gcd, so return one}
    \end{pseudo}
    The running time is quadratic in the number of bits in the input.
\end{algorithm}

A sentence with a clever reference \cref{alg:euclid}.

\end{document}

Esto es estrictamente equivalente a la respuesta de @egreg en sus efectos, excepto que no necesita saber ni preocuparse por el nombre interno del tcolorboxcontador.

Respuesta2

Recibes la advertencia

LaTeX Warning: cref reference format for label type `tcb@cnt@algorithm' 
undefined on input line 26.

Definir el formato.

Y, por favor, no pongas espacios después de los paréntesis abiertos (o antes de los cerrados) si no quieres que a tus lectores les sangren los ojos.

\documentclass{article} 

\usepackage{tcolorbox} % colored box with a lot of flexibility
\tcbuselibrary{skins,theorems} % extra lib for pseudo
\usepackage{pseudo} % for pseudocode
\usepackage{cleveref}


% create a float env for algorithms
\newtcbtheorem{algorithm}{Algorithm}{pseudo/booktabs, float}{alg}

\crefname{tcb@cnt@algorithm}{algorithm}{algorithms}

\begin{document} 

\begin{algorithm}{Euclid’s algorithm, \pr{Euclid}(a, b)}{euclid}
    \textbf{Input:}  Two positive integers, $a$ and $b$.\\
    \textbf{Output:} The greatest common divisor of $a$ and $b$.
    \begin{pseudo}[label=\small\arabic*, indent-mark]
        while $a \neq b$ \ct{If equal, both are gcd} \\+
            if $a > b$ \ct{Reduce max with multiple of min} \\+
                    $a = a - b$ \ct{$a$ is largest} \\-
            else $b = b - a$ \ct{$b$ is largest} \\-
        return $a$ \ct{Both are gcd, so return one}
    \end{pseudo}
    The running time is quadratic in the number of bits in the input.
\end{algorithm}

A sentence with a clever reference to \cref{alg:euclid}.

\end{document}

ingrese la descripción de la imagen aquí

información relacionada