GeneralLatex inserts blank page at end problem: package conflicts?

LaTeX specific issues not fitting into one of the other forums of this category.
nanomir
Posts: 7
Joined: Fri Jan 09, 2009 6:39 pm

Latex inserts blank page at end problem: package conflicts?

Post by nanomir »

Hi all,

I'm having a problem with Latex inserting blank page at end of a document. Here is a minimal example:

Code: Select all

\documentclass{article} 
\usepackage[utf8]{inputenc} 

\usepackage[T1]{fontenc}
\usepackage{ae,aecompl} 

% comment any of these three - and the blank page at end is gone !!
\usepackage{float} 
\usepackage{lastpage}
\usepackage{minitoc} 


\title{Test document}

\begin{document}

\section{Introduction}

Welcome to the introductory section !!! 

\end{document}
I'm thinking it's some sort of a conflict between float, lastpage and minitoc - since as soon as one of them is commented, then the undesired blank page at end of the document is gone?

Can anyone confirm this problem? What could I do to rid of the blank page at end, if I do want to use all of these three packages?

Thanks... Cheers ! :D

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Latex inserts blank page at end problem: package conflicts?

Post by localghost »

I can't comprehend this behaviour when compiling your code. Perhaps a matter of outdated package versions. Start a run on the following code.

Code: Select all

\listfiles
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}  % supersedes ae

\usepackage{float}
\usepackage{lastpage}
\usepackage{minitoc}

\usepackage{blindtext}

\title{Test document}
\author{nanomir}

\begin{document}
  \blinddocument
\end{document}
Afterwards search the log file and post the section between *File List* and *********** here (using the code environment).


Best regards and welcome to the board
Thorsten¹
nanomir
Posts: 7
Joined: Fri Jan 09, 2009 6:39 pm

Latex inserts blank page at end problem: package conflicts?

Post by nanomir »

Hi localghost,

Thanks much for the prompt response !! First of all, I forgot to mention that I'm using Miktex 2.7 on an XP.

I did the procedure you recommended, and besides pdflatex complaining that "! Package babel Error: You haven't loaded the option english yet.", here is the file list section:

Code: Select all

 *File List*
 article.cls    2005/09/16 v1.4f Standard LaTeX document class
  size11.clo    2005/09/16 v1.4f Standard LaTeX file (size option)
inputenc.sty    2006/05/05 v1.1b Input encoding file
    utf8.def    2006/03/30 v1.1i UTF-8 support for inputenc
   t1enc.dfu    2006/03/30 v1.1i UTF-8 support for inputenc
  ot1enc.dfu    2006/03/30 v1.1i UTF-8 support for inputenc
  omsenc.dfu    2006/03/30 v1.1i UTF-8 support for inputenc
 fontenc.sty
   t1enc.def    2005/09/27 v1.99g Standard LaTeX file
 lmodern.sty    2007/01/14 v1.3 Latin Modern Fonts
   float.sty    2001/11/08 v1.3d Float enhancements (AL)
lastpage.sty    1994/06/25 v0.1b LaTeX2e package for refs to last page number (
JPG)
 minitoc.sty    2008/07/16 v60 Package minitoc (JPFD)
 mtcmess.sty    2006/03/14
  tester.mtc0
 english.mld    2006/01/13
 english.mld    2006/01/13
blindtext.sty    2006/11/21 V1.7 blindtext-Package
  xspace.sty    2006/05/08 v1.12 Space after command names (DPC,MH)
   t1lmr.fd    2007/01/14 v1.3 Font defs for Latin Modern
  omslmr.fd    2007/01/14 v1.3 Font defs for Latin Modern
 omslmsy.fd    2007/01/14 v1.3 Font defs for Latin Modern
 ***********
Hmm... indeed, some widely varying versions - in particular lastpage being from 1994 :) Any suggestions on how I perform an update?

Thanks,
Cheers ! 8-)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Latex inserts blank page at end problem: package conflicts?

Post by localghost »

nanomir wrote:[...] I did the procedure you recommended, and besides pdflatex complaining that "! Package babel Error: You haven't loaded the option english yet." [...]
A fault of mine. The blindtext package demands babel loaded with a language option (here english). Otherwise this warning is the result.
nanomir wrote:[...] Hmm... indeed, some widely varying versions [...] Any suggestions on how I perform an update? [...]
Just use the MiKTeX Package Manager (Start -> Programs -> MiKTeX -> Browse Packages).
nanomir
Posts: 7
Joined: Fri Jan 09, 2009 6:39 pm

Re: Latex inserts blank page at end problem: package conflicts?

Post by nanomir »

localghost,

Thanks again for the response !! Maybe I should mention that I'm trying to use a 'portable' MikTex as per http://ftp.math.purdue.edu/mirrors/ctan ... -HOWTO.txt ... So, to start the package manager, I just had to start the environment, and then from command line type mpm; and then chose Repositories/Update Wizard.

The first message from mpm is a complaint that MikTex is not properly installed; but it still runs the update OK, and then on second update it notices it is at latest version. Interestingly, lastpage is not among the packages to be updated; Miktex reports it as packaged on 2001-05-14, yet even after update, when I compile the minimal example, I still get the blank page - and the exact same filelist (btw, looked in texmf\tex\latex\lastpage\lastpage.sty, and indeed, it says: "\def\filedate{1994/06/25}")

Apparently, that is the latest version of lastpage Miktex offers.. Can I maybe obtain a .sty file from somewhere else, and then just update it manually (i.e. by overwriting the .sty file)?

Thanks.. Cheers !
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Latex inserts blank page at end problem: package conflicts?

