%% LaTeX package crossreftools - version 1.0 (2020/07/19 -- 11:55:58) %% Driver file for crossreftools.sty %% %% %% ------------------------------------------------------------------------------------------- %% Copyright (c) 2017 -- 2020 by Dr. Christian Hupfer %% ------------------------------------------------------------------------------------------- %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either version 1.3 %% of this license or (at your option) any later version. %% The latest version of this license is in %% http://www.latex-project.org/lppl.txt %% and version 1.3 or later is part of all distributions of LaTeX %% version 2005/12/01 or later. %% %% %% This work has the LPPL maintenance status `author-maintained` %% %% \documentclass{book} \usepackage{hyperref} \usepackage{nameref} \usepackage[user]{zref} \usepackage{cleveref} \usepackage{crossreftools} \setlength{\parindent}{0em} \def\labeltoshow{foochapterlabel} \def\equationlabeltoshow{fooequationlabel} \crtlistoflabelsstructurelevel{section} \begin{document} \tableofcontents \crtlistoflabels* \clearpage \chapter{Some easy usages of crossreftools} %\setcounter{chapter}{16}% Just for checking Let us refer the usual way: \Cref{\labeltoshow} \edef\foocntr{\crtcrefcounter{\labeltoshow}} The counter for \fbox{\labeltoshow} is \foocntr\ or \crtcrefcounter{\labeltoshow}. It is used on page \crtcrefpage{\labeltoshow}. The value for the misspelled label name is \crtcrefnumber{labeltoshowstuff}, whereas the correct value is \crtcrefnumber{\labeltoshow}. Let us check for a subsection label: \crtcrefcounter{foosubsectionlabel} The result is \fbox{\crtcrefresult{\labeltoshow}} \edef\labeltoshowname{\crtcrefname{chapter}} \section{Extracting usual reference information} Extracting content with \verb!\crtextractref! \begin{itemize} \item reference: \crtextractcref{reference}{\labeltoshow} \item page: \crtextractcref{page}{\labeltoshow} \end{itemize} If the \fbox{hyperref} package is loaded, further properties are retrievable: \begin{itemize} \item name: \crtextractref{name}{\labeltoshow} \item hyperanchor: \crtextractref{anchor}{\labeltoshow} \item unused: \crtextractref{unused}{\labeltoshow} \end{itemize} The 5th (and usually empty) label property introduced by hyperref is unused as of version v6.85a of that package -- \crtextractref{unused}{labelname} will return nothing here, i.e. the expansion is empty. This works only if there is usual hyper anchor for the counter: \crtrefcounter{fooequationlabel}. \section{Extracting the cleveref names} \begin{itemize} \item The lower case cross reference name for \fbox{\equationlabeltoshow} is \crtcrefnamebylabel{\equationlabeltoshow}, this time using \verb!\crtcrefnamebylabel!; the upper case name is \crtCrefnamebylabel{\equationlabeltoshow}. \item Extracting content with \verb!\crtextractcref! \begin{itemize} \item counter: \crtextractcref{counter}{\labeltoshow} \item number: \crtextractcref{number}{\labeltoshow} \item result: \crtextractcref{result}{\labeltoshow} \item reference: \crtextractcref{reference}{\labeltoshow} \item page: \crtextractcref{page}{\labeltoshow} \end{itemize} \end{itemize} The macro \verb!\crtextractcref! is expandable!\edef\counterof{\crtextractcref{counter}{\labeltoshow}} Using the stored value for counter: \counterof! See \crthyperCref{fooequationlabel} and \cref{pythagoreantheorem}. \chapter{Placing more generic labels} \clearpage \crtcrossreflabel[Let us place a label without a counter]{Let us plant a label not being connected to a counter:}[somelabel] and \crtcrossreflabel*{some visible text that is invisibly placed here}[invisiblelabel] \clearpage See \ref{somelabel} or \crtnameref{somelabel} on \cpageref{somelabel}, but \crtlnameref{somelabel}. \crtunameref{invisiblelabel} \chapter{This is foo}\label{foochapterlabel} \setcounter{section}{5} \section{Foo}\label{foosectionlabel} \zlabel{foosectionlabel} \subsection{Foo subsection} \label{foosubsectionlabel} \begin{equation} E=mc^{2}\label{firstequationlabel} \end{equation} \begin{equation} E=mc^{2}\label{fooequationlabel} \end{equation} \clearpage \section{Another foo bar section} \begin{equation} a^{2} + b^{2}=c^{2}\label[section]{pythagoreantheorem}% Explicitly use a wrong counter type here for testing \end{equation} \chapter{Checking for label existence} \crtifdefinedlabel{firstfooequationlabel}{% Yes, that label exists% }{ No, that label does not exist% } \crtcrefifdefinedlabel{fooequationlabel}{% Yes, that cleveref label exists% }{ No, that cleveref label does not exist% } \end{document}