1

Joint use of MakeUppercase, hyperref and \addcontentsline give me a small unexepceted (yet annoying) problem in the pdf table of contents.

In the following (hopefully) minimal working example, I would like the sections titles to being with an uppercase.

The outpus fine in the actual PDF file, but in the bookmarks of the same PDF there is a slight problem with casing. And LaTeX chokes while compiling.

\documentclass{article}
\usepackage{ifthen}
\usepackage{xspace}
\usepackage{hyperref}
\newboolean{hidesolution}
\setboolean{hidesolution}{true}
\makeatletter
\newcommand\secti@nstring{To be defined}
\newcommand{\problemsection}[1]{
  \ifthenelse{\boolean{hidesolution}}{
    \renewcommand{\secti@nstring}{Questions on #1\xspace}
  }{
    \renewcommand{\secti@nstring}{\MakeUppercase #1 (solutions)\xspace}
  }
  \section*{\secti@nstring}
  \addcontentsline{toc}{section}{\secti@nstring}
}
\makeatother
\newcommand\solution[1]{\ifthenelse{\boolean{hidesolution}}{}{\texttt{#1}}}
\setcounter{tocdepth}2
\begin{document}
\begin{filecontents}[overwrite]{greatproblems.tex}
  \problemsection{great typists}
  \begin{enumerate}
  \item
    Who jumped over the lazy dog?
    \\
    \solution{The quick brown fox.}
  \item
    If violets are blue, what are roses?
    \\
    \solution{Red.}
  \end{enumerate}
\end{filecontents}
\section{Solutions are invisible}
\input{greatproblems.tex}
\setboolean{hidesolution}{false}
\section{Solutions are now visible}
\input{greatproblems.tex}
\tableofcontents
\end{document}

Is there any way to fix this problem? (Other than hardwiring an ugly capital in the middle of a section title.)

2
  • 3
    I get no error and the bookmarks looks ok i.stack.imgur.com/brHn0.png. Is your tex system up-to-date? Nov 15, 2023 at 15:44
  • Thank you, @UlrikeFischer, I'll update my latex in a month when teaching is off for winter... As it gives me time to fix probs if upgrade messes up things. Nov 17, 2023 at 10:22

0

You must log in to answer this question.

Browse other questions tagged .