Post by phi »

nanomir wrote:Hmm... indeed, some widely varying versions - in particular lastpage being from 1994 :)
Your packages are not too old—they are too new! I don't get an empty page with an older version of minitoc, but with the current version, I do get one. Load lastpage after minitoc to make it work.
The problem here is that both packages write something at the end of the document, and the order of those writes is important. lastpage wasn't updated since 1994 since its implementation is seemingly trivial:

Code: Select all

\def\lastpage@putlabel{\addtocounter{page}{-1}%
   \immediate\write\@auxout{\string
   \newlabel{LastPage}{{}{\thepage}}}%
   \addtocounter{page}{1}}
\AtEndDocument{%
   \message{AED: lastpage setting LastPage}%
   \clearpage\lastpage@putlabel}%
Read the section on \BeforeClosingMainAux in the KOMA-Script guide for an explanation why this leads to problems. A solution is also provided there:

Code: Select all

\listfiles
\documentclass[english,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}  % supersedes ae
\usepackage[T1]{fontenc}
\usepackage{babel}

%\usepackage{lastpage}
\usepackage{scrlfile}
\usepackage{float}
\usepackage{minitoc}

\usepackage{blindtext}

\makeatletter
\BeforeClosingMainAux{%
  \if@filesw
    \addtocounter{page}{-1}%
    \immediate\write\@auxout{\noexpand\newlabel{LastPage}{{}{\thepage}}}%
    \addtocounter{page}{1}%
  \fi
}
\makeatother

\title{Test document}
\author{nanomir}

\begin{document}
\pageref{LastPage}
  \blinddocument
\end{document}
nanomir
Posts: 7
Joined: Fri Jan 09, 2009 6:39 pm

Latex inserts blank page at end problem: package conflicts?

Post by nanomir »

Dear phi,

Thanks so much for your reply!!
Load lastpage after minitoc to make it work.
Indeed, that was it:
instead of

Code: Select all

\usepackage{lastpage} 
\usepackage{minitoc}
which results with "Output written on tester2a.pdf (2 pages, 48532 bytes)."; using this:

Code: Select all

\usepackage{minitoc}
\usepackage{lastpage} %Load lastpage after minitoc to make it work.
results with "Output written on tester2a.pdf (1 page, 47901 bytes)."

Thank you all for the great help !!

Cheers ! :D :D :D
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Latex inserts blank page at end problem: package conflicts?

Post by phi »

Concerning my remark about \AtEndDocument: I've just read the whole lastpage documentation, and indeed it documents this behavior, so technically it's not a bug. Because we have scrlfile now, the author's wishlist could finally be fulfilled (after 14 years!), albeit in another way than suggested by the author.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Latex inserts blank page at end problem: package conflicts?

Post by phi »

This approach combines the advantages of \BeforeClosingMainAux (always correct number) and the memoir code (no special casing for hyperref, arbitrary formatting):

Code: Select all

\RequirePackage{scrlfile}
\newcounter{lastpage}
\def\lastpage@write@label{%
  \if@filesw
    \immediate\write\@auxout{\global\c@lastpage\number\numexpr\c@page-1\relax\relax}%
  \fi
}
\BeforeClosingMainAux{\lastpage@write@label}
However, clickable links aren't possible this way, but I think this is acceptable.
sdaau
Posts: 26
Joined: Fri Feb 19, 2010 2:08 pm

Latex inserts blank page at end problem: package conflicts?

Post by sdaau »

Hi all,

Thanks for the discussion here. I was experiencing a problem with \pageref{LastPage}.

With my current list of packages, just loading lastpage after minitoc didn't work for me: when Latex would encounter my definitions like \newcommand{\mycommand} (which otherwise passed), including lastpage after minitoc would result with:

Code: Select all

! LaTeX Error: Command \mycommand already defined.
               Or name \end... illegal, see p.192 of the manual.
Commenting lastpage, and using instead the code from phi in post #pr14259 with \usepackage{scrlfile} and \BeforeClosingMainAux passes during the first time I compile; but the second time crashes with:

Code: Select all

Runaway argument?
{\@secondoffive }\fi  
! Paragraph ended before \Hy@setref@link was complete.
... In the end, I somehow stumbled upon Google Translate: lastpage.styとhyperref.styの競合について; from where I found the page [qa:46490] Re: lastpage.styとhyperref.styの競合について with code that worked for me with hyperlinks - I just had to modify the counters so that they modify by 1 and not by 2 in my case; the MWE example being:

Code: Select all

\documentclass{article}
\makeatletter
    \def\lastpage@putlabel{%
      \addtocounter{page}{-1}%
      \if@filesw
        \begingroup
          \let\@number\@firstofone
          \ifHy@pageanchor
            \ifHy@hypertexnames
              \ifHy@plainpages
                \def\Hy@temp{\arabic{page}}%
              \else
                \pdfstringdef\Hy@temp{\thepage}%
              \fi
            \else
              \def\Hy@temp{\the\Hy@pagecounter}%
            \fi
          \fi
          \immediate\write\@auxout{%
            \string\newlabel
              {LastPage}{{}{\thepage}{}{%
                \ifHy@pageanchor page.\Hy@temp\fi}{}}%
          }%
        \endgroup
      \fi
      \addtocounter{page}{1}%
    }%
\AtEndDocument{%
   \message{AED: lastpage setting LastPage}%
   \clearpage\lastpage@putlabel}%
\makeatother
\usepackage{hyperref}
\begin{document}
test\clearpage
test. \pageref{LastPage}
\end{document}
which now compiles fine, also with hyperlink.
Post Reply