Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appendices in the table of contents #305

Open
timvdalen opened this issue Jan 24, 2021 · 9 comments
Open

Appendices in the table of contents #305

timvdalen opened this issue Jan 24, 2021 · 9 comments
Labels

Comments

@timvdalen
Copy link

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.").

@BrianCriswell
Copy link
Member

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

@timvdalen
Copy link
Author

timvdalen commented Jan 24, 2021

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

@BrianCriswell
Copy link
Member

BrianCriswell commented Jan 25, 2021

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.

@timvdalen
Copy link
Author

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.

@BrianCriswell
Copy link
Member

BrianCriswell commented Jan 25, 2021

More notes:

@BrianCriswell
Copy link
Member

BrianCriswell commented Jan 25, 2021

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).

@BrianCriswell BrianCriswell changed the title Appendices in the table of contents Appendices in the table of contents and footers. Jan 25, 2021
@timvdalen
Copy link
Author

timvdalen commented Feb 14, 2021

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.

@timvdalen
Copy link
Author

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

@timvdalen timvdalen changed the title Appendices in the table of contents and footers. Appendices in the table of contents Feb 14, 2021
timvdalen added a commit to timvdalen/DND-5e-LaTeX-Template that referenced this issue Feb 14, 2021
timvdalen added a commit to timvdalen/DND-5e-LaTeX-Template that referenced this issue Feb 14, 2021
@wishmerhill
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants