# lastpage package: incompatibility with nameref package

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}}
}
\tableofcontents
\listoffigures
\pagestyle{plain}
Text.
%\input{./ch1.tex}
%\input{./ch2.tex}
%\input{./ch3.tex}
%\input{./ch4.tex}
%\input{./biblio.tex}
\end{document}

-

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}}
}


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

lastpage 2012/01/28 v1.2l has been submitted to CTAN to fix the incompatibility with nameref and should soon become available there.

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

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


\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.