rpgtex/DND-5e-LaTeX-Template

Appendices in the table of contents

timvdalen opened this issue · 9 comments

Due to the current setup of dndtoc.sty, the following TOC contents:

\babel@toc {english}{}
\contentsline {chapter}{Introduction}{1}{chapter*.2}%
\contentsline {chapter}{\numberline {1}Test}{2}{chapter.1}%
\contentsline {chapter}{\numberline {A}Test}{4}{appendix.A}%

which renders as follows in book:

image

renders as follows in dndbook:

image

Renewing \tocchapterabbreviationname allows renaming Ch. to something like Chapter, but is there a way to differentiate between normal chapters and appendix chapters?
The titletoc documentation (https://mirror.lyrahosting.com/CTAN/macros/latex/contrib/titlesec/titlesec.pdf) seems to suggest so at the bottom of page 4 ("It defaults to \chaptername except in appendices where it is \appendixname. Use it instead
of \chaptername when defining a chapter.").

Please post a Minimum Working Example to generate the dndbook example.

Of course, apologies:

\documentclass[letterpaper,twocolumn,openany,nodeprecatedcode]{dndbook}
\usepackage[english]{babel}

\usepackage{hyperref}

\begin{document}
	\frontmatter%
	\tableofcontents

	\mainmatter%

	\chapter{Test}

	\appendix
	\chapter{Test}
\end{document}

Edit: Cut down the MWE a little further

Placing this as a note to myself (and others) on a direction to fix this.

https://tex.stackexchange.com/questions/57642/checking-if-is-appendix-or-chapter

I would like something that does not dig into internal book variables if possible. The problem is that our abbreviation in the chapter heading of the toc styling does not handle appendices. Ideally we typeset the chapter abbreviation if we are in mainmatter, appendix abbreviation if we are in the appendices, and nothing otherwise.

Thanks for the direction, I will see if I can hack something together for my document and report back if it might be useful generally.

Unrelated, but your proposed approach would solve another problem I have with the layout in the original issue.
The Introduction chapter is defined as:

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

because I don't want it to appear as Chapter 1 or Chapter 0.
However, my current approach doesn't affect \leftmark, so the page footer is still set to the previous actual chapter (Contents).
I'm currently using a specific \pagestyle with hardcoded text as a workaround, but promoting the Introduction to an actual chapter (in the frontmatter) showing up without the chapter abbreviation would be a much better way to handle this.

More notes:

Thanks for the direction, I will see if I can hack something together for my document and report back if it might be useful generally.

Unrelated, but your proposed approach would solve another problem I have with the layout in the original issue.
The Introduction chapter is defined as:

\chapter*{Introduction}
\addcontentsline{toc}{chapter}{Introduction}

because I don't want it to appear as Chapter 1 or Chapter 0.
However, my current approach doesn't affect \leftmark, so the page footer is still set to the previous actual chapter (Contents).
I'm currently using a specific \pagestyle with hardcoded text as a workaround, but promoting the Introduction to an actual chapter (in the frontmatter) showing up without the chapter abbreviation would be a much better way to handle this.

Okay, so I remembered at least one way to handle this in a (mostly) elegant manner.

\setcounter{secnumdepth}{-1}
\chapter{Introduction}
\setcounter{secnumdepth}{0}

In effect we tell LaTeX to only number Parts (-1). This means that "Chapter X" is not displayed on Introduction and the chapter counter is suspended. When the section numbering depth is restored to Chapter (0), the chapter number will start at 1 (or the next unused number).

Having spent some time looking into this, I believe I have a fix for at least the footer problem.
By defining \chaptermark (https://github.com/rpgtex/DND-5e-LaTeX-Template/blob/f0ef279/lib/dndheader.sty#L22) as \@chapapp\ \thechapter :~ instead of \chaptername\ \thechapter :~, we get a proper Appendix vs Chapter.
This also keeps frontmatter intact.
Backmatter is broken (displaying the last chapter before the backmatter), but that is also true without this change.

Testing for @mainmatter or \ifx\@chapapp\appendixname does not seem to work for me in the footers/toc.
@mainmatter is always true in the toc and footers (though it is correct in the actual document), while I cannot get the comparison between \@chappapp and \appendixname to work at all.

I will hold off on creating a PR until I can find a fix for the TOC problem as well, but maybe my results so far are helpful to someone else.

Just tested this against the latest dev and it seems like the above was already fixed in f0ef279, so that leaves the TOC stuff

Hi. Back on the appendix topic, the proposed solution did not work for me, so I edited it a bit.

First of all, I define a new command in lib/dndstrings.sty to store the TOC abbreviation for the appendix:

\newcommand\tocappendixabbreviationname{Apx.}

Then, in lib/dndtoc.sty, use it.

  \newcommand\tocchapapp{\tocchapterabbreviationname}
    \g@addto@macro\appendix{%
      \addtocontents{toc}{\protect\renewcommand{\protect\@chapapp}{\appendixname}}%
     % \addtocontents{toc}{\protect\renewcommand{\protect\tocchapapp}{\appendixname}}%
      \addtocontents{toc}{\protect\renewcommand{\protect\tocchapapp}{\tocappendixabbreviationname}}%

In my early tests it seems to work.

A working commit can be found in my fork.