Sign up ×
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":


Then I use it like this:

    \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
Welcome to! – 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.















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

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


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.