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 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}{
    \subsubsection{Network Address Translation (NAT) [sec:NAT]}
}{
    \subsubsection{Network Address Translation (NAT)}
}

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!

share|improve this question
1  
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

2 Answers 2

up vote 9 down vote accepted

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

\subsection{Ready}\label{subsec:ready}

Blah

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

Blah

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

Blah

\end{document}

enter image description here

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

share|improve this answer
    
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}
share|improve this answer
    
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
1  
\newcommand{\withlabel}[3]{ ... #3{#1 [#2]} ... #3{#1} ...} and then \newcommand{\subsubsectionwithlabel}[2]{\withlabel{#1}{#2}{\subsubsection}}. –  krlmlr Feb 27 '13 at 12:19
1  
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

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.