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.



