# Memoir sheetsequence counter does not increment when bidi is loaded

I would like to use \thesheetsequence in the trim area (sheet-number.tex) as described in the Memoir documentations but the counter does not increment (it always shows 1) and \thelastsheet is always 0. Any idea what may cause this?

[Update] I must also add that this happens in a big project with a lot of packages and small customized configurations. The packages loaded are available here: packages.tex. Unfortunately, ATM I cannot share the complete project or provide a minimal example.

[Update2] I have found that the problem is caused when bidi is loaded. Now the question is how to fix it.

[Update3] Example of code not working is added (also thanks to @daleif):

\documentclass[a4paper]{memoir}
\usepackage{etoolbox}
\usepackage{bidi}
\begin{document}

\def\do#1{\thesheetsequence\newpage}
\docsvlist{1,2,3,4,5,6,7,8,9}

\end{document}

• Welcome to TeX.SX! Can you show a small example of what you are attempting to? – egreg Aug 25 '15 at 10:13
• @egreg Thank you for your answer. An example of what I want to do will follow in the next comment. It works in a "simple" document, but not in my overly sophisticated project. I think I am facing this problem because of some package incompatibility or misconfiguration. Any idea where and how I can find more clues? – Shayanlinux Aug 26 '15 at 20:37
• code snippet on Gist \quarkmarks \renewcommand*{\tmarktl}{\registrationColour{% \begin{picture}(0,0) \setlength{\unitlength}{1bp}\thicklines \put(-36,0){\line(1,0){24}} \put(0,12){\line(0,1){24}} \put(3,27){\normalfont\ttfamily\fontsize{8bp}{10bp}\selectfont\ Sheet \thesheetsequence} \end{picture}}} \checkandfixthelayout – Shayanlinux Aug 26 '15 at 20:37
• @Shayanlinux erh, what are we suppose to do with that sniplet in the comment? – daleif Aug 27 '15 at 7:42
• As for your update, without code, we cannot help. Then you have to learn one of the most basic debugging concepts for your self. Copy the entire project to a new folder. Then start removing stuff, bit by bit. Compile each time. If the problem persists, then the bit you removed probably did not matter. At the end you end up with either knowing exactly what went wrong. Or a minimal example that you can post here. Until then, there is not much we can do. – daleif Aug 27 '15 at 7:45

Too big for a comment. As Egreg says you need to show us an example of this.

This MWE works just fine

\documentclass[a4paper]{memoir}
\usepackage{etoolbox}
\begin{document}

\def\do#1{\thesheetsequence\newpage}
\docsvlist{1,2,3,4,5,6,7,8,9}

\end{document}


I'm using etoolbox to give me a loop to produce several pages

bidi is a bit of a beast. In this case bidi happily overwrites \@outputpage without taking into account that others may have added to it.

The sheetsequence is implemented in memoir via

\g@addto@macro{\@outputpage}{\stepcounter{sheetsequence}}


that is, by adding to \@outputpage. That is now gone because of bidi

You can bring it back by adding

\makeatletter

after loading bidi.