# Beamer Lecture: reference title of lecture in the course

Example:

\documentclass{beamer}

\begin{document}

\lecture{lecture 1}{week 1}
\begin{frame}
\end{frame}

\begin{frame}
see Lecture \ref{week 1}
\end{frame}

\end{document}


This yields

yet it would be nice to have something like "see Lecture 'lecture 1'", so printing the title of the lecture with label "week 1".

Any ideas how to implement this? Ideally, this should be compatible with cross-referencing and includeonlylecture as explained at reference to equation from other lecture in class beamer

Icing on the cake would be the following: having a macro \lectureref{label}, where label is a \label{}-label on a frame within the scope of a \lecture{}-lecture.

## 1 Answer

This is actually fairly easily done. You can already manually set a \label for a \lecture and use that for cross-referencing. We can easily insert one at every \lecture using \AtBeginLecture. In order to allow referencing the name, we have to set \@currentlabelname first. (I chose to use the short lecture title for this, but you can the the long form if you prefer.) Then, we can use the usual commands \ref and \nameref.

It is generally advisable to name all your labels with a prefix denoting their type. I chose the lec: prefix here. So you will have to use e.g. the label week-1 in beamer's native commands but lec:week-1 when cross referencing.

\documentclass{beamer}

\usepackage{csquotes}

\makeatletter
\AtBeginLecture{%
\edef\@currentlabelname{\beamer@shortlecturename}%
\label{lec:\beamer@currentlecturelabel}%
}
\makeatother

\includeonlylecture{week-2}

\begin{document}

\lecture[short week~1 title]{very long and clumsy week~1 title}{week-1}
\begin{frame}
a frame
\end{frame}

\lecture{week~2 title}{week-2}
\begin{frame}
see lecture~\ref{lec:week-1}, which is called~\enquote{\nameref{lec:week-1}}
\end{frame}

\end{document}


• I'll think some more about your icing on the cake, though that is a bit more involved. Jan 27, 2021 at 12:08
• Great and thanks. Regarding this xr-solution from the other question, I just was surprised that (it seems, if I do not mix things up) I can avoid using this package and the solution with externaldocument when I use frame-labels after the frame I want to reference. Yet a \lectureref-command would be here very handy.
– Arne
Jan 27, 2021 at 13:09