0

When using the twoside in the article class, resetting the page counter creates an issue in regards to the odd and even side margins. Is it possible to declare a custom counter that article considers the page counter for odd/even sides?

\documentclass[twoside]{article}
\usepackage{everypage}
\usepackage{lipsum}
\newcounter{technicalpage}
\setcounter{technicalpage}{1}
\AddEverypageHook{\stepcounter{technicalpage}}
%------ For counting and referring correctly ------%
\makeatletter
\newcounter{labelnumber}
% Same as \label, but also specify counter
\def\setlabel#1#2{\@bsphack%
    \protected@write\@auxout{}%
    {\string\newlabel{#1}{{\@currentlabel}{\csname the#2\endcsname}}}%
    \@esphack}
\def\getpage#1{%
    \bgroup%
  % Define current label (temporarily within group)
    \edef\@currentlabel{\the\csname c@#1\endcsname}%
  % Set a unique label name (unique by counter).
  % Extra {} for intention to use with \expandafter
    \xdef\tst@labelName{{page:labelno:\thelabelnumber}}%
    \stepcounter{labelnumber}%
  % Set the label
    \expandafter\setlabel\tst@labelName{#1}%
  % Do pageref to display page
  \expandafter\pageref\tst@labelName%
    \egroup%
}
\makeatother
%------ End counting / referring ------%
\begin{document}
  \pagenumbering{roman}%
  %On page 1 (even)
  This is page \getpage{page} for intro stuff and the page counter will reset further down. Technically page \getpage{technicalpage}.\par\lipsum
  \pagenumbering{arabic}
  Claims to be page \getpage{page}, but is technically page \getpage{technicalpage}\space and should, internally, be treated as such.
  % Should say page 1, as it is, but should be treated like even with regards to margins,
  % because it's technically the second page. So I want't article to consider
  % \c@technicalpage as the counter for determining odd/even page.


   TP=\getpage{technicalpage}
aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\
aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\aaa\\
aaa\\aaa\\
   TP=\getpage{technicalpage}

\end{document}

I found it really odd that I couldn't find any answers on this? Maybe I've searched for the wrong things?

Related: Odd/even page margins - an odd page has "even page margins", which does not in my opinion provide a sufficient answer at the time of writing.

Edit/remark: I am aware of the \cleardoublepage and how it should be used before \pagenumbering, as \pagenumbering intends. However, I'd like to solve this matter in another way than skipping an extra page.

David Carlisle
  • 757,742
  • 1
    You could do this but won't the reader find it very strange to have odd numbered pages on the left side of a spread? – David Carlisle Dec 13 '18 at 09:34
  • 1
    the question isn't that clear but you don't have to use \pagenumbering: If you just want to change the number format without resetting to 1 then use \renewcommand\thepage{\arabic{page}} not \pagenumbering{arabic} – David Carlisle Dec 13 '18 at 09:39
  • 2
    As David wrote: in twoside documents, odd page numbers should be on the right. Everything else is very irritating for the reader. – Ulrike Fischer Dec 13 '18 at 09:42
  • 1
    One reason that the question is not clear is that it isn't clear how you intend to use these commands, The example used both \thepage and \thetechnicalpage in the body text but neither is safe in that context, page references are only guaranteed to give the right number in the page head and foot, in the body you need to use \pageref (and define a similar command for technicalpage references. – David Carlisle Dec 13 '18 at 09:42
  • @DavidCarlisle I see your point, and agree with that odd numbers should on the right. However, I still want to know how one would approach doing this, for educational purposes. – Andreas Storvik Strauman Dec 13 '18 at 09:52
  • @DavidCarlisle In regards to \thepage and \thetechnicalpage: wouldn't \thetechnicalpage work here due to the everypage package, assuming no one else redefines \thetechnicalpage? – Andreas Storvik Strauman Dec 13 '18 at 09:56
  • No, it will work like \thepage and give the number the last time a page was shipped out but that may or may not be the page that text lands on if there is a paragraph broken over a page, or a float is inserted that pushes this on a page. Try using a paragraph with \thetechnicalpage at the start and the same at the end, the two values will always be the same, even if the paragraph breaks over one or more pages, – David Carlisle Dec 13 '18 at 10:15
  • @DavidCarlisle better now? – Andreas Storvik Strauman Dec 13 '18 at 10:20
  • @AndreasStorvikStrauman Not really: I still can not guess the intention here, sorry. I added another paragraph which shows \getpage{technicalpage} returning 2 on both page 2 and page 3, which is what I would expect, but I can not guess what you want. – David Carlisle Dec 13 '18 at 10:27
  • @DavidCarlisle I thought you understood what I wanted earlier: Consider the algorithm that sets the margins provided by \oddsidemargin and \evensidemargin. I assume that this algorithm, that probably exists somewhere in article.cls, uses the page counter to decide whether a page is even or odd. However, I want said algorithm to base it's odd / even decision on a different counter, so that when the page counter is reset, the margins stay correct. Even when this entails having even numbers on the right side. – Andreas Storvik Strauman Dec 13 '18 at 10:33
  • 1
    It is easier to have the page counter being the internal value used to decide on odd or even pages and just print a value other than page (eg \thetechnicalpage in the page foot) because \ifodd\c@page is used _everywhere(margin setting, positioning of \marginpar, ...) in the format itself and in dozens of packages, and if you change that they will all break, but almost nothing assumes that you print the value of\thepage` in the document. – David Carlisle Dec 13 '18 at 12:15

0 Answers0