Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a macro that contains the title for the current section, however when using the titlesec package, it no longer works for \section and \subsection. I know titlesec redefines the functions I'm using, but have not been able to figure out a workaround.

MWE:

\documentclass{article}

\usepackage{etoolbox}

\makeatletter
\pretocmd{\@sect}{\gdef\currtitle{#7}}{}{}
\pretocmd{\@ssect}{\gdef\currtitle{#5}}{}{}
\pretocmd{\@part}{\gdef\currtitle{#1}}{}{}
\pretocmd{\@spart}{\gdef\currtitle{#1}}{}{}
\makeatother

\usepackage{titlesec}

\begin{document}
\tableofcontents

\part*{First Starred part}
\currtitle

\part{First Un-starred part}
\currtitle

\section*{First Starred Section}
\currtitle

\section{Second Un-starred Section}
\currtitle

\subsection*{First Starred Subsection}
\currtitle

\subsection{Second Un-starred Subsection}
\currtitle

\end{document}
share|improve this question
    
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. –  Torbjørn T. Nov 21 '11 at 21:54

1 Answer 1

up vote 2 down vote accepted

For \section and lower level titles you can do

\apptocmd{\ttl@straight@i}{\global\let\currtitle\ttl@savetitle}{}{}

However, if you're not going to hide titles in groups, the simple

\makeatletter
\newcommand{\currtitle}{\ttl@savetitle}
\makeatother

should suffice.

For \part your code still works and I believe also the similar one for \chapter.

share|improve this answer
    
The first approach was exactly what I was looking for. Thanks! –  lyineyes Nov 21 '11 at 22:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.