# Ease the handling of labels

I want to ease the handling of labels in my document, and I want to show the label for a section if define a "variable".

Currently I'm doing it like this

Setting the up the "variable":

\usepackage{etoolbox}
\newtoggle{DEBUG}
\toggletrue{DEBUG}
%\togglefalse{DEBUG}

Then I use it like this:

\label{sec:NAT}
\iftoggle{DEBUG}{
}{
}

Is there an better way to do this? As it is now I still have to remember to set the same label in both places. Is there any libraries for this maybe?

I assume the best would be if there was a library that would allow me to write

\subsection{Section nam}{sec:NAT}

and then according to some setting it would output it correctly and also set the label!

-
Welcome to TeX.sx! –  Peter Jansson Feb 27 '13 at 12:13
And remember that \label goes after \<sub>section. :) –  zeroth Feb 27 '13 at 13:40

The proper approach to this problem is to use a package written just for this purpose: showlabels.

\documentclass{article}

\usepackage{showlabels}

\begin{document}

\section{Introduction}\label{sec:intro}

Blah

\section{Start}\label{sec:start}

Blah

Blah

\subsection{Set}\label{subsec:set}

Blah

\subsection{Go}\label{subsec:go}

Blah

\end{document}

By just commenting out the \usepackage{showlabels} line, the labels won't be shown any more.

-
There is also a final option: "Finally, we have the options final and draft. The option final turns o all the functionality of this package. This is included so that if that option is given globally in the \documentclass declaration then this package does respect it. ..." –  krlmlr Feb 27 '13 at 13:04
@krlmlr I prefer to comment out the package for preparing the final version of the document, because it patches some commands and some small risk of introducing break points or whatsits remains. –  egreg Feb 27 '13 at 13:11

You could define a wrapper command

\newcommand{\subsubsectionwithlabel}[2]{
\iftoggle{DEBUG}{
\subsubsection{#1 [#2]\label{#2}}
}{
\subsubsection{#1\label{#2}}
}
}

and use that instead of \subsubsection: