0

I have a document in which the displayed page number goes from 8 on the 8th page to 0 on the next page. Unfortunately I cannot provide the code because the document is confidential and when I replace the code by \lipsums to de-confidentialise it the resetting ceases.

I tried debugging the problem with lots of \thepage commands to see where the page number changed inappropriately. It appears to do that after a section of highlighted text in the environment \hl{...} from package soul.

At first it appeared that this only happened when the environment spanned the soft page break. But later I found it happening even in a case where the \hl environment was near but did not span the soft page break.

Is anybody aware of known problems of interactions between soul's \hl environment and the page counter, and how to circumvent them? Or if not, of interactions with other packages that can cause unwanted page counter resets. I have searched the code and it definitely contains no explicit counter commands such as \setcounter or \newcounter in the code.

Thank you

Although I cannot provide the document code, I can provide the preamble that shows what packages I am using:

\documentclass[11pt,a4paper]{article}
\usepackage[margin=0.75in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{breqn}
\usepackage{xypic} % for commutative diagrams
\usepackage{color}
\usepackage[hidelinks]{hyperref}
\usepackage{soul}
\usepackage{graphicx}
\usepackage{epstopdf}
%\usepackage[square,sort,comma,numbers]{natbib}
\usepackage[authoryear]{natbib}
\usepackage[usenames,dvipsnames]{xcolor}
\newcommand{\hlc}[2]{ {\sethlcolor{#1} \hl{#2}} }
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}}
\usepackage[mathscr]{euscript}
\usepackage{booktabs} % For \toprule, \midrule and \bottomrule
%\usepackage{siunitx} % Formats the units and values
%\usepackage{pgfplotstable} % Generates table from .csv
%\usepackage{relsize} % allows use of \mathlarger{} command
\setlength{\parindent}{0pt} % this stops indentation 1st line of para
\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex} % this adds space after each para
\newcommand{\Z}{\mathbb{Z}} % defines \Z as shorthand for command \mathbb{Z}
\newcommand{\R}{\mathbb{R}}
\newcommand{\N}{\mathbb{•}b{N}}
\newcommand{\half}{\tfrac{1}{2}}
\newcommand{\dbar}[1]{\Bar{\Bar{#1}}}
\newcommand{\kk}{{}_k}
\newcommand\dt {^{\delta t}}
\newcommand{\avg}{\textrm{Avg}\dt}
\newcommand{\prop}{\textrm{Prop}\dt}
\newcommand{\ldt}{\lim_{\delta t\to 0}}
\newcommand{\kinf}{_{k=0}^\infty}
\newcommand{\cadlag}{c\`adl\`ag}
\pagenumbering{arabic}
\newcommand{\rplus}{\R_+}
\newcommand{\highlight}[1]{%
  \colorbox{red!50}{$\displaystyle#1$}}
\usepackage{scalerel,stackengine}
\stackMath
\newcommand\reallywidehat[1]{%
\savestack{\tmpbox}{\stretchto{%
  \scaleto{%
    \scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\bigwedge\kern-.6pt}%
    {\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG WEDGE
  }{\textheight}% 
}{0.5ex}}%
\stackon[1pt]{#1}{\tmpbox}%
}
\begin{document} 
  • 3
    Well, if the behavior does not show with lipsum, chances are the the culprit is somewhere on page 7 on the undisclosed document. Just comment out all stuff on that page, and the error hopefully disappears. Then resurrect stuff one by one, and this will allow you to identify the culprit. Also try to insert some lipsum pages before and see if the troublemaker shifts, i..e if the page gets reset later on. –  Jun 22 '18 at 23:54
  • 3
    anything could reset the page counter \mainmatter or \pagenumbering or \setcounter or just \count0=0 it should be easy to make an example from the text you have, just change every letter to x and then check the problem still occurs, and adjust o be more like your original if necessary to trigger the problem. Otherwise there isn't really any answer to the question as posted. – David Carlisle Jun 23 '18 at 00:15
  • 1
    I get this all the time with exam package when I make multiple choice questions. My questions and answers are often multi line with included images, as such, the “size” of the question is larger than some threshold value that crashes the counters. If answer (a) and (b) are on page 8 and answer (c) and (d) overflow onto next page, the page counter resets. I don’t know how this could crash a page counter, but obviously counting code that has nothing to do with page numbers can. Interestingly enough, the question number and answer option counters don’t crash. – 2nd.Bridger Jun 23 '18 at 02:30
  • @DavidCarlisle Thanks, that could work, as it should not change paging, and the problem's appearance is very sensitive to paging. I can't just replace all letters by x as then a whole bunch of commands will become syntax errors like \xxx. or \begin{xxxxxxxx}. What would be needed would be a command to replace letters by x except when they are either part of a single word preceded immediately by a backslash or enclosed by braces {}. My regex knowledge is too rusty to be able to do that. I'd welcome a suggested command from anybody that speaks fluent regex. – Andrew Kirk Jun 23 '18 at 03:04
  • 1
    @AndrewKirkyou could spend a few minutes regex debugging but really i wouldn't bother, just get the example down to a couple of pages by deleting stuff, then delete a (say) 5 line paragraph by x\\x\\x\\x\\x and do that for each para checking the problem still occurs. It will take you less time than it takes to debug an automatic edit. – David Carlisle Jun 23 '18 at 08:18
  • 4
    I believe this might be the same problem as reported in bug with page numbers when using soul package – Circumscribe May 21 '20 at 16:06

0 Answers0