This can be done, but it could be risky; in the following example, the first word of each chapter or section is taken to automatically build the label with each invokation of \chapter
or \section
; titlesec
with its explicit
option was used to grab the title; using xstring
, the first word is extracted:
\documentclass[10pt]{book}
\usepackage[explicit]{titlesec}
\usepackage{xstring}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge\StrBefore{#1}{ }[\mlabel]#1\label{\mlabel}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{\StrBefore{#1}{ }[\mlabel]#1\label{\mlabel}}
\begin{document}
Some references to chapters: \ref{Some} and \ref{Other} and some references to sections: \ref{A} and \ref{Another}
\chapter{Some Chapter}
\section{A Test Section}
\chapter{Other Chapter}
\section{Another Test Section}
\end{document}

If two sectional units have the same initial word in their titles, this will fail, but you could then select a different string to build the labels.
In my initial solution I assumed that the titles contain at least one blank space, but one could use another string; for example (as in nicolai.rostov's answer) the whole name of the sectional unit. In this case, the xstring package is not needed anymore and one could simply say
\documentclass[10pt]{book}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge#1\label{#1}}
\titleformat{\section}
{\normalfont\Large\bfseries}{\thesection}{1em}{#1\label{#1}}
\begin{document}
Some references to chapters: \ref{Some Chapter} and \ref{Other Chapter} and some references to sections: \ref{A Test Section} and \ref{Another Test Section}
\chapter{Some Chapter}
\section{A Test Section}
\chapter{Other Chapter}
\section{Another Test Section}
\end{document}
My examples only show the mechanism for chapters and sections, but it can be easily extended to other sectional units.
C-c C-s
and you can label each section, just by hitting theEnter
key. – kan Apr 12 '13 at 1:25