| 1 |
%% LaTeX package crossreftools - version 1.0 (2020/07/19 -- 11:55:58) |
| 2 |
%% Driver file for crossreftools.sty |
| 3 |
%% |
| 4 |
%% |
| 5 |
%% ------------------------------------------------------------------------------------------- |
| 6 |
%% Copyright (c) 2017 -- 2020 by Dr. Christian Hupfer <dr dot christian dot hupfer at gmail dot com> |
| 7 |
%% ------------------------------------------------------------------------------------------- |
| 8 |
%% |
| 9 |
%% This work may be distributed and/or modified under the |
| 10 |
%% conditions of the LaTeX Project Public License, either version 1.3 |
| 11 |
%% of this license or (at your option) any later version. |
| 12 |
%% The latest version of this license is in |
| 13 |
%% http://www.latex-project.org/lppl.txt |
| 14 |
%% and version 1.3 or later is part of all distributions of LaTeX |
| 15 |
%% version 2005/12/01 or later. |
| 16 |
%% |
| 17 |
%% |
| 18 |
%% This work has the LPPL maintenance status `author-maintained` |
| 19 |
%% |
| 20 |
%% |
| 21 |
|
| 22 |
\documentclass{book} |
| 23 |
|
| 24 |
\usepackage{hyperref} |
| 25 |
\usepackage{nameref} |
| 26 |
\usepackage[user]{zref} |
| 27 |
\usepackage{cleveref} |
| 28 |
|
| 29 |
\usepackage{crossreftools} |
| 30 |
|
| 31 |
|
| 32 |
\setlength{\parindent}{0em} |
| 33 |
|
| 34 |
\def\labeltoshow{foochapterlabel} |
| 35 |
|
| 36 |
\def\equationlabeltoshow{fooequationlabel} |
| 37 |
|
| 38 |
|
| 39 |
\crtlistoflabelsstructurelevel{section} |
| 40 |
\begin{document} |
| 41 |
|
| 42 |
\tableofcontents |
| 43 |
|
| 44 |
\crtlistoflabels* |
| 45 |
|
| 46 |
\clearpage |
| 47 |
|
| 48 |
\chapter{Some easy usages of crossreftools} |
| 49 |
%\setcounter{chapter}{16}% Just for checking |
| 50 |
|
| 51 |
Let us refer the usual way: \Cref{\labeltoshow} |
| 52 |
|
| 53 |
\edef\foocntr{\crtcrefcounter{\labeltoshow}} |
| 54 |
|
| 55 |
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}. |
| 56 |
|
| 57 |
|
| 58 |
Let us check for a subsection label: \crtcrefcounter{foosubsectionlabel} |
| 59 |
|
| 60 |
The result is \fbox{\crtcrefresult{\labeltoshow}} |
| 61 |
|
| 62 |
\edef\labeltoshowname{\crtcrefname{chapter}} |
| 63 |
|
| 64 |
\section{Extracting usual reference information} |
| 65 |
|
| 66 |
Extracting content with \verb!\crtextractref! |
| 67 |
\begin{itemize} |
| 68 |
\item reference: \crtextractcref{reference}{\labeltoshow} |
| 69 |
\item page: \crtextractcref{page}{\labeltoshow} |
| 70 |
\end{itemize} |
| 71 |
|
| 72 |
If the \fbox{hyperref} package is loaded, further properties are retrievable: |
| 73 |
|
| 74 |
\begin{itemize} |
| 75 |
\item name: \crtextractref{name}{\labeltoshow} |
| 76 |
\item hyperanchor: \crtextractref{anchor}{\labeltoshow} |
| 77 |
\item unused: \crtextractref{unused}{\labeltoshow} |
| 78 |
\end{itemize} |
| 79 |
|
| 80 |
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. |
| 81 |
|
| 82 |
|
| 83 |
This works only if there is usual hyper anchor for the counter: \crtrefcounter{fooequationlabel}. |
| 84 |
|
| 85 |
\section{Extracting the cleveref names} |
| 86 |
|
| 87 |
\begin{itemize} |
| 88 |
|
| 89 |
\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}. |
| 90 |
\item Extracting content with \verb!\crtextractcref! |
| 91 |
\begin{itemize} |
| 92 |
\item counter: \crtextractcref{counter}{\labeltoshow} |
| 93 |
\item number: \crtextractcref{number}{\labeltoshow} |
| 94 |
\item result: \crtextractcref{result}{\labeltoshow} |
| 95 |
\item reference: \crtextractcref{reference}{\labeltoshow} |
| 96 |
\item page: \crtextractcref{page}{\labeltoshow} |
| 97 |
\end{itemize} |
| 98 |
\end{itemize} |
| 99 |
|
| 100 |
The macro \verb!\crtextractcref! is expandable!\edef\counterof{\crtextractcref{counter}{\labeltoshow}} Using the stored value for counter: \counterof! |
| 101 |
|
| 102 |
|
| 103 |
See \crthyperCref{fooequationlabel} and \cref{pythagoreantheorem}. |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
\chapter{Placing more generic labels} |
| 108 |
|
| 109 |
\clearpage |
| 110 |
\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] |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
\clearpage |
| 116 |
|
| 117 |
See \ref{somelabel} or \crtnameref{somelabel} on \cpageref{somelabel}, but \crtlnameref{somelabel}. \crtunameref{invisiblelabel} |
| 118 |
|
| 119 |
|
| 120 |
\chapter{This is foo}\label{foochapterlabel} |
| 121 |
|
| 122 |
\setcounter{section}{5} |
| 123 |
\section{Foo}\label{foosectionlabel} \zlabel{foosectionlabel} |
| 124 |
|
| 125 |
\subsection{Foo subsection} \label{foosubsectionlabel} |
| 126 |
|
| 127 |
\begin{equation} |
| 128 |
E=mc^{2}\label{firstequationlabel} |
| 129 |
\end{equation} |
| 130 |
|
| 131 |
\begin{equation} |
| 132 |
E=mc^{2}\label{fooequationlabel} |
| 133 |
\end{equation} |
| 134 |
|
| 135 |
|
| 136 |
\clearpage |
| 137 |
|
| 138 |
\section{Another foo bar section} |
| 139 |
\begin{equation} |
| 140 |
a^{2} + b^{2}=c^{2}\label[section]{pythagoreantheorem}% Explicitly use a wrong counter type here for testing |
| 141 |
\end{equation} |
| 142 |
|
| 143 |
|
| 144 |
\chapter{Checking for label existence} |
| 145 |
|
| 146 |
\crtifdefinedlabel{firstfooequationlabel}{% |
| 147 |
Yes, that label exists% |
| 148 |
}{ |
| 149 |
No, that label does not exist% |
| 150 |
} |
| 151 |
|
| 152 |
\crtcrefifdefinedlabel{fooequationlabel}{% |
| 153 |
Yes, that cleveref label exists% |
| 154 |
}{ |
| 155 |
No, that cleveref label does not exist% |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
\end{document} |