0

I have been developing my own custom dark theme for TeXworks that I am currently using but just recently noticed a somewhat bug with the TOC. The TOC entries for the chapter are correctly being printed in white text but the sections/subsections/etc are not. This is how the MWE is currently outputting the TOC:

enter image description here

I have tried adding hyperref with the options suggested by Werner (namely: \usepackage[linktoc=all]{hyperref}) but this did not change the colour of the page numbers. The answer by Mico to change the color of the TOC using \begingroup, \endgroup also did not work - the page numbers for sections/subsections/etc stayed black.

What am I missing that is causing this? I am not sure why the chapter numbers are displaying correctly yet the TOC entries beneath chapter are not changing to be printed in white when I have set the \color to white as global \AtBeginDocument.

MWE:

\documentclass[oneside]{book}

\usepackage{lipsum} \usepackage{xcolor} \usepackage{etoolbox}

\AtBeginDocument{\pagecolor{black}\color{white}}

\begin{document}

\tableofcontents

\chapter{First chapter} \lipsum[1-2] \section{Foo section} \lipsum[1] \subsection{Bar subsection} \lipsum[1] \chapter{Second chapter} \lipsum[1-2] \section{Foo section} \lipsum[1] \subsection{Bar subsection} \lipsum[1] \end{document}

JamesT
  • 3,169

1 Answers1

1

enter image description here

use

 \pagecolor{black}\color{white}

not

\AtBeginDocument{\pagecolor{black}\color{white}}

so that the default document color is white.

David Carlisle
  • 757,742
  • That is embarrassing on my part! Any idea as to why \AtBeginDocument changed it strictly only for those page numbers or is it just one of the TeX quirks? Thanks for the quick response, worked in my main doc and I will update my answer in the first link. – JamesT Oct 01 '22 at 23:20
  • 1
    latex sets the document default color (which is set when normalising settings in page heads, floats etc to the color at \begin{document} but \AtBeginDocument is too late so you set white but the document default was black. I didn't check why only some levels are enforcing the default color – David Carlisle Oct 01 '22 at 23:25
  • Now I know to be a little wary of \AtBeginDocument and look there for issues, thanks for the advice and explanation. I have updated two previous answers that contained that error so hopefully they are useful to others in the future. – JamesT Oct 01 '22 at 23:27