[Tex/LaTex] how to get the current chapter name, section name, subsection name, etc

cross-referencingmdframedsectioning

How can one get the current name of the following: Chapter, Section, Subsection(s), frame, label, mdframed?

Best Answer

With this solution you can still use the starred versions and optional arguments of \chapter et al.

\documentclass{book}
\let\Chaptermark\chaptermark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\let\Sectionmark\sectionmark
\def\sectionmark#1{\def\Sectionname{#1}\Sectionmark{#1}}
\let\Subsectionmark\subsectionmark
\def\subsectionmark#1{\def\Subsectionname{#1}\Subsectionmark{#1}}
\let\Subsubsectionmark\subsubsectionmark
\def\subsubsectionmark#1{\def\Subsubsectionname{#1}\Subsubsectionmark{#1}}

\begin{document}
\chapter{First chapter}\label{ch:first}
This is chapter~\ref{ch:first} with title ``\Chaptername''.
\section{First section}\label{sec:first}
This is section~\ref{sec:first} with title ``\Sectionname''.
\subsection{The first subsection}\label{subsec:first}
This is subsection~\ref{subsec:first} with title ``\Subsectionname''.
\subsubsection{Last subsubsection}\label{subsubsec:first}
This is subsubsection~\ref{subsubsec:first} with title ``\Subsubsectionname''.
\end{document}