[Tex/LaTex] Why is the cross reference not working and some other questions

cross-referencingsyntax

I am a TEX beginner and I am now learning how to create a reference. I am reading the book "The Not So Short Introduction to LATEX2" by Oetiker, Partl, Hyna, Schlegl; on page 42 section 2.8 Cross Reference, the code is written as

A reference to this section \label{sec:this} looks like:
"see section~\ref{sec:this} on page~\pageref{sec:this}"

And I am using CTex and WinEdt and my questions are:

  1. I made a pdf file from the above code, but the section and page numbers are not highlighted and I cannot click on them. Why is it so?
  2. I tried to make a reference to other pages by typing its page number like {sec:37}, but it does not work. How can I fix it?
  3. What does the code sec actually mean? Is it arbitrary or a predefined syntax?
  4. When I typed \label{}, a menu box named Labels (51) appeared, and there is a dropdown menus like c:ISYAC, c:UNBOUND, c:UNIFBURN,… etc… what is that? Do we have to choose from those list or can we write our own like {sec:this}?

Helps are greatly appreciated! Many many thanks!

Best Answer

The general mechanism is to set an anchor some where in your document with \label{<name>}, where <name> can be a combination of numbers, letters, : and - (to be safe). These anchors must be set explicitly by the author, thats why \ref{sec:47} doesn’t work unless it is not defined by you. After setting up an anchor you can refer to it with \ref{<name>} (giving the corresponding counter, like chapter or section or equation or … number) or \pageref{<name>} (giving the corresponding page number).

Some author use identifiers like sec:, eq:, thm: etc. to make anchor names more human readable but this is not necessary for the mechanism to work.

packages
LaTeX’s mechanism can be extended by some packages:

  • hyperref makes references click-able hyper links (and has some more features).
  • cleveref finds the right names for labels and prints \ref{anchor5} as section~5 instead of 5, for instance.
  • varioref compares the page numbers of anchor and reference and add text like on previous page, on page 6 etc. automatically.
  • nameref can print the actual title of an anchor.

MWE

\documentclass[english]{article}

% langage
\usepackage{babel}

% only for \lipsum blind text
\usepackage{lipsum}

% ref packages
\usepackage{nameref}
% folowing  must be in this order
\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}
\section{First section}
\lipsum[1-10]

\section{My section}\label{sec:mysection}
\lipsum[1-22]

\section{References}
\begin{itemize}
    \item \verb+\ref{sec:mysection}+: \ref{sec:mysection}
    \item \verb+\pageref{sec:mysection}+: \pageref{sec:mysection}
    \item \verb+\cref{sec:mysection}+: \cref{sec:mysection}
    \item \verb+\cpageref{sec:mysection}+: \cpageref{sec:mysection}
    \item \verb+\vref{sec:mysection}+: \vref{sec:mysection}% already combined with \cref
    \item \verb+\vpageref{sec:mysection}+: \vpageref{sec:mysection}
    \item \verb+\nameref{sec:mysection}+: \nameref{sec:mysection}
\end{itemize}
\end{document}

different references

Related Question