## LaTeX forum ⇒ LyX ⇒ Wrong page numbers in index

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am

### Wrong page numbers in index

My thesis is going out for its first test print tomorrow, and I just discovered that I have the wrong page numbers in many of the index entries. I've googled this but found nothing relevant. Since it's a bit of an emergency, I'm taking my chances here!

The page numbers for the index entries are right in the first third or so of the text (which is ~215 pages). After that they start to lag behind. At first some entries still get the right page numbers, but the difference grows until at the end of the text they are all 3-4 pages behind. It's as if the index processor divides the text into pages differently from the actual page rendering. I have no idea how this works or how to try to fix it.

I'm using the "default" index processor and the AMS Book document class, if that's any help.

Ijon Tichy
Posts: 167
Joined: Mon Dec 24, 2018 10:12 am
Try one more run of the index processor MakeIndex and after this one more LaTeX run. If the page numbers in the index are still not in sync we need much more information—enough to reproduce the problem.

H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am
Thanks for the reply. I've tried all the processors included in LyX with the same result, page numbers lag behind a few pages toward the end.

I can't send you the thesis file, but I can tell you that the index log has no warnings, but the LaTeX log is full of overfull and underfull error messages. I'm using a bunch of wrap floats, and sometimes formulas are higher than what fits on an ordinary line, etc. I wonder if that might confuse the index processor.

H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am
This is my preamble. The document is divided into subdocuments that are included in a master file.

---------------------------------
LyX-GENERATED PREAMBLE
---------------------------------

%% Do not edit unless you really know what you are doing.
\documentclass[swedish,english]{amsbook}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{wrapfig}
\usepackage{textcomp}
\usepackage{mathrsfs}
\usepackage{amsthm}
\usepackage{amssymb}
\makeindex
\usepackage{graphicx}
\usepackage[authoryear]{natbib}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\usepackage{subscript}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\numberwithin{section}{chapter}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}
\newenvironment{lyxlist}[1]
{\begin{list}{}
{\settowidth{\labelwidth}{#1}
\setlength{\leftmargin}{\labelwidth}
\renewcommand{\makelabel}[1]{##1\hfil}}}
{\end{list}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\input{preamble}
\date{}

\usepackage{geometry}

\geometry{paperheight=242mm,paperwidth=165mm}
\geometry{left=22.5mm,right=22.5mm}
\geometry{top=22.5mm,bottom=22.5mm}

\makeatother

\usepackage{babel}

----------------------------------------------------
MY OWN PREAMBLE (A BIT OF A MONSTER)
----------------------------------------------------

%%% General stuff %%%

% Old
%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{mathptmx}

\usepackage{mathrsfs}
\usepackage{mathabx}

\allowdisplaybreaks

\usepackage[normalem]{ulem}

\usepackage{enumerate}

%%% Better colors %%%

%\definecolor{green}{RGB}{0, 180, 0}
%\definecolor{cyan}{RGB}{0, 180, 180}
%\definecolor{yellow}{RGB}{211,211,0}

%%% Include TiKZ and libraries %%%

\usepackage{tikz}

\usepackage{caption}

\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,automata}

\usetikzlibrary{shapes.geometric}

%%% Include plot stuff %%%

\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{pgfplotstable}
\pgfmathsetseed{7105} % set the random seed
\pgfplotstableset{ % Define the equations for x and y
create on use/x/.style={create col/expr={17+2*\pgfplotstablerow}},
create on use/y/.style={create col/expr={(5.2*\thisrow{x}+90)+80*rand}}
}
% create a new table with 30 rows and columns x and y:

%%% Define styles %%%

\tikzstyle{state}=[circle, thick, inner sep=0pt, minimum size=25, draw]

%%%%%% Define commands %%%%%%

%% Conceptual/causal and nomic necessity %%

\newcommand{\cnec}{\,\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle C$}; \end{tikzpicture}\,}

\newcommand{\cpos}{\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=0.5, diamond, draw] {$\scriptscriptstyle C$}; \end{tikzpicture}}

\newcommand{\nnec}{\,\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle N$}; \end{tikzpicture}\,}

\newcommand{\npos}{\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=0.5, diamond, draw] {$\scriptscriptstyle N$}; \end{tikzpicture}}

