1

I need to refer in \frametitle to a section that I have labelled with a new command \mylabel. Here is the code

\documentclass{beamer} 


\makeatletter
\newcommand*{\mylabel}[2]{%
\@bsphack
\begingroup
\def\@currentlabel{#2}%
\label{#1}%
\endgroup
\@esphack

}
\makeatother


\begin{document}



\section[Title 1]{This is a long title that gos on very long long long long long  
 long long title more long long }{\mylabel{LabelTopic1}{This is a long title that  
 gos on very long long long long long long long title more long long }}



\frame<presentation>{\frametitle{\ref{LabelTopic1}}}




\end{document}

This is what I have got enter image description here

The problem is that the name is too long and does not fit in one line of frametitle and the line does not break. I think that something is missing in the command \mylabel. But I don't know what.

Thank you for any help

  • I've tried \protect. But it doesn't work. Thank you anyhow. – michele Mar 14 '14 at 22:18
  • I am bit niave. I have understood to do the following ' \section[Title 1]{This is a long title that gos on very long long long long long long long title more long long }{\mylabel{LabelTopic1}{This is a long title that gos on very long long long long long long long title more long long }} – michele Mar 14 '14 at 22:22
  • I really don't understant. But with me it doesn't work. I am using miktex 2.9. But I don't think that is the problem. It must be somethingelse. – michele Mar 14 '14 at 22:43
1

The title and section names are what is known as moving arguments and the macros inside them should be protected from bad omen and Dutch weather. (Extra reading if interested : Why use \DeclareTextFontCommand vs. just \newcommand?) Compile it twice

\documentclass{beamer} 

\makeatletter
\newcommand*{\mylabel}[2]{%
\@bsphack%
\begingroup%
\def\@currentlabel{#2}%
\label{#1}%
\endgroup%
\@esphack%
}
\makeatother
\begin{document}

\section[Title 1]{This is a long title that gos on very long long long
                  long long long long title more long long }{% Watch the next line
                      \protect\mylabel{LabelTopic1}{This is a long title that gos on very 
                      long long long long long long long title more long long}%
                      }

\frame<presentation>{\frametitle{\ref{LabelTopic1}}}
\end{document}

enter image description here

| improve this answer | |
  • tex.stackexchange.com/questions/4736/… might also be useful 'extra reading' to link to. – Adam Liter Mar 14 '14 at 22:43
  • @Adam Yes that's included in David's answer – percusse Mar 14 '14 at 22:59
  • Thank you. The reading were indeed intersting. At the end I got it. I had to use XeLaTex or LuaLaTex (not Latex), which allow me to use robust commands (at least I think to have understood). – michele Mar 14 '14 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.