So verwenden Sie \mylabel in einem \frametitle

So verwenden Sie \mylabel in einem \frametitle

Ich muss auf einen Abschnitt verweisen \frametitle, den ich mit einem neuen Befehl gekennzeichnet habe \mylabel. Hier ist der 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}

Das ist, was ich habe Bildbeschreibung hier eingeben

Das Problem ist, dass der Name zu lang ist und nicht in eine Zeile des Frametitle passt und die Zeile nicht umbricht. Ich denke, dass im Befehl etwas fehlt \mylabel. Aber ich weiß nicht, was.

Vielen Dank für jede Hilfe

Antwort1

Die Titel- und Abschnittsnamen sind sogenannte bewegliche Argumente und die Makros darin sollten vor Unheil und schlechtem Wetter geschützt werden. (Weitere Lektüre bei Interesse:Warum \DeclareTextFontCommand und nicht einfach \newcommand verwenden?) Kompilieren Sie es zweimal

\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}

Bildbeschreibung hier eingeben

verwandte Informationen