TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command that expands to the current section name (which I can then use with \index{})?

This is similar to Name of current section/figure, but I like to get the name of the section instead of the current type, also \nameref{} doesn't work when using index. I tried

\label{sec:foo} \index{\nameref{sec:foo}}

which will show the current section name in Index, but it's out of order with the other non-\nameref{} Index entries. I believe that's because they are hyperlinked.

share|improve this question
Dirty hack: add \let\oldsection\section, \def\section#1#{\sectionii{#1}}\def\sectionii#1#2{\def\currsecname{#2}\oldsecti‌​on#1{#2}} to your preamble; then in each section \currsecname holds the name of the current section. – Bruno Le Floch Feb 13 '12 at 13:06
@Bruno: did not work for me :( Undefinied control sequenz – Megachip Nov 22 '12 at 21:32
@Megachip Which control sequence is undefined? Maybe you have a typo? – Bruno Le Floch Nov 23 '12 at 20:29
up vote 4 down vote accepted


\section{A section}\label{x}\indexref{x}

According to the documentation of nameref.sty, the title to which \label{x} refers is stored in the macro \GetTitleStringResult (globally). So we emit \nameref{x} in a box just to get the title and expand the macro containing the title before applying \index.

share|improve this answer
Thanks a log egreg, this does work! But there is now way to get the current section name from a command, so that I could avoid the detour with \label{} and \nameref{}? – Flow Feb 13 '12 at 13:46
You might redefine \section, but it's tedious; this has the merit to work with any sectional level. – egreg Feb 13 '12 at 13:53
You should be able to define \newcommand\labelandindex[1]{\label{#1}\indexref{#1} to at least avoid writing everything twice, shouldn't you? – yo' Nov 21 '13 at 8:00

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.