summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/crossreftools/crossreftools_driver.tex
blob: 973bdf676b5e71ee4a1a3bbdae2819c7703ca780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%% LaTeX package crossreftools - version 0.9 (2019/01/03 -- 15:57:43)
%% Driver file for crossreftools.sty
%%
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2017 -- 2019 by Dr. Christian Hupfer <typography dot with dot latex at gmail dot com>
%% -------------------------------------------------------------------------------------------
%%
%% 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}