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.

According to Guide to LaTeX, 4th edition, when creating a \label{name},

The keyword name may be any combination of letters, numbers, or symbols.

Is the name of a label case-sensitive? Can the name contain spaces?

I'm asking because when using Vim's snipmate TeX snippet, if I type sec and hit tab, I automatically get:

\section{section name}
\label{sec:section name}

Then when I enter the section name in the \section, Vim automatically puts the same text after the sec: portion of the \label. Since my sections are often multiple, capitalized words, the label name ends up containing spaces and are capitalized. For instance, I might get:

\section{Planned Testing}
\label{sec:Planned Testing}

Prior to allowing Snipmate in Vim automatically enter the label name based on the section name, I would have manually typed:

\section{Planned Testing}
\label{sec:planned_testing}

Spaces not allowed

Syntastic in Vim shows an error if a label name contains spaces.

share|improve this question
    
As far as i know, they are case-sensitive. You shouldn't use whitespace, or underscores, or Umlauts (ä, ü) in your labels. TeX will convert them to something funny. Using XeTeX or LuaTeX you can use Umlauts in labels. –  Johannes_B Dec 12 '13 at 18:11
    
I use \label{chap:chapter-name},\label{sec:section-name},\label{subsec:subsection‌​-name},\label{fig:figure-name},\label{tab:table-name},\label{eq:equation-na‌​me},\label{lst:code-name} and \label{itm:important-note} as shown in en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing and tex.stackexchange.com/questions/12174/… –  texenthusiast Dec 12 '13 at 19:16
    
@Johannes_B Why do you recommend not using underscores? –  Matthew Rankin Dec 12 '13 at 22:29
    
@texenthusiast Is there a reason you use hyphens instead of underscores? The two examples of multi-word labels in the first link you provided—LaTeX/Labels and Cross-referencing—used underscores as opposed to hyphens—\label{fig:my_figure} and \label{the_label}. –  Matthew Rankin Dec 12 '13 at 22:34
    
@MatthewRankin you can use them as tex.stackexchange.com/questions/121416/…, but sometimes one might get into troubles, see more tex.stackexchange.com/questions/18311/…. To eliminate all conflicts(to be safe all times), I gave my choice :). –  texenthusiast Dec 12 '13 at 22:43

1 Answer 1

Is the name of a label case-sensitive? Can the name contain spaces?

Yes and yes.

References are stored as a macro using \csname r@<name>\endcsname, so anything allowed within \csname...\endcsname is valid (as reference, see Understanding how references and labels work and What exactly do \csname and \endcsname do?). This includes a distinction between case (since, by nature \macro is different from \Macro, \MaCRo, \MACRO, ...).

As a small example consider:

enter image description here

\documentclass{article}
\expandafter\def\csname some bizarre Name 123\endcsname{Stuff}
\begin{document}
\csname some bizarre Name 123\endcsname

\section{A section}\label{sec:A section}
See~\ref{sec:A section} and~\ref{sec:a section}.
\end{document}
share|improve this answer
6  
although spaces are permitted in the name of a label, it's generally recommended that you not use them. they have been known to cause problems in journal production, so if you are submitting an article for publication, it's best to stick to the simplest option that will get the job done reliably. –  barbara beeton Dec 12 '13 at 18:57

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.