[Tex/LaTex] Adding section to appendix causes a compile error

appendicesnumberingsectioning

Background

Include multiple appendixes in a book. (Using KOMA Script v2.)

Problem

I have isolated the problem and created a minimal example to demonstrate the issue:

The only difference (according to gVim's diff tool) between good.lyx and bad.lyx are the following lines:

\begin_layout Subsection
jasper.php
\end_layout

\begin_layout Standard
TODO
\end_layout

Loading good.lyx into LyX works as expected: a PDF can be created. Loading bad.lyx into LyX does not work as expected. The following error results:

Missing number, treated as zero.

\end{document}

A number should have been here; I inserted '0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

Questions

  • Why does typing one more subsection cause an error?
  • How can the error be resolved so that any number of sections and subsections can be added to the appendix?

Thank you!

Best Answer

What does this harmless subsection command? It starts a new page! And this page has a different page style. The first page has page style plain because it's the beginning of a chapter, but the next page has scrheadings style. There we may search the problem.

It is in your preamble:

\rehead{\textsc{\ChapterTitle \ChapterNumberIfNeededEven}}
\lohead{\textsc{\ChapterNumberIfNeededOdd \ChapterTitle}}
...
\def\ChapterNumberIfNeededEven{%
  \ifnum 0<\thechapter{} $ \star $ \chaptername{} \thechapter{} \fi
}
\def\ChapterNumberIfNeededOdd{%
  \ifnum 0<\thechapter{} \chaptername{} \thechapter{} $ \star $ \fi
}

Don't compare a number 0 with \thechapter - in your appendix \thechapter is "A" ! Instead, something like

 \ifnum\value{chapter}=0 ...

could work.

On a plain chapter starting page that error could not occur.

Related Question