0

Related in particular to the following question:

tex.stackexchange.com/questions/376836

I want to know how to obtain the next number in the toc for a section without any frames?

To complicate the matter a little more: I am working with customized squares for the sections in the toc, as presented here:

tex.stackexchange.com/questions/422192

The best I could do so far is the following MWE,

\documentclass{beamer}

\defbeamertemplate{section in toc}{my squares toc}
{\leavevmode\leftskip=1.75ex%
    \llap{%
         \usebeamerfont*{section number projected}%
         \usebeamercolor[bg]{section number projected}%
         \vrule width2.9ex height2.32ex depth.78ex%
         \hskip-2.8ex%
         \hbox to2.7ex{\hfil\color{fg}\inserttocsectionnumber\hfil}}%
    \kern1.5ex\inserttocsection\par}
\setbeamertemplate{section in toc}[my squares toc]

\makeatletter
\newcommand\immaddtocontents[1]{{%
        \let\protect\@unexpandable@protect
        \immediate\write\@auxout{\noexpand\@writefile{toc}{#1}}%
}}
\makeatother

\begin{document}

\begin{frame}{TOC}
    \tableofcontents
\end{frame}

\section{The first section}

\begin{frame}
Some text.
\end{frame}

\section{The second section}

\immaddtocontents{\vfill \leavevmode\leftskip=1.75ex \protect\usebeamercolor[fg]{section in toc}
    \kern1.5ex \insertsection \par}

\end{document}

I would be happy to avoid, if possible, any additional package. 1 2

1 Answers1

1

I found a solution myself. In the unlikely case anyone is interested in my question - I present the solution.

It is however a bit clunky and I appreciate any improvement.

\documentclass{beamer}

\defbeamertemplate{section in toc}{my squares toc}
{\leavevmode\leftskip=1.75ex%
    \llap{%
        \usebeamerfont*{section number projected}%
        \usebeamercolor[bg]{section number projected}%
        \vrule width2.9ex height2.32ex depth.78ex%
        \hskip-2.8ex%
        \hbox to2.7ex{\hfil\color{fg}\inserttocsectionnumber\hfil}}%
    \kern1.5ex\inserttocsection\par}
\setbeamertemplate{section in toc}[my squares toc]

\makeatletter
\newcommand\immaddtocontents[1]{{%
        \let\protect\@unexpandable@protect
        \immediate\write\@auxout{\noexpand\@writefile{toc}{#1}}%
}}
\makeatother

\begin{document}

\begin{frame}{TOC}
    \tableofcontents[pausesections]
\end{frame}

\section{The first section}

\begin{frame}
Some text.
\end{frame}

\section{The second section}

\immaddtocontents{\onslide<2->{\vfill \leavevmode\leftskip=1.75ex \protect\usebeamercolor[fg]{section in toc}
         \llap{%
             \usebeamerfont*{section number projected}%
            %\color{my color background}%       %\usebeamercolor[fg or bg]{beamer-color name} does not work
             \vrule width2.9ex height2.32ex depth.78ex%
             \hskip-2.8ex%
             \hbox to2.7ex{\hfil\color{white}\insertsectionnumber\hfil}}% %color{fg} changed to \color{white}
        \kern1.5ex \insertsection \par}}

\end{document}

As seen, I only changed the \immaddtocontents{...} after the section without slides and imitated the defined section in toc template. I run across color problems, that I fixed in certain ways.

I needed to change the color commands - \usebeamercolor[bg]{...} as well as \color[fg] did not work for some reason.

The other differences to code of the code in the question are the [pausesections] option after \tableofcontents and \onslide... inside \immaddtocontents{...}. These changes are just made to obtain the display order I prefer.

answer1 answer2 answer3