I'm writing a document in LyX which I will add to over time, adding a new section on each edit. I have enabled hyperref in the pdf properties and have a table of contents which correctly links to each section. However, for convenience I'd like to have a link before the toc which jumps directly to the start of the most recent (i.e. last) section.

Is it possible to access the variables used in generating the toc for this purpose? Alternatively, can I just put a label at the very end of the document (which would be a reference to a subsection) and do some maths to find the section itself? If so, how would I then link to it?

  • Welcome to TeX.sx! Please register on this site, too. Jan 4, 2013 at 18:33
  • Wouldn't it be easiest to put a label lastsection or similar manually always to the last section? I don't see too much benefit in automating this. Jan 4, 2013 at 18:36

2 Answers 2


I wouldn't take this too seriously, but it works, even if \section* is used. Of course you should never use \label{lastsection} in your document, but only \ref{lastsection} or \pageref{lastsection}.


  \unexpanded{\global\expandafter\let\expandafter\r@lastsection\csname} r@\perhaps@last\endcsname}


Last section is at page \pageref{lastsection}






enter image description here


The MWE below does what I was hoping to achieve, but ideally I'd like to do something so that I don't have to manually add the \newpage or \label{sec:lastmeeting} bits. I think I need to do a \renewcommand but, as I understand it, it all gets a bit messy because \section takes arguments.



Last meeting: \nameref{sec:lastmeeting}
\newpage\section{Meeting 1}\label{sec:lastmeeting}\lipsum[1-6]
\newpage\section{Meeting 2}\label{sec:lastmeeting}\lipsum[1-6]
  • @Stephan Thanks for the suggestion. I'm not sure what happened with my site registration and for some reason I can't comment on the original question. The benefit of automating the labelling is that I'm lazy and prone to error so would rather something repetitive be done for me.
    – howecome
    Jan 8, 2013 at 9:53

You must log in to answer this question.