1

I am trying to configure the aaltothesis class here (.cls file here). The .cls file is designed with the roman pagenumbering for the pages 2-4 i.e. for abstract pages but arabic numbers for pages 5-777. However, the following Line 1 affects the global page numbering for some reason:

  • if you change the line one to line two, you get arabic page numbering in pages 5-777.
  • if you keep the line 1, you get the roman pagenumbering not in pages 2-4, but instead in pages 5-777

    %\pagenumbering{roman}% Line 1% https://tex.stackexchange.com/a/330691/13173 
    \pagenumbering{arabic}% Line 2
    

My .tex file

\documentclass[english,12pt,a4paper,utf8]{aaltothesis}
\usepackage{mathtools, amssymb, amsbsy}

%% Xelatex
%\usepackage{polyglossia} % also loads package fontspec
%\usepackage{unicode-math} % if you also need maths
%% Pdftex
\usepackage[T1]{fontenc}% %  https://tex.stackexchange.com/q/330683/13173
\usepackage{inputenc}% For scands in both Finnish and English input docs % https://tex.stackexchange.com/q/330683/13173
\setmainlanguage{english} % loads language hyphenation rules and such

\begin{document}
Lorem
\end{document}

Shortened version of .cls code but full here

You see Roman numbering which should be correct

% See full copyright here http://paste.ubuntu.com/23212741/
\NeedsTeXFormat{LaTeX2e}%
\ProvidesClass{aaltothesis}[2015/09/24 Aalto Univ. ELEC thesis class v2.2]%
\RequirePackage{ifthen}%
%

%%%%%%% Storage of number of pages and number of abstracts %%%%%%%
\newcounter{NMainPages}%
\newcounter{NInitPages}%
\newcommand*{\storeinipagenumber}{%
\immediate\write\@auxout{\string\setcounter{NInitPages}{\arabic{page}-1}}%
}%
\AtEndDocument{%
\immediate\write\@auxout{\string\setcounter{NMainPages}{\thepage}}%
}%

% ...

\endinput

Experimenting David's answer

Now, I have the following but it will not reliably get the last number of the document

\immediate\write\@auxout{\string\setcounter{NMainPages}{\arabic{page}}}%

How can you have stable last number of the document without \immediate and with the package lastpage?

OS: Debian 8.5
TeXLive: 2016
LaTeX execution machine: pdftex, XeLaTeX
.cls file: here

  • 1
    You have to use decimal numbers, even if they are later typeset as roman numerals. In this case, use \setcounter{NMainPages}{13}. – gernot Sep 21 '16 at 17:47
  • This is a spurious error. The class is not intended to be used this way. Have a look at thesistemplate.tex: After all the introductory stuff, the command \pagenumbering{arabic} appears, before the main matter starts. Without this, \thepage will produce a roman numeral at the end of the document; with it, everything is fine. (Note that the problem is triggered by NMainPages, not NInitPages.) I suggest that you start from thesistemplate.tex provided by the university and adapt it to your needs. In any case it has nothing to do with package calc. – gernot Sep 21 '16 at 18:05
  • 1
    @Masi Why do you want to fix it? Even if the class code is not robust and cannot handle situation for which it was not intended, it works when you start from the thesistemplate. If you don't mind the effort, you can contact the maintainer, but I don't see a quick fix since there should be done more than just replacing \thepage. – gernot Sep 21 '16 at 18:20
  • 1
    @Masi To rewrite the cls file, you need an adequate reference telling how the thesis should be formatted. Then you can start from an already existing class and adapt it. And use command like \frontmatter, \mainmatter, \backmatter that will take care of appropriate page numbering etc. For pragmatic reasons, though, I'd rather spend the time on completing the thesis and live with the imperfect university style. Just my personal experience with students finishing late ;-) – gernot Sep 21 '16 at 18:37
  • 4
    You posted a class file that is not the original, and you removed the copyright notice. That is known as copyright infringement. You should fix that. – Johannes_B Sep 21 '16 at 18:40
3
\immediate\write\@auxout{\string\setcounter{NMainPages}{\thepage}}%

is clearly wrong, a fix to the immediate problem would be to write the number as a number so

\immediate\write\@auxout{\string\setcounter{NMainPages}{\arabic{page}}}%

however this will not reliably get the last number of the document, not having \immediate would help, but an accurate number requires more careful control of any final float pages that may generate output at \end{document} You could look at the lastpage package for some details.

| improve this answer | |
  • 1
    @Masi huh??? you have \pagenumbering{roman}% which fairly clearly sets roman numbering that is what caused the error. see Johannes comments above, you presumably do not want teh entire document with roman page numbering and the class is not written to support that, so you should just fix your document not to do that. – David Carlisle Sep 21 '16 at 19:55
  • 2
    @Masi no it has nothing to do with xetex. If you look at the template.tex at the link you provided it clearly shows the page numbering being set back to arabic for the main text you have not followed those instructions so you got an error. it is unrelated to xetex or anything else mentioned in the question. – David Carlisle Sep 21 '16 at 20:22
  • 1
    @Masi you got the error specified in the original question with setcounter failing on a roman number, if you have edited the class to allow roman numbers then you will get no error but it is still wrong to have the whole document with roman numbers, just not a tex error. – David Carlisle Sep 21 '16 at 20:26
  • You are right about execution machine - I can reproduce the problem in pdflatex and xetex now. - - Yes, enabling roman puts the document to roman, which is wrong like you say. This is the thing which I do not understand at the moment. – Léo Léopold Hertz 준영 Sep 21 '16 at 20:37
  • 3
    @Masi I can not understand how it can be confusing, there is nothing subtle about this \pagenumbering(roman} makes the page numbers be in roman until you specify \pagenumbering{arabic} to turn that off. The template you were supposed to follow does that but your document does not. – David Carlisle Sep 21 '16 at 20:44

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.