[Tex/LaTex] cleveref and titlesec, \section issues.

appendicescleverefsectioningtitlesec

I have some problems with cleveref and titlesec, providing a minimal working example below:

\documentclass{report}
\usepackage{titlesec} %% <-- the issue as far as i know, but i need the package
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\chapter{ninjas are okay}
some text \cref{app:ninja_bkg} bla bla and \cref{app:ninja_fail}
\appendix
\chapter{ninja background}
\label{app:ninja_bkg}
ninjas originated from ???
\section{ninja fail}
\label{app:ninja_fail}
usually ninjas dont fail, but sometimes they do
\end{document}

where the line in the middle produces:

some text appendix A bla bla and section A.1

But I want:

some text appendix A bla bla and appendix A.1

If I remove the titlesec package everything works fine, but sadly I need it. Guessing titlesec redefines \section, but I'm not enough of a latex-hacker to fix it =/

Best Answer

You can use (as described in cleveref's documentation) \crefname, \Crefname, and the optional argument for the \label command to supply a new "type" for the sections in the appendices, ; a little example:

\documentclass{report}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{cleveref}

\crefname{secinapp}{appendix}{appendices}
\Crefname{secinapp}{Appendix}{Appendices}

\begin{document}

\chapter{Test chapter}\label{testchap}

\section{test section}\label{testsec}

A reference to a regular section: \cref{testsec}, and a reference to a section in appendix: \cref{testsecapp}

\appendix
\chapter{Test appendix}\label{testapp}

\section{Test section in app}\label[secinapp]{testsecapp}

\end{document}

The cleveref documentation gives a hint about using the aliascnt package to avoid having to use the optional argument for the new type (I haven't tested this approach, though).