# Set Custom Text in Place of Chapter Prefix for a Specific Chapter

I have a situation where the Introductory Chapter and another chapter of a book are un-numbered. I know how to ensure that the entries for these chapters appear in the Table of Contents, as you'll see from the code posted below.

I have designed the Chapter Heading such that it shows Chapter № and The Name of The Chapter, as below:

A screenshot of the un-numbered Introductory Chapter is as shown below:

However, I would like to have a situation where, for the Introductory Chapter, I have "Introduction" in Place of "Chapter №", and "This is where it all Begins" for the "Chapter Name", the way this book was designed, as per screenshots below:

See the corresponding Table of Contents, with Introduction replacing the Chapter prefix, and Custom Text used for the Chapter Name:

Here is my Code:

\documentclass[english, 12pt, twoside, a5paper]{scrbook}

\usepackage{scrlayer-scrpage}
\automark[chapter]{chapter}
\cfoot{\thepage}
\ifoot{}
\ofoot{}

\usepackage{blindtext}

% ---- TOC customization to change styling of frontmatter chapter

\makeatletter
\newcommand\matter@switch{}
\protect\renewcommand\protect\matter@switch{\normalfont\itshape}%
}%
}
\protect\renewcommand\protect\matter@switch{}%
}%
}

\setkomafont{disposition}{\normalfont}

\begin{document}

\frontmatter

\pagestyle{empty}

% Dedication

\vspace*{10cm}
\begin{center}
{\textit{To all the lovely folks on tex.stackexchange.com}}
\end{center}

\cleardoublepage

\pagenumbering{roman}

\rmfamily
\normalfont

\tableofcontents

\blindtext

\blindtext

\mainmatter

% Chapter Style

\KOMAoption{chapterprefix}{true}
\renewcommand\raggedchapter{\raggedleft}

\setkomafont{chapterprefix}{\normalfont\normalsize\scshape}

\renewcommand*{\chapterformat}{%
\enskip \chapappifchapterprefix{\nobreakspace}\thechapter\autodot%
}

\renewcommand\chapterlineswithprefixformat[3]{%
\MakeUppercase{#2}\par%
#3\par\bigskip
\rule{\textwidth}{.5pt}}

\RedeclareSectionCommand[beforeskip=30pt, afterskip=1.5\baselineskip]{chapter}

\addchap[Introduction]{This is where it all Begins}
\label{sec:chapter0}

\Blindtext

\chapter{What Is the Whole Point?}
\label{sec:chapter1}

\Blindtext

\chapter{The Point of It All}
\label{sec:chapter2}

\Blindtext

\label{sec:chapter3}

\blindenumerate
\blinditemize
\blinddescription

\clearpage

\backmatter

\end{document}


I have checked the KOMA-Script docs and searched the web for solutions to this but I could't find anything. The closest I've found to arriving at the solution has been to do the following (line 90 in the code above), as documented in the KOMA-Script docs.

\addchap[Introduction]{This is where it all Begins}


Thank You.

You could define a new key for the optional argument of the sectioning commands and redefine \chapterlineswithprefixformat and patch \addchaptertocentry:

\documentclass[english, 12pt, twoside, a5paper,
headings=optiontoheadandtoc,% <- added (activates advanced functionality of the optional argument of the sectioning commands)
]{scrbook}
\usepackage{babel}
\usepackage{blindtext}

\usepackage{scrlayer-scrpage}
\automark[chapter]{chapter}
\clearpairofpagestyles
\cfoot*{\pagemark}

\setkomafont{disposition}{\normalfont}
\setkomafont{chapterprefix}{\normalfont\normalsize\scshape}

\DeclareTOCStyleEntry[
dynnumwidth,
numsep=1.5em,
beforeskip=.5ex plus .5pt
]{chapter}{chapter}

\usepackage{xpatch}
\makeatletter
\newcommand\matter@switch{}
\xapptocmd\frontmatter
{%
}
{}{\frontmatterPatchFailed}
\xapptocmd\mainmatter
{%
\KOMAoption{chapterprefix}{true}%
\renewcommand\raggedchapter{\raggedleft}%
\RedeclareSectionCommand[beforeskip=30pt, afterskip=1.5\baselineskip]{chapter}%
}
{}{\mainmatterPatchFailed}

% define a new key for the optional argument of the sectioning commands
\providecommand*\@specialprefix{}
\FamilyStringKey[.section]{KOMAarg}{specialprefix}{\@specialprefix}

\renewcommand\chapterlineswithprefixformat[3]{%
\ifstr{#1}{chapter}
{%
\ifstr{\@specialprefix}{}
{\MakeUppercase{#2}}
{\MakeUppercase{%
{\usekomafont{chapterprefix}{%
\@specialprefix
\setlength{\@tempskipa}{\scr@chapter@innerskip}%
}}%
}}%
#3\par\bigskip
\rule{\textwidth}{.5pt}%
}{%
#2#3% original defininition for other levels with style=chapter
}%
\gdef\@specialprefix{}% reset the key
}
{%
\ifstr{\@specialprefix}{}
{%
\ifstr{#1}{}
{\chaptername
\texorpdfstring
{~#1}%
}
{#2}%
}%
}
}
\makeatother

\usepackage[numbered]{bookmark}
\hypersetup{hypertexnames=false}

\begin{document}

\thispagestyle{empty}
\vspace*{10cm}
\begin{center}
\textit{To all the lovely folks on tex.stackexchange.com}
\end{center}

\frontmatter
\tableofcontents
\blindtext
\blindtext

\mainmatter
\addchap[specialprefix=Introduction]{This is where it all Begins}
\label{sec:chapter0}
\Blindtext
\chapter{What Is the Whole Point?}
\label{sec:chapter1}
\Blindtext
\chapter{The Point of It All}
\label{sec:chapter2}
\Blindtext

• Thanks @esdd for the awesome solution! I noticed that the pdf bookmarks generated by the hyperref package are in the form Chapter [1ex][r] № ..., which is rather awkward. This is caused by the code {\chaptername\protect\quad\protect\makebox[1ex][r]{#1}\protect\hfill}. Removing the \makebox[1ex][r] solved the problem! – engineervix Apr 16 '18 at 2:39
• You are using package bookmark with option numbered? See my updated answer. – esdd Apr 16 '18 at 7:12
• Thanks once again @esdd, I was using the hyperref package, and this code snippet illustrates how I used it. Even after replacing it with \usepackage[numbered]{bookmark} and \hypersetup{hypertexnames=false}, the resulting bookmarks are still the same! – engineervix Apr 16 '18 at 10:06
• I have changed the patch of \addchaptertocentry too. Note the usage of\texorpdfstring ;-) – esdd Apr 16 '18 at 11:53