Redefinir localmente o nome de referência do intelligentef para capítulos

Redefinir localmente o nome de referência do intelligentef para capítulos

Considere o seguinte 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}

Isso resulta na seguinte saída:

Resultado atual

Embora o resultado seja desejado como abaixo:

Resultado desejado

Eu me pergunto como a tentativa acima de redefinir localmente cleverefo nome para referências de capítulos pode ser corrigida para funcionar conforme planejado.

Em geral, preciso de uma solução para usar \crefnamemacro em escopo local.
Adicionar \begingroup/ \endgroupnão ajudou.

Como uma melhoria adicional, o nome de referência original dos capítulos pode ser armazenado inicialmente e restaurado após o final do appendicesambiente (em vez do par chapter/ chaptersstrings codificado no MWE).

Responder1

O pacote cleverefredefine a opção \appendix. Se você adicionar este comando (com ou sem appendicesambiente) você obterá as referências desejadas em seu MWE. Mas não há comando para voltar às referências regulares dos capítulos.

Uma solução é usar o argumento opcional de label. Este argumento opcional adicional clevereftambém é fornecido por:

\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}

insira a descrição da imagem aqui

Responder2

Depoisesdd responderConsegui fazer isso de uma forma um pouco mais 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}

Resultado

informação relacionada