I want to prepend some text to chapter titles on the TOC according to certain conditions. For example (this doesn't work):
\documentclass[letterpaper,openany,oneside]{book}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tocloft}
% If the chapter is an appendix, print "Apéndice", else "Capítulo".
\makeatletter
\renewcommand\cftchappresnum{
\ifx\@chapapp\appendixname
Apéndice\
\else
Capítulo\
\fi
}
\makeatother
\renewcommand\cftchapaftersnumb{\newline}
\renewcommand\cftchapleader{\cftdotfill{4}}
\renewcommand\cftchappagefont{\normalfont}
\setlength{\cftchapnumwidth}{0em}
\begin{document}
\tableofcontents
\mainmatter
\chapter{First chapter}
\section{First section}
\chapter{Another chapter}
\section{this is yet another section}
\appendix
\chapter{First Appendix}
\end{document}
I know this is a duplicate, but I want to know if something like this is possible because I have to test for a number of conditions. Namely:
- Is this the first chapter of the TOC?
- Is this title equal to "foo"
- Etc.

memoirinstead, then the example would be defunct. There it is just\renewcommand\cftchaptername{\chaptername~}\renewcommand\cftappendixname{\appendixname~}. Don't know why this has not been added totocloft. – daleif Feb 18 '15 at 12:29\@chapappwould only work if it changed during the setting of the ToC, which it doesn't. Of course, one could do that, but there are other ways of doing this - by writing to the ToC to change the definition of\@chapappat the appropriate moment. – Werner Feb 21 '15 at 00:32