I try to compile several .tex in a main document, so i use the package subfiles. I want to display for each inputed file the page number of the current page relatively to the inputed file, and also to display the total pages of this inputed file on each its page ; and this for all the inputed files. I'm near to sucess but ... I use a local counter for the number of page, and several counters for the total page amount of each inputed file (using the package totcount).

I have simplified the code, so here I have one main file "main-file.tex", and 3 folders "Ch1", "Ch2", and "Ch3", the first containing the file "Ch1-2nde.tex", the second containing the file "Ch2-2nde.tex", and the last the file "Ch3-2nde.tex". Here is the code I use for main-file.tex :

    \RequirePackage[a4paper, top=0.5cm, bottom=1.6cm, left=0.7cm , right=0.7cm]{geometry}


        \filename@parse{#1}% LaTeX's file name parser
        \newpage %ajout ici pour sauter automatiquement une page entre

    %to create counter "compteurChi" "compteurChii" ..., and \roman because no
    %number is supported as a counter name.


            {\textbf{\huge Chapitre #1}}

        \fancyfoot[C]{\textbf{Page \thepage / \pageref{LastPage} }}
            \fbox{\bfseries \thelocalPage} / \total{compteurCh\theAuxCounter}}



Here the code in Ch1-2nde.tex :

    Ch1 first page
    Ch1 second page
    Ch1 third page

The code in Ch2-2nde.tex :

    Ch2 first page
    Ch2 second page
    Ch2 third page

The code in Ch3-2nde.tex :

    Ch3 first page
    Ch3 second page
    Ch3 third page

So, The problem is even if I compile two times, there is still "??" left at the bottom left side for the two first inputed files (the counter value of compteurChi and compteurChii are not present in the .aux file ... And I don't know why).

Please, some help ^^.

  • 1
    The compteurCh counters are defined after \begin{document}, this screws the totcount system up – user31729 May 15 '15 at 1:38
  • If I put the block : \multido{\i=1+1}{3}{% \setcounter{AuxCounter}{\i} \newcounter{compteurCh\theAuxCounter} \regtotcounter{compteurCh\theAuxCounter} } before the \begin{document} nothing change, it stays as before. – math45 May 15 '15 at 2:02
  • \newcounter should be used in the preamble only – user31729 May 15 '15 at 2:08
  • by writing \setcounter{AuxCounter}{1} \newcounter{compteurChi} \regtotcounter{compteurChi} \newcounter{compteurChii} \regtotcounter{compteurChii} \newcounter{compteurChiii} \regtotcounter{compteurChiii} in the preamble, it worked. So the problem comes from the loop .... Do you know how to solve this ? Thanks – math45 May 15 '15 at 2:21
  • math45: Loops with command definitions (which is true for \newcounter too) are always tricky, due to grouping effects – user31729 May 15 '15 at 8:16

This problem is solved by egreg in this post

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.