Most of the solution was that I ran the latex command too few times -- 
two instead of three (or maybe more). If someone writes the list with 
evidence that a LyX-internal compile acts differently than a sequence 
of equivalent commands, ask him to run latex a couple more times at 
the end. It doesn't take much time, and it just might work.

More comments within the email...

On Saturday 25 June 2011 15:47:37 Steve Litt wrote:
> On Saturday 25 June 2011 08:46:33 you wrote:
> > Am 24.06.2011 21:04, schrieb Steve Litt:
> > > The following shellscript compiles my PDF:
> > > 
> > > =============================
> > > #!/bin/bash
> > > 
> > > rm -f junk.*
> > > cp -p larry.lyx junk.lyx
> > > lyx --export latex junk.lyx
> > > latex junk.tex
> > > makeindex -c -q junk.idx
> > > latex junk.tex
> > > dvips  junk.dvi
> > > ps2pdf13 junk.ps
> > > acroread junk.pdf
> > > =============================
> > 
> > Why so complicated and not using LyX to export directly to PDF
> > using e.g. pdflatex or ps2pdf?
> > 
> > Besides this, depending on your file, you will need up to 2 latex
> > runs, not just 2 as in your script. And I recommend not to run
> > latex + dvips + ps2pdf but just directly pdflatex.

Uwe -- I didn't know what you meant by this, and not knowing cost me a 
day as I found out for myself. I'm pretty sure you meant two latex 
runs AFTER the call to makeindex. That was the piece I was missing.

The situation was enormously complicated by so many factors that it 
almost looked like an intermittent. What finally put me in the right 
direction was that sometimes internal compiles would work just fine 
until I externally compiled and then they'd break. Or sometimes 
externals would compile right until a substantial change was made, and 
then they'd compile wrong even if that change was backed out.

Complicating all of this was the fact that it depended on where the 
text happened to page break.

I had two symptoms, which I've now seen enough to be able to describe:

1) The page numbers reported by Acrobat Reader did not match the page 
numbers on the pages. In fact, often times after the first or second 
page of the table of contents, Acrobat Reader would report a TOC page 
as page 1, as if the call to \mainmatter had been right in the middle 
of the table of contents.

2) The index was not included in the table of contents.

Both symptoms seemed to appear only with my script, and not with in-
LyX compiles. When script-compiled, both symptoms seemed intermittent, 
and seemed to depend on where the text naturally page-broke. No 
combination of \vfill and \clearpage or \pagebreak or \newpage could 
simulate the corrective action of the page happening to break just 
right.

THE SOLUTION:

Component 1: 3 calls to latex:

I finally called latex, then makeindex, then latex twice. Doing this 
seemed to eliminate most of the perceived intermittence and tended to 
make my script compile to the same result as lyx-internal compiles.

Component 2: Put \pagebreak right before the TOC, and \mainmatter 
right after.

This made TOC pagination correct.

Component 3: LyX clearpage, then \phantomsection, then the LyX index

This made the index show up. The \phantompage made the TOC entry go to 
the beginning of the index instead of the beginning of the section 
before it.

LESSONS LEARNED:

When anyone asks why a compilation script works differently than the 
LyX internal compile, or when they complain of Acroread's page 
numbering not matching the page numbers in the book, immediately 
suggest they add two or three calls to latex immediately after their 
last one. Also, they must put calls to latex between anything that 
gathers data for tables or indexes.

Early use of extra calls to latex can save over a day of 
troubleshooting. As a practical matter, once everything is said and 
done they can probably back out many of the extra calls to latex. I 
needed only three in the finished script.

Thanks

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt

Reply via email to