TransWikia.com

Capitalize Headings in TOC and capitalize headings (using KOMA) and not loosing references

TeX - LaTeX Asked by MaCo on April 2, 2021

I am struggling with the links/bookmarks together with capitalizing TOC and capital headings.

First I struggled with making my capitalized TOC, as well as capitalized headings up to subsections (yes I know it does not look nice, but Cooporate Design requires it).

I am using TeXnicCenter with LuaLaTeX. Additional due to the used documentclass koma-script, so I was searching for an alternative to the package ‘tocloft’

EDIT:
Tried to make my question clear:

I managed almost to get what I wanted with using usepackage{tocloft}:

documentclass[
a4paper,
10pt,
oneside,
%chapterprefix,
%appendixprefix,
numbers=noenddot,
toc=chapterentrywithdots,
toc=listof
]{scrbook}

usepackage{lipsum}
%usepackage{blindtext}
usepackage[]{appendix}         % to get the prefix Appendix infront of Appendix chapters



usepackage[
bookmarks,
bookmarksopen=true,
bookmarksnumbered=true,
pdfauthor={ME},
pdftitle={SCRBook},
colorlinks,
%linkcolor=color{blue},
%urlcolor=color{blue},
plainpages=false,
unicode=true
]{hyperref} 


setcounter{secnumdepth}{3}



%BEGIN - TOC consist only of Word "Appendix", and then on 1st page of appendix content of appendix
%https://tex.stackexchange.com/questions/585062/table-of-contents-with-appendix-short-and-a-new-toc-with-detailed-appendix/585195#585195
DeclareNewTOC[%
owner=jobname
]{atoc}

makeatletter
newcommand*{useappendixtoc}{%
    renewcommand*{ext@toc}{atoc}%
    scr@ifundefinedorrelax{hypersetup}{}{%
        hypersetup{bookmarkstype=atoc}%
    }%
}
makeatother

usepackage{xpatch}

xapptocmdappendix{%
    addchap{appendixname}
    listoftoc*{atoc}
    useappendixtoc
}{}{}

%END - TOC consist only of Word Appendix


