2

I have a custom .sty file that has an option, "slides", for including packages and commands specific to beamer documents. Here's how it's structured:

\NeedsTeXFormat{LaTeX2e} \ProvidesPackage{master-sty-mwe} % switch for 'slides' option \newif\ifyourpkgprefix@slidesoption\yourpkgprefix@slidesoptionfalse \DeclareOption{slides}{\yourpkgprefix@slidesoptiontrue} \DeclareOption*{\OptionNotUsed} % discard any undeclared option \ProcessOptions\relax \ifyourpkgprefix@slidesoption % Place anything here that is specific to slides \beamertemplatenavigationsymbolsempty \addtobeamertemplate{navigation symbols}{}{ % if noframenumbering is specified, don't print slide numbers. % else, do print slide numbers. \ifbeamer@noframenumbering \relax \else% \usebeamerfont{footline}% \usebeamercolor[fg]{footline}% \hspace{1em}% {\scriptsize\insertframenumber/\inserttotalframenumber} \fi% } \else % Place anything here that is specific to non-slides \fi \endinput 

What I want to achieve in the first if block is to print the current slide number and the total slide number on a slide, unless noframenumbering is specified with \begin{frame}[noframenumbering]. This all works in the following .tex file:

\documentclass{beamer} \usepackage[slides]{master-sty-mwe} \begin{document} \begin{frame}[noframenumbering] slide with no slide numbers \end{frame} \begin{frame} slide with slide numbers \end{frame} \end{document} 

But when I include the .sty file without the "slides" option, I get an Undefined control sequence for \usebeamerfont[footline].

Here is a .tex file that triggers the error:

\documentclass{article} \usepackage{master-sty-mwe} \begin{document} test \end{document} 

With some tweaking around, it seems to be the \ifbeamer@noframenumbering if/else statement that's causing the error (commenting it out fixes it), but I can't tell why we're in the \ifyourpkgprefix@slidesoption block in the first place.

I tried changing \ifbeamer@noframenumbering to something false like \ifnum2>3 but that doesn't retrigger the error. Changing it to \ifbeamer@containsverbatim also triggers the error. These ifs are defined in "beamerbaseframe.sty".

I would want to be able to use my .sty file with and without the "slides" option without running into this error, but at this point, I'm also very curious about what's going on.

1 Answer 1

4

This is a standard issue independent of beamer: it's about how TeX parses conditionals. You have the primitive TeX conditional opening with \ifyourpkgprefix@slidesoption, which TeX then works through looking for a token equal to \else or \fi. When you load beamer, it finds \ifbeamer@noframenumbering and that is also equal to a start-of-conditional. TeX then looks first at this (so 'using up' an \else and \fi), then 'using up' the outer \else and \fi. When you don't load beamer, \ifbeamer@noframenumbering is not defined but that means the first \else TeX sees is matched with \ifyourpkgprefix@slidesoption.

To get around this, you have a couple of options. Probably the easiest is to do \csname else\endcsname, etc., i.e. 'hide' the tokens

\ifyourpkgprefix@slidesoption % Place anything here that is specific to slides \beamertemplatenavigationsymbolsempty \addtobeamertemplate{navigation symbols}{}{ % if noframenumbering is specified, don't print slide numbers. % else, do print slide numbers. \csname ifbeamer@noframenumbering\endcsname \relax \csname else\endcsname \usebeamerfont{footline}% \usebeamercolor[fg]{footline}% \hspace{1em}% {\scriptsize\insertframenumber/\inserttotalframenumber} \csname fi\endcsname } \else % Place anything here that is specific to non-slides \fi 
1
  • Thank you! It now compiles when the slides option is off, but when it is on, I'm getting an incomplete \iftrue error for the first frame with noframenumbering, and an incomplete \iffalse error for the first frame without noframenumbering. I'm guessing that the parser isn't finding the first else in the first case, and the first fi in the second? Commented Jun 23 at 13:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.