I need to typset a book with very long section names. The long names should appear in the normal text and in the ToC but not in the header, so I can’t use the optional argument.
\sectionmark is my fried but only for the page after the \section started because the first marking command on a page wins the place in the header.
Is it possible to set the header of the current page even after a \section set a header already?
\documentclass{book}
\usepackage{lipsum}
\begin{document}
\chapter{Test}
\lipsum
\section{A Section}
\lipsum[3-5]
\section{A very long section title, which doesn't
fit in the header because it's extremly long}
\sectionmark{Short title}
\lipsum[1-14]
\end{document}
The example is very minimalistic. The template I must use uses fancyhdr to change the layout.
I found this answer but it works only for chaperts because they always happen to be on a right page and so \chaptermark gives the desired result on the next left page.
Follow up question to my answer
Is ist possible to make a (Perl or whatever running on Mac OS X) script that converts
\section{long text}
\sectionmark{short text}
to
\section[long text]{long text\sectionmark{short text}}
or alternatively to
\section{long text}[short text]
I can’t ensure that there are no line breaks in the long text or if there is a break between \section and \sectionmark.
I asked the follow up question again here on StackOverflow.