6

When I try to use the nameref package together with the lastpage package (version earlier than 2013/01/28, of course) I have following two errors:

! Package lastpage Error: no auxiliary file allowed
! Extra \else

But without the nameref package (and referencing chapters by names) my LaTeX document builds without problems.
What does this error mean? And what are possible causes?

My document file:

\documentclass[a4paper,oneside,12pt]{report}
\usepackage[polish]{babel}
\usepackage[latin2]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{indentfirst}
\usepackage{titlesec}
\usepackage{nameref}
\usepackage{lastpage}
\usepackage{fancyhdr}
\onehalfspacing
\titleformat*{\section}{\normalsize\bfseries}
\setlength{\parindent}{1cm}
\begin{document}
\pagestyle{plain}
Text.
%\input{./title.tex}
\pagenumbering{arabic}
\fancypagestyle{plain}{% 
    \fancyhf{}
        \fancyfoot[C]{Strona \normalsize\thepage\ z \pageref{LastPage}}
    \renewcommand{\headrulewidth}{0pt} % remove line between header and main text
}
\tableofcontents
\listoffigures
\pagestyle{plain}
Text.
%\input{./ch1.tex}
%\input{./ch2.tex}
%\input{./ch3.tex}
%\input{./ch4.tex}
%\input{./biblio.tex}
\end{document}
8

For some reasons, nameref and lastpage fight each other when trying to do something to the .aux file just before finishing.

All works if you say

\usepackage{zref-user,zref-lastpage}

instead of \usepackage{lastpage} and

\fancypagestyle{plain}{%
  \fancyhf{}
  \fancyfoot[C]{\normalsize Strona \thepage\ z \zpageref{LastPage}}
  \renewcommand{\headrulewidth}{0pt} % remove line between header and main text
}

Note the command \zpageref. (Also \normalsize should go before Strona).

  • Works like a charm :) – Michał Herman Jan 27 '13 at 11:43
  • "For some reasons, nameref and lastpage fight each other when trying to do something to the .aux file just before finishing." Well, the reason was a little bit different (see my answer), but zref-lastpage works, of course. – Stephen Jan 28 '13 at 19:42
3

Since lastpage 2012/01/28 v1.2l the incompatibility with nameref is fixed.

The nameref package redefines \label to have five arguments instead of two, therefore

\newlabel{LastPage}{{}{\thepage}{}{}{}}

instead of

\newlabel{LastPage}{{}{\thepage}}

must be used in the lastpage package, when also nameref is used in the document. (When nameref and hyperref were both used, there was no problem, because hyperref uses another label format, which was already regarded by lastpage.)

Using lastpage since version 1.2l, 2013/01/28, your MWE works without any problem.

Thanks for reporting the incompatibility! (See at Acknowledgements and History in the package's documentation.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.