LyXWrong page numbers in index

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

Wrong page numbers in index

Post by H_Strandin »

rais wrote:
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.
Okay, thanks. I didn't know what \makeindex does.

So. I exported my files from LyX to PDFLaTeX to be able to check the .idx file. I now have a PDF of my dissertation with a correct index, but I'm not sure what happened.

First the compilation with TeXworks didn't put the bibliography or the index in the output document at all. I then noted that when all the bibliographic references were replaced with "?", the page numbers in the original index were exactly right. I then tried, in TeXworks, to run BibTeX and MakeIndex manually before I ran PDFLaTeX (because I basically have no idea what I'm doing). I did this a couple of time, I think, before suddenly the rendered document had the right page numbers in the index. Alchemy!

But I have a correct PDF now, and I wouldn't if you hadn't given me some feedback and directions, thanks a ton! If you can understand what happened in LyX (where the index was as if there were no bibliographic references, but those references were nevertheless in the rendered document) then I would be curious to hear it.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Wrong page numbers in index

Post by rais »

Well, I'm not a LyX user, but it sounds like it runs
  1. pdfLaTeX
    (probably more than once to resolve TOC/LOF/LOT)
  2. BibTeX
  3. makeindex
    (or vice versa)
  4. pdfLaTeX
    (again, probably more than once)
When BibTeX is run, it creates a .bbl file which is read by the next (and consecutive) pdfLaTeX run(s) to resolve the bibliography itself and the \cite commands.
When makeindex is run, it creates a .ind file which is read by the next (and consecutive) pdfLaTeX run(s) to resolve the index.
When pdfLaTeX is run (step d), all the \cite commands show more than just `?'. Your code doesn't provide the info, which style you're using but it does indicate an author-year style. So instead of `?' you may get `Knuth, Donald E. (1984)' which undoubtedly requires more space than just a `?'.
Depending on how much space was still available on that page (and how many more cites there are), this may well cause following text (including some \index commands) to be shifted to the next page. With a sufficient number of \cite commands, this shifting may happen more than once.
This pdfLaTeX run (step d) will also create the index (because makeindex already created the necessary .ind file), but it will have the wrong page numbers as described, because makeindex created the .ind file before the \cite commands were resolved.
If LyX cannot be configured that it runs makeindex (again) after pdfLaTeX after BibTeX (after pdfLaTeX), I suggest you contact the LyX community about that.

BTW: if memory serves, LyX puts all created files (.aux, .idx, ...) into a temporary folder.
What I said before was nonsense, though: the last entry in .idx file isn't necessarily the last entry in the index, because makeindex sorts what it reads from the .idx file.
But you could still verify---or falsify---say, an entry of the index that has a wrong page number with its corresponding entry in the .ind file: if that page number reads correct, you have proof that makeindex is run too early in the chain of commands.
You just need to find where LyX puts these files, first.:)

[edit]
Correction: the last entry in the .ind file corresponds to the last \index command in the text, so it should be the entry with the highest possible error in page number, no matter where it ends up in the index.
Must've confused myself, here :roll:
[/edit]

KR
Rainer
H_Strandin
Posts: 9
Joined: Sun Mar 19, 2017 11:40 am

Wrong page numbers in index

Post by H_Strandin »

Thanks, yes that sounds like a plausible explanation.
rais wrote:If LyX cannot be configured that it runs makeindex (again) after pdfLaTeX after BibTeX (after pdfLaTeX), I suggest you contact the LyX community about that.
I might write a report on this. I've used LyX for 10 years without any problems (other than occasionally with getting Swedish spellchecking to work), but this is the first time I include an index.
Post Reply