%% Semantics for diachronic causation %%%

\newcommand{\pcond}[3]{\begin{tikzpicture} \draw (0,0) node (box) [outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle #1$}; \draw (0,0) node [above right] {$\scriptscriptstyle #3$}; \draw (0,0) node [above left] {$\scriptscriptstyle #2$}; \draw [->] (box.east) -- (0.55,0); \end{tikzpicture}}

\newcommand{\pnec}{\,\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle P$}; \end{tikzpicture}\,}

\newcommand{\ppos}{\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=0.5, diamond, draw] {$\scriptscriptstyle P$}; \end{tikzpicture}}

\newcommand{\nneci}[1]{\!\begin{tikzpicture} \draw (0,0) node [outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle N$}; \draw (-.3,.1) node {$\scriptstyle #1$}; \end{tikzpicture}\,}

\newcommand{\diaeq}[1]{\,\begin{tikzpicture} \draw (0,0) node (circle) [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle #1$}; \draw (0,0) node (arrowend) [above right, minimum width=16] {}; \draw [<->] (circle.east) -- (arrowend.south east); \end{tikzpicture}\,}

\newcommand{\causes}[2]{\!\begin{tikzpicture} \draw (0,0) node (circle) [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle C$}; \draw (-.25,.1) node {$\scriptstyle #1$}; \draw (0,0) node (condition) [above right, minimum width=16] {$\scriptscriptstyle #2$}; \draw [->] (circle.east) -- (condition.south east); \end{tikzpicture}\,}

\newcommand{\indicates}[2]{\!\begin{tikzpicture} \draw (0,0) node (circle) [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle I$}; \draw (-.25,.1) node {$\scriptstyle #1$}; \draw (0,0) node (condition) [above right, minimum width=16] {$\scriptscriptstyle #2$}; \draw [->] (circle.east) -- (condition.south east); \end{tikzpicture}\,}

\newcommand{\causesbi}[2]{\!\begin{tikzpicture} \draw (0,0) node (circle) [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle C$}; \draw (-.37,.1) node {$\scriptstyle #1$}; \draw (0,0) node (condition) [above right, minimum width=16] {$\scriptscriptstyle #2$}; \draw [->] (circle.east) -- (condition.south east); \end{tikzpicture}\,}

\newcommand{\indicatesbi}[2]{\!\begin{tikzpicture} \draw (0,0) node (circle) [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle I$}; \draw (-.37,.1) node {$\scriptstyle #1$}; \draw (0,0) node (condition) [above right, minimum width=16] {$\scriptscriptstyle #2$}; \draw [->] (circle.east) -- (condition.south east); \end{tikzpicture}\,}

%% Temporal logic %%

\newcommand{\nnext}{\!\begin{tikzpicture} \draw (0,0) node [circle, outer sep=0, inner sep=1, minimum size=9, fill=black, draw] {$\scriptscriptstyle \color{white} F$}; \end{tikzpicture}\,}
\newcommand{\pnext}{\!\begin{tikzpicture} \draw (0,0) node [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle F$}; \end{tikzpicture}\,}

\newcommand{\nprev}{\!\begin{tikzpicture} \draw (0,0) node [circle, outer sep=0, inner sep=1, minimum size=9, fill=black, draw] {$\scriptscriptstyle \color{white} P$}; \end{tikzpicture}\,}
\newcommand{\pprev}{\!\begin{tikzpicture} \draw (0,0) node [circle, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle P$}; \end{tikzpicture}\,}

\newcommand{\nfut}[1]{\!\!\begin{tikzpicture} \draw (0,0) node [diamond, outer sep=0, inner sep=1, minimum size=9, fill=black, draw] {$\scriptscriptstyle \color{white} F$}; \draw (-.24,.17) node {$\scriptstyle #1$}; \end{tikzpicture}}
\newcommand{\pfut}[1]{\!\!\begin{tikzpicture} \draw (0,0) node [diamond, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle F$}; \draw (-.24,.17) node {$\scriptstyle #1$}; \end{tikzpicture}\,}

\newcommand{\npast}[1]{\!\!\begin{tikzpicture} \draw (0,0) node [diamond, outer sep=0, inner sep=1, minimum size=9, fill=black, draw] {$\scriptscriptstyle \color{white} P$}; \draw (-.24,.17) node {$\scriptstyle #1$}; \end{tikzpicture}\,}
\newcommand{\ppast}[1]{\!\!\begin{tikzpicture} \draw (0,0) node [diamond, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle P$}; \draw (-.24,.17) node {$\scriptstyle #1$}; \end{tikzpicture}\,}

\newcommand{\nint}{\begin{tikzpicture} \draw (0,0) node [ outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle T$}; \end{tikzpicture}\,}
\newcommand{\pint}{\begin{tikzpicture} \draw (0,0) node [diamond, outer sep=0, inner sep=1, minimum size=9, draw] {$\scriptscriptstyle T$}; \end{tikzpicture}\,}

%% Arrows

%% Other

\newcommand{\circled[1]}{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=1pt] (char) {\small#1};}}[/code]

Johannes_B
Site Moderator
Posts: 4109
Joined: Thu Nov 01, 2012 4:08 pm
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am
This is about an alphabetically ordered list of words that occur in the text, with page numbers. An English index, I guess.

H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am
This looks like a Deep Dark Mystery and unfortunately I don't have time to investigate it in depth. Unless someone is struck by some divine inspiration, the dissertation will ship with a broken index.

The one clue I have is that the error is incremental. The page numbers lag behind approximately one page per twenty pages, starting from page 75 or so. So, something is clearly broken in the processing. I'm considering adding a footnote with the algorithm for getting the approximate page number, since the error is almost linear.

Anyway, thanks for taking a look at the post!

rais
Posts: 256
Joined: Sun Nov 16, 2014 8:51 pm
Well, the index processor can't get confused, it only ouputs what it is told by way of the .idx file.
The only ways I can see to get a wrong page number in the index are
1. some weird changes in page numbering
2. some material gets inserted before the \index command in question, after the index processor got called
Have a look into your generated .idx file. It contains a bunch of lines with\indexentry{<entry>}{<page>}. Compare the last entry with the last entry of your index: should they agree (i.e., wrong in both places), I'd tend to the first item in my list. Should they not agree (i.e., correct page in .idx file but wrong page in index), I'd tend to the second item---and Ijon Tichy gave you the correct answer, already.

KR
Rainer

H_Strandin
Posts: 8
Joined: Sun Mar 19, 2017 11:40 am
Thanks for the input, it would be lovely to get this working.

I can't check the .idx file right now, but I'm looking at the preamble I pasted above. I'm totally guessing now, but it has "\makeindex" in the middle of the package imports. (LyX did that.) Does that mean that the TiKZ graphics on the pages hasn't been rendered when the index is created? That would fit the symptoms, maybe.

rais
Posts: 256
Joined: Sun Nov 16, 2014 8:51 pm
H_Strandin wrote:I'm totally guessing now, but it has "\makeindex" in the middle of the package imports.

I don't see a problem with that. \makeindex basically creates a file handle for the .idx file, opens it for writing, (re)defines \index so it will write into this .idx file, and lets itself to don't-do-anything' (such that a second call to \makeindex won't try to open the same file handle, again).
H_Strandin wrote:Does that mean that the TiKZ graphics on the pages hasn't been rendered when the index is created?

I don't know what you've put between two consecutive \index commands where the first shows the correct yet the second a wrong page number in the resulting index. Come to think of it, your code doesn't even show a single \index command.
Suffice to say there are possibilities for (La)TeX to shift material (here including an \index command) onto the next (or even later) page.
Just imagine you've got \printindex issued before an \index`: on the first LaTeX run, the .idx file is created (but doesn't contain anything yet for \printindex to show, because you haven't run makeindex yet).
Now you run makeindex, so a file .ind gets created. Now you run LaTeX again (to get s.th. from \printindex, at last). Depending on how big your index is, everything after it will be shifted now by its size.
Though I doubt that's your problem, there are other scenarios possible to that or a similar effect.

KR
Rainer