# 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:

\subsubsectionwithlabel{Network Address Translation (NAT)}{sec:NAT}

-
Hehe, was just about to post this myself as I figured it out myself, but you were faster. You got a tip for handling of \section \subsection \subsubsection? Or shall I just define one for each? – David Everlöf Feb 27 '13 at 12:03
Define a "master" macro with three parameters (use the command as third parameter) and then define \section etc. as calls of that master macro. – krlmlr Feb 27 '13 at 12:05
Care to elaborate with an example? – David Everlöf Feb 27 '13 at 12:14
I have, and indeed it seems better, thats why I change that answer to the correct! :) But thanks anyway, you answer still got a "1 up". – David Everlöf Feb 27 '13 at 13:50