Some background: I have been working on a 600 page LaTeX document (a scientific writing with a lot of math) for 15+ years. The source is trilingual (English, Norwegian and Spanish) with identical numbering of all chapters/ figures/ tables/ equations in all the three languages. It is (semi)automatically translated to a series of Beamer slideshows - one show for each language - again with identical numbering of the same text elements as mentioned above. The idea has been to write and maintain one piece of code to make cross referencing of text elements easier (not to say possible), with a view to teaching the same subject for different people in different grades from MSc to PhD, both physically and online at the same time. The software worked flawlessly for many years (and saved me a lot of time) until changes in the outside world made it harder for me to keep up with the good intentions. A week ago I decided to install my old scripts on a new computer to see if I could save the project and to my delight it compiled again (after years of dormancy). Another triumph with open source software!
However, inside the Spanish version of the Beamer slideshow there was a new error saying "! Extra \else." All the remaining material compiled just fine. Now, the root of the problem seems to be the unintentional misuse of \vpageref inside a Beamer frame, but only if the frame is inserted via a file that is part of an \include statement. My question is not primarily how to fix the problem but rather what is the cause of it, so that I can learn how to steer away in the future. I find errors like this very difficult to deal with - maybe I have too little understanding of the TeX language.
This is the MWE:
% Mac OS Big Sur v11.4
% This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/MacPorts 2020.54632_4)
% LaTeX2e <2020-02-02> patch level 5
% Document Class: beamer 2019/09/29 v3.57
\documentclass{beamer}
\usepackage{varioref}
\begin{document}
\include{./includefile}
\end{document}
The includefile is:
\begin{frame}
\vpageref{aRef} % or \vref{aRef}
\end{frame}%
The exact error message is:
! Extra \else.
\@include ...ediate \closeout \@partaux \fi \else
\deadcycles \z@ \@nameuse ...
l.9 \include{./inputfile}