# Using Titlesec, titletoc, and titleps together affects the command \tableofcontents

Writing a book of probability in arabic, I want to use the titleps package for different beautiful headpages, in my files where I use titletoc for partial table of contents. All was good until I used the package titleps together with titlesec and titletoc. When I put the command \tableofcontents, the compilation does not end, but appears to go into an infinite loop... I have tried to use titlesec and titletoc, and obtain the contents with \tableofcontents, and all worked well, but not when using all three packages. Why does this happen? How can I write the contents and the partial contents at the same time, and use at the same time titleps?

Here is a WME, used with Texmaker on Windows 8.1, where I replaced the arabic names by latin names, to watch the effect of compilation. Don't be concerned about right-to-left text, because of the main language which is arabic here, a right-to-left language...

\documentclass[14pt,a4paper]{extbook}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{titleps}

\setlength{\columnseprule}{0.1pt}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\gappto\captionsarabic{\renewcommand{\chaptername}{Chaptername}}
\gappto\captionsarabic{\renewcommand{\contentsname}{Contents}}

\begin{document}

\titlecontents{lsection}
[2.3em]{\small}{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}
\titlecontents{lsubsection}
[4.6em]{\small}{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}

\newpagestyle{Mystyle}{
Titlebook]% even left
[]% even centre
[\sectiontitle \hspace*{5pt} .\thesection]% even right
{}% odd left
{}% odd centre
{\chaptertitle
\hspace*{14pt}
\thepage}% odd right
}

\pagestyle{Mystyle}

%  \tableofcontents

\chapter{Chapter 1}
\startcontents[chapters]
{\large\bf Minicontents}
\vspace*{5pt}
\hrule \vspace*{-10pt}
\begin{multicols}{2}
\printcontents[chapters]{l}{1}{\setcounter{tocdepth}{1}}
\end{multicols}
\vspace*{-5pt} \hrule

\section{Section 1}
\section{Section 2}
\newpage
\section{Section 3}
\section{Section 4}

\end{document}


The compilation gives this pdf file, and when I uncomment % \tableofcontents, the compilation never stops. I just want to put the command \tableofcontents at the beginning of the file !

I've tried to go down a level in the contents, by transforming chapter in section, and section in subsection, and now all is good ! There's no problem of compilation, it gives the contents, partial contents and uses the titleps package... But I need of course to go up by a level, because there is chapters in my book !...This fact may, I think, give some ideas for programmers of Latex.. I give the following MWE

\documentclass[14pt,a4paper]{extbook}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{titleps}

\setlength{\columnseprule}{0.1pt}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}

\gappto\captionsarabic{\renewcommand{\contentsname}{Contents}}

\begin{document}

\titlecontents{lsection}
[2.3em]{\small}{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}
\titlecontents{lsubsection}
[4.6em]{\small}{\contentslabel{2.3em}}
{\hspace*{-2.3em}}
{}

\newpagestyle{Mystyle}{
Titlebook]% even left
[]% even centre
[\sectiontitle \hspace*{5pt} .\thesection]% even right
{}% odd left
{}% odd centre
{\sectiontitle
\hspace*{14pt}
\thepage}% odd right
}

\pagestyle{Mystyle}

\tableofcontents

\section{section 1}
\startcontents[sections]
{\large\bf Minicontents}
\vspace*{5pt}
\hrule \vspace*{-10pt}
\begin{multicols}{2}
\printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}
\end{multicols}
\vspace*{-5pt} \hrule

\subsection{subsection 1}
\subsection{subsection 2}
\newpage
\subsection{subsection 3}
\subsection{subsection 4}

\end{document}


which gives the following output. I want the same output; but with "chapter" instead of "section"

• There is an error in LTR mode, which stems from the fact that you haven't loaded the packages properly. From the first page of the titleps manual: It [titleps] can be used without titlesec, but you will get most of it when used together. To load it as a separate package, use the customary \usepackage{titleps}, but with titlesec you have to load it with \usepackage[pagestyles]{titlesec}. I still get the infinite loop when I use polyglossia, but with this fix the output is correct with left-to-right languages. – Paul Gessler Aug 19 '14 at 14:12
• At all; even if the command is shorted like \usepackage[pagestyles]{titlesec}, what I knowed, the compilation not end. I have tried in LTR mode, by putting the main language english... with the commands \setmainlanguage{english} \setotherlanguage[numerals=maghrib]{arabic}... it have the same behaviour... so it loops infinitely with \tableofcontents... – Faouzi Bellalouna Aug 19 '14 at 15:35
• Other thing. On a try, I saw that if the toc file contains a "chapter" entry, you can't change it, even if you change the \chapter entry by \section.. you must delete the .toc file and produce another by compilation.. This is unusual in Latex.. I never saw this ! – Faouzi Bellalouna Aug 19 '14 at 22:20