# frontmatter command causing error when used with custom ToC

I've been playing with this pretty ToC, with the goal of simplifying it for my needs. I have successfully done that, but when I try to implement it into my bigger file, \frontmatter seems to cause an error, yet the code runs error-free without \frontmatter.

The error produced, is:

! Extra }, or forgotten \endgroup. \ttl@tocentry ... #5{#7}\strut \kern \z@ }\fi {#6} \ifcase #1\relax \ifttl@fr... l.1 \contentsline {chapter}{A chapter}{i}

There is no missing } in the code, so there is some deeper issue. I've been researching this error but don't understand how to fix it.

MWE:

\documentclass[11pt]{book}

\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

% % % pretty ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{26.7em}%
{\vrule width 2pt depth 3pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}

\titlecontents{chapter}
[0em]{\vspace*{0.3\baselineskip}}
{\parbox{14.8em}{%
\hfill\huge\rmfamily\bfseries\thecontentspage}%
\vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{}{\endleftbar}
% % %

\begin{document}

\tableofcontents
%\frontmatter   %untoggle to see error(s)
\chapter{A chapter}
\mainmatter
\chapter{Another chapter}
\chapter{Another chapter}

\end{document}


With frontmatter the chapter is unnumbered. The argument of titlecontents is empty and so you end with an lonely \endleftbar which hasn't a opening \leftbar:

 \documentclass[11pt]{book}

\usepackage{framed}
\usepackage[compact,pagestyles,clearempty]{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}

% % % pretty ToC modified from https://tex.stackexchange.com/questions/35825/pretty-table-of-contents
\patchcmd{\tableofcontents}{\contentsname}{\rmfamily\contentsname}{}{}

\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{26.7em}%
{\vrule width 2pt depth 3pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}

\titlecontents{chapter}
[0em]{\vspace*{0.3\baselineskip}}
{\parbox{14.8em}{%
\hfill\huge\rmfamily\bfseries\thecontentspage}%
\vspace*{-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{\parbox{14.8em}{% <----- new
\hfill\huge\rmfamily\bfseries\thecontentspage}% <---new
\vspace* {-2.4\baselineskip}\leftbar\textsc{\normalsize\chaptername~\thecontentslabel}\\\normalsize\rmfamily}
{\endleftbar}
% % %

\begin{document}

\tableofcontents
\frontmatter   %untoggle to see error(s)
\chapter{A chapter}
\mainmatter
\chapter{Another chapter}
\chapter{Another chapter}

\end{document}


• Ah, I see. I will want a lowercase roman numeral to the left of that bar for the frontmatter content. – AML May 9 '18 at 19:55
• Would you prefer I start a new question for the numbering issue? – AML May 9 '18 at 21:47
• Where is the problem? Copy the code from the numbered case and adapt it if needed. – Ulrike Fischer May 9 '18 at 21:49
• I must not be following, because I've played around with your code and still can't make it work forfrontmatter numbering. – AML May 9 '18 at 21:54
• I edited the answer and copied the code. – Ulrike Fischer May 9 '18 at 22:01