cleveref: настройка вывода \cref

cleveref: настройка вывода \cref

Я использую cleverefпакет. Мой документ выглядит примерно так:

\documentclass{article}
\usepackage{cleveref}

\begin{document}
\tableofcontents

\section{Section A}
    Refer to \cref{append} for more details.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}

\section{Appendix}
    \subsection{Appendix A}
        \subsubsection{Detailed Explanation} \label{append}
            blah
    \subsection{Appendix B}
\end{document}

Мне приходится использовать подразделы и подподразделы таким образом, поскольку само приложение должно иметь собственную запись и номер раздела в ToC.

Теперь я хочу, чтобы мой результат был чем-то вроде

Раздел А

Более подробную информацию см. в Приложении A, Разделе I.

Я уже пробовал использовать \crefnameдля настройки вывода:

\crefname{secapp}{Anhang \Alph{subsection}, Section}{Appendix \Alph{subsection}, Section}

%Stuff here
\subsubsection{Detailed Explanation} \label[secapp]{append}

но secappтакое определение приводит cleverefк выводу номера подраздела, в котором \crefбыл вызван.

Есть ли способ отформатировать вывод, как описано выше, используя cleveref?

Спасибо!

решение1

На мой взгляд, схема именования/нумерации сбивает с толку, но использование xassoccntмакроса \RegisterPostLabelHook{\zlabel}автоматически определяет дополнительные метки, сохраняя \thesubsectionдля соответствующего приложения «раздел», который извлекается \parentCrefпозже.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xassoccnt}
\usepackage{xpatch}
\usepackage{hyperref}
\usepackage[user,counter,hyperref]{zref}
\usepackage{cleveref}

\makeatletter
\AtEndPreamble{
  \newif\if@hyperrefloaded
  \@ifpackageloaded{hyperref}{
    \@hyperrefloadedtrue
  }{
    \@hyperrefloadedfalse
  }
}
\makeatother


\usepackage{xparse}

% Define a new property named 'appendix'

\makeatletter
\zref@newprop{appendix}{\thesubsection}

% Add the new property to the main property list stored with \zlabel, but for \appendix only
\g@addto@macro{\appendix}{%
  \zref@addprops{main}{appendix}%
}

% Command for uppercase output
\NewDocumentCommand{\parentCref}{m}{%
  \zref@ifrefundefined{#1}{%
    \Cref{#1}%
  }{%
    \if@hyperrefloaded
    \hyperlink{\zref@extract{#1}{anchor}}{\appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}}%
    \else
    \appendixname\ \zref@extract{#1}{appendix}, Section \zref@extract{#1}{default}%
    \fi
  }%
}
\makeatother


\AtBeginDocument{%
 \RegisterPostLabelHook{\zlabel}
}

\begin{document}


\section{Normal section} \label{firstsection}
Refer to \parentCref{append} for more details, but don't forget \parentCref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}


\clearpage

\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}


\end{document}




%\crefname{subsubappendix}{\appendixname \Alph{subsection}, Section}{\appendixname \Alph{subsection}, Section}

\crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}
\Crefformat{subsubappendix}{#2\appendixname\ thesubappendix, Section  #1#3}

\begin{document}
\tableofcontents

\section{Section A} \label{firstsection}
Refer to \cref{append} for more details, but don't forget \Cref{append:b}.

\appendix
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thesubsubsection}{\Roman{subsubsection}}



\section{Appendix}
\subsection{Appendix A}
\subsubsection{Detailed Explanation} \label{append}
blah
\subsection{Appendix B} \label{appendix:B}
\subsubsection{Even more detailed explanations} \label{append:b}

\end{document}

введите описание изображения здесь

Связанный контент