you can suppress the automatically generated toc entry and replace it.
to suppress, add this command to your preamble:
\DeclareRobustCommand{\SkipTocEntry}[4]{}
if you are using hyperref, change the [4]
to [5]
-- this is the number of elements in the toc entry to be suppressed.
immediately before the line that generates the toc entry, insert the line
\addtocontents{toc}{\SkipTocEntry}
if applying it to a chapter, and you use \include
to insert your chapters, it must be in the same file as the \chapter
command; if you put it in the driver file, the timing will be off, and the chapter entry from the next chapter will be suppressed instead.
a replacement entry should be inserted immediately after the line that generated the toc entry, in order to ensure that the page number has been resolved correctly.
define a counter \newcounter{prevpage}
in the preamble. when setting up the replacement toc entry,
\setcounter{prevpage}{\value{page}}
\addtocounter{prevpage}{-1}
then use \addtocontents{toc}{xxx}
where xxx
is the line that was automatically generated (and suppressed) that you can copy from the .toc
file, except that you should replace the assigned page number by {\theprevpage}
. if you had to \protect
some commands in the text of the original heading, you should do the same in the replacement toc entry.
say this line appears in the toc (the example is from a test using amsbook
):
\contentsline {section}{\tocsection {}{5}{Section title}}{10}
the page number is {10}
. what you'd put in your file as a replacement is
\addtocontents{toc}{\protect\contentsline {section}{\protect\tocsection {}{5}{Section title}}{\theprevpage}}
observe that \contentsline
and \tocsection
do need to be \protect
ed.
(i took this example from a test using amsart.cls
, but the principle should be the same regardless of the document class. just copy what's in the .toc
file from your first run, and modify it appropriately.)
EDIT: the OP created an admirable macro, \transsection
to handle this. what follows is a self-contained example file demonstrating the use of his macro with the book
class.
\documentclass{book}
\usepackage{verbatim}
\DeclareRobustCommand{\SkipTocEntry}[4]{}
\newcounter{prevpage}
\newcommand{\transsection}[1]{%
\addtocontents{toc}{\SkipTocEntry}%
\section{#1}%
\setcounter{prevpage}{\value{page}}\addtocounter{prevpage}{-1}%
\addtocontents{toc}{%
\protect\contentsline {section}{%
\protect\numberline {\thesection}#1}{\theprevpage}}}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{First}
\section{First section}
some text
\clearpage
\transsection{Test section}
We want this section to have a page number one less than the
real one. This is from question 55645 in TeX.SX, where the
author is setting an Arabic page on the page before the
English translation page, and wants the TOC to show that
page number.
\vspace{1\baselineskip}
\verbatiminput{\jobname.tex}
\end{document}
Best Answer
You need to do at least three things to achieve the output you're after:
Make the page number reset with every use of
\section
. This can be achieved byThe above also sets the page number display to be
\thesection.\arabic{page}
by default.To correct the above default setting of the page numbering, use
Finally, you want to let the page numbering start from 1. To do this, you need to make sure that the page numbering is adjusted only when you call
\section
(otherwise it may be reset when calling\subsection
,\subsubsection
...). Here a patch viaetoolbox
of\@sect
inserts an appropriate page number stepping:Here is complete, minimal example that shows the output: