
Considere el siguiente MWE:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\usepackage{etoolbox}
\BeforeBeginEnvironment{appendices}{%
\crefname{chapter}{appendix}{appendices}%
%\Crefname{chapter}{Appendix}{Appendices}%
}
\AfterEndEnvironment{appendices}{%
\crefname{chapter}{chapter}{chapters}%
%\Crefname{chapter}{Chapters}{Chapters}%
}
\begin{document}
\noindent Reference to~regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to~appendix chapter: \cref{chp:appendix_chapter}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\chapter{Appendix chapter} \label{chp:appendix_chapter}
Appendix chapter text.
\end{appendices}
\end{document}
Da como resultado el siguiente resultado:
Si bien se desea que el resultado sea el siguiente:
Me pregunto cómo cleveref
se puede arreglar el intento anterior de redefinir localmente el nombre de las referencias de los capítulos para que funcione según lo previsto.
En general, necesito una solución para utilizar \crefname
macros dentro de un ámbito local.
Agregar \begingroup
/ \endgroup
no ayudó.
Como mejora adicional, el nombre de referencia original de los capítulos podría almacenarse al principio y restaurarse después del final del appendices
entorno (en lugar del par de cadenas chapter
/ chapters
codificado en el MWE).
Respuesta1
"El paquete cleveref
redefine el cambio" \appendix
. Si agrega este comando (con o sin el appendices
entorno) obtendrá las referencias deseadas en su MWE. Pero no hay ningún comando para volver a las referencias de capítulos habituales.
Una solución es utilizar el argumento opcional de label
. Este argumento opcional adicional también lo proporciona cleveref
:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\begin{document}
\noindent Reference to regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to appendix chapter: \cref{chp:appendix_chapter}.
\noindent Referece to another regular chapter: \cref{chp:another}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\chapter{Appendix chapter}
\label[appendix]{chp:appendix_chapter}% <- changed (optional argument added)
Appendix chapter text.
\end{appendices}
\chapter{Another regular chapter}\label{chp:another}
\end{document}
Respuesta2
Despuésesdd respuestaLogré hacerlo de una manera un poco más automatizada:
\documentclass{scrbook}
\usepackage{appendix}
\usepackage{cleveref}
\begin{document}
\noindent Reference to~regular chapter: \cref{chp:regular_chapter}.
\noindent Reference to~appendix chapter: \cref{chp:appendix_chapter}.
\noindent Reference to~another regular chapter: \cref{chp:another_regular_chapter}.
\chapter{Regular chapter} \label{chp:regular_chapter}
Regular chapter text.
\begin{appendices}
\appendix
\chapter{Appendix chapter} \label{chp:appendix_chapter}
Appendix chapter text.
\end{appendices}
\renewcommand{\thechapter}{\arabic{chapter}}
\chapter{Another regular chapter} \label{chp:another_regular_chapter}
Another regular chapter text.
\end{document}