0

I have tried to write a program that will let users input a file as an appendix. These pages should be numbered with roman numbers. It has worked well, but now I am trying to make an improvement: If the user do not have an appendix I would like the pagecounter to be set to zero. My approach was to set a counter to zero and have it updated in the document command. I can see that I have missed something, but I cannot find out what. Can someone direct me to a solution? Here is an example

\documentclass[a4paper,12pt]{article}

\usepackage{xparse}
\usepackage{pageslts}

\newcounter{Appcount}
\setcounter{Appcount}{0}

\ExplSyntaxOn

\NewDocumentCommand{\app}{m}
{
    \newpage
    \pagenumbering{roman}
    \fancyhf{}
    \rhead{\itshape Side \, \thepage\ av \, \lastpageref{pagesLTS.roman}}
    \appendix

    \section*{Vedlegg}
    \input{#1}

    \setcounter{Appcount}{\lastpageref{pagesLTS.roman}}

}

\ExplSyntaxOff

\begin{document}


    \app{filename.tex} %can be left out

    Number of pages in the appendix: \theAppcount
\end{document}
  • 3
    You should mention what doesn't work. – Ulrike Fischer Apr 29 at 8:03
  • Sorry, what doesn't work is that the \setcounter{Appcount}{\lastpageref{pagesLTS.roman}}. The counter will always be zero, but the number of pages shown in the appendix is correct. – Per G. Østerlie Apr 29 at 11:56
1

\lastpageref{pagesLTS.roman} is not a number and can not be used in a \setcounter. You can try the refcount package and the label pagesLTS.roman.local provided by pageslts:

\documentclass[a4paper,12pt]{article}

\usepackage{xparse}
\usepackage{pageslts}
\usepackage{fancyhdr}
\newcounter{Appcount}
\setcounter{Appcount}{0}
\usepackage{refcount}
\ExplSyntaxOn
\NewDocumentCommand{\app}{m}
{
    \newpage
    \pagenumbering{roman}
    \fancyhf{}
    \rhead{\itshape Side \, \thepage\ av \, \lastpageref{pagesLTS.roman}}
    \appendix

    \section*{Vedlegg}
    \input{#1}
    \setcounter{Appcount}{\getpagerefnumber{pagesLTS.roman.local}}

}

\ExplSyntaxOff

\begin{document}


    \app{test3.tex} %can be left out

    Number of pages in the appendix: \theAppcount
\end{document}
| improve this answer | |

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.