In the titlesec package, one may use the \ifthesection (or \ifthechapter,...) command to apply some customization commands only when a \section has been defined. However, it seems that using \sectionmark (for instance to define a short running title) breaks this feature. Here is a MWE:
\documentclass{book}
\usepackage[pagestyles,outermarks]{titlesec}
\usepackage{lipsum}
\newpagestyle{main}{
\headrule
\sethead[\normalsize \thepage][][\scshape \chaptertitlename~\thechapter. \chaptertitle]
{\ifthesection{\thesection.~\sectiontitle}{}}{}{\normalsize \thepage}
}
\begin{document}
\tableofcontents
\pagestyle{main}
\chapter{First Chapter}
\lipsum
\lipsum
\chapter{Second Chapter}
\section{First Section}
\lipsum
\lipsum
\section{Second Section with a very long title that I do not want to show in the running heads but which is fine for the table of contents}
\sectionmark{Second Section}
\lipsum
\end{document}
In this example, the odd-side headers for chapter 1 (a chapter with no sections) only shows the page number, as expected (in particular the \ifthesection command prevents the dot from showing up):

In chapter 2, we have a first section for which everything works fine:

But things get more complicated when it comes to the second section, which has a very long name. Let us imagine that we want the full name in the table of contents, and a short running head in the headers. The command \sectionmark{Second Section} normally works, but it does not when \ifthesection is used in the headers style definition. In the present form, we get:

I can think of three possibilities to solve this problem:
- One solution would be to remove the
\ifthesectioncommand in the headers style definition, but then a dot would appear in the headers for chapters with no sections. Then another way to test if this dot (or any other character) should be printed would be needed. - Using the optional argument for the
\sectioncommand:\section[Second Section]{Second Section with a very long title that I do not want to show in the running heads but which is fine for the table of contents}. Then a hack would be needed to modify the table of contents so that the full name appears. - Playing around with marks to replace the
\sectionmark{Second Section}with an appropriate command which does not break the\ifthesectioncommand.
It seems to me that it would be preferable to choose the third solution, the other two looking more like work-arounds. However, I do not know much about the marks system. Does anybody know how to do this?
