I am writing a book with multiple chapters (in different sections, if that is relevant). Chapters are numbered. I want a way to transform the chapter name into the chapter number, someplace else in my text. That is, I want to say "See Chapter 4, which covers magic in depth". The chapter that is responsible for covering magic in depth may change over the course of the editing process: I want the chapter number to change with it automatically. I don't want to refer to the name alone. I am using LaTeX's autonumbering for chapters. Is this possible?

Package nameref and \nameref{chapterlabel} should work, where chapterlabel is something you stated right after \chapter{Magic} , say e.g. \label{magicchapter}. But your request is a little confusing since there seem to be wanted two different behaviours of the reference?
– user31729May 17 '14 at 13:49

1

Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729May 17 '14 at 13:50

@ChristianHupfer I think \nameref*{CurrentSection::Title::<something>} and printing the section counter along with it, is what he's looking for. Similar to how you determined the CurrentSection counter at the Index for the request I made here tex.stackexchange.com/questions/175054/…
– 1010011010May 17 '14 at 14:09

@1010011010: Perhaps it is similar, perhaps the answer I gave to your question is useful too.
– user31729May 17 '14 at 14:14

@1010011010 , your answer is something I would prefer not to get into: my knowledge of LaTeX is self taught, rather limited, and does not extend to many of the commands used in your version. If there is a simpler way to solve my problem, one that doesn't require pages of code, that would be lovely. I will write it if I have to, but I am hoping that there is a simpler method.
– Keller SchollMay 17 '14 at 17:00

2 Answers
2

LaTeX provides this cross-referencing scheme out-of-the-box. Place \label{<label>} after a counter that can be referenced (like a chapter, section, subsection, theorem, ...) and use it elsewhere as \ref{<label>}. This will only return the counter number and nothing else:

\documentclass[openany]{book}
\usepackage[paper=a6paper]{geometry}% Just for this example
\usepackage{xparse,nameref}
\NewDocumentCommand{\chapref}{s m}{Chapter~\ref{#2}\IfBooleanF{#1}{ \nameref{#2}}}
\begin{document}
\chapter{Sample 1}\label{ch:first}
This is covered in more detail in \chapref*{ch:second}. Also see~\ref{ch:second}.
\chapter{Sample 2}\label{ch:second}
This is covered in more detail in \chapref{ch:first}. Also see~\ref{ch:first}.
\end{document}

The above example sets the \labels after every \chapter. They're referenced using \ref{<label>}, which clearly just returns the chapter number. However, with the addition of nameref we can grab hold of the chapter title as well, referencing it as \nameref{<label>}. A combination of \ref and \nameref is incorporated in what I defined as \chapref, which translates to Chapter~\ref{<label>} \nameref{<label>}. The latter \nameref is conditional on whether you call \chapref with/without a star *.

The above example can be made fully-functional with hyperref, providing inter-document hyperlinking.

The option [openany] was just so the two chapters fit on subsequent page and is not needed in your document.

As an alternative to Werner's code, you could also use one of the packages which set this up for you automatically. fancyref and cleveref are two which spring to mind. For example:

\documentclass[openany]{book}
\usepackage[paper=a6paper]{geometry}% Just for this example
\usepackage{fancyref}
\begin{document}
\chapter{Sample 1}\label{chap:first}
This is covered in more detail in \fref{chap:second}. Also see~\ref{chap:second}. \Fref{chap:second} covers this in excruciating detail.
\chapter{Sample 2}\label{chap:second}
This is covered in more detail in \fref{chap:first}. Also see~\ref{chap:first}. \Fref{chap:first} covers this in more detail.
\end{document}

Note that chapter is added automatically if the chap prefix is used in the label, and that \Fref and \fref produce capitalised and non-capitalised output. (I believe that cleveref automatises things further but I've not used it myself.)