# Beamer: Sections inside TOC without frames, but with next tocsectionnumber

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
\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}

\kern1.5ex \insertsection \par}

\end{document}


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

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
\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}

\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.