I'm seeing the following error messages from pdflatex on a really gigantic project:
(see the transcript file for additional information)pdfTeX warning (dest): name
{lstnumber.-14.11} has been referenced but does not exist, replaced by a fixed
one
pdfTeX warning (dest): name{lstnumber.-18.22} has been referenced but does not
exist, replaced by a fixed one
pdfTeX warning (dest): name{lstnumber.-9.40} has been referenced but does not e
xist, replaced by a fixed one
pdfTeX warning (dest): name{lstnumber.-4.3} has been referenced but does not ex
ist, replaced by a fixed one
The top of my main file looks like this:
\documentclass[ebook,10pt,oneside,final]{memoir}
\usepackage{microtype}
% support for code listings
\usepackage[final]{listings}
\include{autodedent}
\lstset{
basicstyle=\ttfamily\footnotesize,
numberstyle=\footnotesize,
breaklines=true,
numbers=left,
firstnumber=1,
rangeprefix=//,
includerangemarker=false
}
% support for indexing
\usepackage{makeidx}
\makeindex
% make _ a non-special character
\usepackage{underscore}
% support for cross-references
\usepackage{hyperref}
% \newcommand{\href}[2]{#2}
% fix spacing in \tableofcontents
\renewcommand\partnumberline[1]{#1\hspace{1em}}
% custom commands for use in the text of the book itself
\newcommand{\newterm}[1]{\textit{#1}}
\newcommand{\code}[1]{\mbox{\lstinline[basicstyle=\ttfamily]$#1$}}
\newcommand{\slurl}[1]{\href{https://#1}{\textsl{#1}}}
\newcommand{\codeblock}[2]{\label{foo#1#2}\hspace{1em}\lstinputlisting[linerange=ex#2-dex#2,autodedent]{examples-ch#1.cc}}
\newcommand{\codeblockref}[2]{\pageref{foo#1#2}}
\newcommand{\Csharp}{C\#}
\begin{document}
\frontmatter
\include{preface}
\tableofcontents
\mainmatter
% ...and so on...
An example of \codeblock from the body of the text:
Let's write a function to multiply each of the elements
in an array by 2.
\codeblock{1}{1}
Our function \code{double_each_element} works \emph{only} with objects of type
\code{array_of_int}...
And an example of \codeblockref:
Compare this version of the code to the version on page
\codeblockref{1}{1}.
Unfortunately, if you throw just these snippets together in a test file and run pdflatex test.tex; pdflatex test.tex — it works fine! (Except that the hyperlink on the number "1" actually goes to the table of contents, not to page 1.) But when I do the same thing at the scale of many chapters, I get the error messages about lstnumber.-14.11 seen at the top of this question.
I did find out that lstnumber.-<some number> is the format of the labels that are auto-generated by the listings package, so I assume this is some bad interaction between listings and hyperref. But what exactly is going wrong and what can I do to fix it?
The \hspace{1em} in my \codeblock macro was my naïve attempt to work around the bug described here, in case that was the problem.
\labelinto thelabel={lst:#1-#2}parameter to\lstinputlisting, or is there something else happening in there also? – Quuxplusone Apr 19 '17 at 05:26\lstinputlistinguses\refstepcounterautomatically and then applies the label. Your approach with\phantomsectionis an unnecessary by-pass, because\phantomsectionintroduces phantom anchors that are grabbed by\label(actually byhyperrefin the background) – Apr 19 '17 at 05:28