%%ALTERNATIVE1
% BEGIN Capitalize sections in TOC and LOF.
usepackage{tocloft}
usepackage{etoolbox}
makeatletter
patchcmd{l@chapter}{#1}{uppercase{#1}}{}{}       % Capitalize chapters.
patchcmd{l@section}{#1}{uppercase{#1}}{}{}       % Capitalize sections.
patchcmd{l@subsection}{#1}{uppercase{#1}}{}{}    % Capitalize subsections
makeatother


%-----for headings in capital------
usepackage[explicit]{titlesec} 

deftab#1{parbox[t]{25mm}{#1}hfill}

titleformat{chapter}{largebfseries}{parbox[t]{13mm}{thechapter}}{0mm}{MakeUppercase{#1}}
titleformat{name=chapter,numberless}{largebfseries}{}{0mm}{MakeUppercase{#1}}

titleformat{section}{largebfseries}{parbox[t]{13mm}{thesection}}{0mm}{MakeUppercase{#1}}
titleformat{name=section,numberless}{largebfseries}{}{0mm}{MakeUppercase{#1}}

titleformat{subsection}{normalsizebfseries}{parbox[t]{13mm}{thesubsection}}{0mm}{MakeUppercase{#1}}
titleformat{name=subsection,numberless}{normalsizebfseries}{}{0mm}{#1}

titleformat{subsubsection}{normalsizebfseries}{parbox[t]{13mm}{thesubsubsection}}{0mm}{#1}
titleformat{name=subsubsection,numberless}{normalsizebfseries}{}{0mm}{#1}

titlespacing{chapter}{0pt}{12pt}{6pt}
titlespacing{section}{0pt}{12pt}{6pt}
titlespacing{subsection}{0pt}{6pt}{3pt}
titlespacing{subsubsection}{0pt}{6pt}{3pt}

setlength{headsep}{12pt}
% END Capitalize sections in TOC and LOF.


begin{document}
    begin{titlepage}
    huge{textbf{TITLE}}  
    bigskip
    Here text for titlepage
        
    end{titlepage} 
        
    
    addchap{Executive Summary}
    addsec{Executive subchapter1}
    lipsum[1]
    addsec{Executive subchapter2}
    lipsum[2]
    newpage
        
    renewcommand{contentsname}{Table of Content}  % WARNING: don't move to preamble  doesn't work there
    setcounter{tocdepth}{6}              % how deep is the table of contents listed
    setcounter{secnumdepth}{6}           % how deep are the sections numbered  
    tableofcontents
    listoffigures
    listoftables
    

    chapter{Chapter}
    label{chap}
    lipsum[1-5]
    section{Section1}
    lipsum[1-5]
    
    begin{tabular}{||c|c|c|c|}
        hline
        rule[-1ex]{0pt}{2.5ex} a & b & c & d 
        hline
        rule[-1ex]{0pt}{2.5ex} 1 & 2 & 3 & 4 
        hline
        rule[-1ex]{0pt}{2.5ex} 5 & 6 & 7 & 8 
        hline
        rule[-1ex]{0pt}{2.5ex} 9 & 10 & 11 & 12 
        

    end{tabular}
    

    
    
    
    section{Section2}
    lipsum[1-5]
    subsection{Subsection1}
    lipsum[1-5]
    subsection{Subsection2}
    lipsum[1-5]
    subsubsection{SubSubSection1}
    lipsum[1-5]
    
    chapter{Chapter2}
    lipsum[1-5]
    section{Section}
    lipsum[1-5]
    
    section{Section}
    lipsum[1-5]
    subsection{Subsection}
    lipsum[1-5]
    subsection{Subsection}
    lipsum[1-5]
    subsubsection{SubSubSection}
    lipsum[1-5]
    
    ref{chap}
    
    begin{appendices}
        appendix
        
        chapter{AppChapter1}
        lipsum[1-5]
        section{Section1}
        lipsum[1-5]
        
        section{Section2}
        lipsum[1-5]
        subsection{Subsection1}
        lipsum[1-5]
        subsection{Subsection2}
        lipsum[1-5]
        subsubsection{SubSubSection1}
        lipsum[1-5]
        
        chapter{AppChapter2}
        lipsum[1-5]
        section{Section}
        lipsum[1-5]
        
        section{Section}
        lipsum[1-5]
        subsection{Subsection}
        lipsum[1-5]
        subsection{Subsection}
        lipsum[1-5]
        subsubsection{SubSubSection}
        lipsum[1-5]
    end{appendices}

    
end{document} 

But as I am using KOMA scrbook this is not recommended, so I tried to make it work with DeclareTOCStyleEntry, but then I lost the hyperlink between TOC and the individual headings (sorry this version is not anymore available).
So I tried to the example from 1st answer (exchange the codepart ALTERNATIVE1 with ALTERNATIVE2):

%%ALTERNATIVE2
%%BEGIN - not loosing hyperref for capital headings %https://tex.stackexchange.com/questions/586977/capitalize-headings-in-toc-using-koma-declaretocstyleentry-and-not-loosing-re/586998#586998
%usepackage{xpatch}
xpatchcmd{chapterlineswithprefixformat}
{#3}
{MakeUppercase{#3}}
{}{PatchFailedI}

xpatchcmd{chapterformat}
{chapappifchapterprefix{nobreakspace}}
{MakeUppercase{chapappifchapterprefix{nobreakspace}}}
{}{PatchFailedII}


xpatchcmd{sectionlinesformat}
{#4}
{MakeUppercase{#4}}
{}{PatchFailedIII}

xpatchcmd{addtocentrydefault}
{#3}
{MakeUppercase{#3}}
{}{PatchFailedIV}


pdfstringdefDisableCommands{defMakeUppercase#1{#1}}

%END - not loosing hyperref for capital headings

This works quite well but I still have the following problem:
The chapter are not yet in the correct size nor capitalized and from subsubsections on the heading is not non-capitalized.
Another issue is that the TOC and the listof are not capitalized.

Maybe I just did not got your help right…?!??

One Answer

Unfortunately, there is no MWE in the question. Assuming you use MakeUppercase in an argument of addtocentrydefault and load package hyperref, you will get the error message

! Undefined control sequence. MakeUppercase ...ppercaseUnsupportedInPdfStrings

To avoid this error you can use texorpdfstring.

Example:

documentclass[
  a4paper,
  10pt,
  oneside,
  chapterprefix,
  appendixprefix,
  numbers=noenddot,
  toc=chapterentrywithdots
]{scrbook}
usepackage{blindtext}% only for dummy text

usepackage{xpatch}
xpatchcmd{chapterlineswithprefixformat}
  {#3}
  {MakeUppercase{#3}}
  {}{PatchFailedI}
xpatchcmd{chapterformat}
  {chapappifchapterprefix{nobreakspace}}
  {MakeUppercase{chapappifchapterprefix{nobreakspace}}}
  {}{PatchFailedII}

xpatchcmd{sectionlinesformat}
  {#4}
  {texorpdfstring{MakeUppercase{#4}}{#4}}
  {}{PatchFailedIII}

xpatchcmd{addtocentrydefault}
  {#3}
  {texorpdfstring{MakeUppercase{#3}}{#3}}
  {}{PatchFailedIV}

begin{document}
tableofcontents
blinddocument
blinddocument
end{document}

enter image description here

Or you could use

pdfstringdefDisableCommands{defMakeUppercase#1{#1}}

to disable MakeUppercase for the pdf-bookmarks. Example:

documentclass[
  a4paper,
  10pt,
  oneside,
  chapterprefix,
  appendixprefix,
  numbers=noenddot,
  toc=chapterentrywithdots
]{scrbook}
usepackage{blindtext}% only for dummy text

usepackage{xpatch}
xpatchcmd{chapterlineswithprefixformat}
  {#3}
  {MakeUppercase{#3}}
  {}{PatchFailedI}
xpatchcmd{chapterformat}
  {chapappifchapterprefix{nobreakspace}}
  {MakeUppercase{chapappifchapterprefix{nobreakspace}}}
  {}{PatchFailedII}

xpatchcmd{sectionlinesformat}
  {#4}
  {MakeUppercase{#4}}
  {}{PatchFailedIII}

xpatchcmd{addtocentrydefault}
  {#3}
  {MakeUppercase{#3}}
  {}{PatchFailedIV}

usepackage{hyperref}
pdfstringdefDisableCommands{defMakeUppercase#1{#1}}

begin{document}
tableofcontents
blinddocument
blinddocument
end{document}

The result is the same as above.

Answered by esdd on April 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP