I would like to create a number of the form a/b where a denotes the current section (easy) and b the maximal section number in the document (this I am struggling with). Similarly for subsections and subsubsections. For the example below, it should thus be 2/3.1/1.3/4. How can I find out the maximal ((sub)sub)section number in the document?
Update: After David's comment, I used \label{} to refer to the last ((sub)sub)section. However, for subsections and subsubsections, \ref{} includes the section or subsection number as well. How can this be avoided?
\documentclass{article}
\usepackage{units}
\newcommand\sectionnum{\arabic{section}}
\newcommand\subsectionnum{\arabic{subsection}}
\newcommand\subsubsectionnum{\arabic{subsubsection}}
\begin{document}
\section{Section 1}
\section{Section 2}
\subsection{Subsection 2.1}\label{lastsubsec}
\subsubsection{Subsubsection 2.1.1}
\subsubsection{Subsubsection 2.1.2}
\subsubsection{Subsubsection 2.1.3}
Now we are in Section \nicefrac{\sectionnum}{\ref{lastsec}}.\nicefrac{\subsectionnum}{\ref{lastsubsec}}.\nicefrac{\subsubsectionnum}{\ref{lastsubsubsec}}
% should give 2/3.1/1.3/4
\subsubsection{Subsubsection 2.1.4}\label{lastsubsubsec}
\section{Section 3}\label{lastsec}
\end{document}
.auxfile, then pick them up on the next run. I'm pretty sure I've done that before in an answer here, I'll see if I can see the duplicate question (but anyone with code to hand should feel free to answer:-) – David Carlisle Mar 19 '14 at 09:50\AtEndDocument{\immediate\write\@auxout{\string\expandafter\gdef\noexpand\csname B@\the\c@subsection\string\endcsname{\the\c@paragraph}}}[with\makeatletter...\makeatother] to the header and obtain the additional line\expandafter\gdef \csname B@0\endcsname{0}in the.auxfile... – Marius Hofert Mar 19 '14 at 16:29\thesection/\ref{lastsec}and put \label{lastsec} after the last section – David Carlisle Mar 19 '14 at 16:47\ref{}includes the section number, and for subsubsections, it includes the section and subsection number. How can this be avoided? – Marius Hofert Mar 19 '14 at 18:28