I newbee to writing a class for syllabus book creation. I am trying to generate a \jobname.toc file outputing commands, which when I try to read through \input{\jobname.toc} inside tabular environment, it doesn't generate any output.
\def\fileversion{1.0}
\def\filedate{2025/08/05}
%% Starting point of class
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{syllabus}[\filedate\space Version \fileversion]
%% Passing all the previous Options that the rvexamwcmt class revices to article class
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{book}%
}
\ProcessOptions\relax
\LoadClass{book}
\RequirePackage{ifthen}
\RequirePackage{longtable}
% class code
% Open .toc file for writing
\newwrite\syll@tocfile
\immediate\openout\syll@tocfile=\jobname.toctree
\newcommand*{\tocentry}[2]{#1 & #2\\}
\newcommand*{\addtotableofcontents}[1]{%
\edef\@currenttitle{#1}%
\immediate\write\syll@tocfile{\string\tocentry\space{\@currenttitle}{\thepage}}%
}
\newcommand\Mytableofcontents{%
\section*{Contents}
\IfFileExists{\jobname.toctree}{\jobname.toctree File Found }{\textit{(No entries found.)}}\\
\begin{table}[h]
\centering
\begin{tabular}{|p{1.2\linewidth}|r|}
\tocentry{Introduction}{2}
\input{\jobname.toctree}
\message{>>> Finished reading \jobname.toctree^^J}
\end{tabular}
\end{table}
}
\endinput
and Main.tex file:
\documentclass{syllabus}
\usepackage{lipsum} % For dummy text
\begin{document}
\Mytableofcontents
\clearpage
\chapter{Introduction}
\section{Introduction}
\addtotableofcontents{Induction}
\lipsum[1]
\section{Methodology}
\addtotableofcontents{Methodology}
\lipsum[2]
\section{Results}
\addtotableofcontents{Results}
\lipsum[3]
\section{Conclusion}
\addtotableofcontents{Conclusion}
\lipsum[4]
\end{document}
I am not getting any output because of \input{}. I also tried modifying the .cls file
\newread\foo
\newcommand\Mytableofcontents{%
\openin\foo=\jobname.toctree
\read\foo to \x
\closein\foo
\section*{Contents}
\IfFileExists{\jobname.toctree}{\jobname.toctree File Found }{\textit{(No entries found.)}}\\
% \hline\\
\begin{table}[h]
\centering
\begin{tabular}{|p{1.2\linewidth}|r|}
\tocentry{Introduction}{2}
% \input{\jobname.toctree}
\x
\message{>>> Finished reading \jobname.toctree^^J}
\end{tabular}
\end{table}
}


\begin{table}[h]here it makes no sense to float that table..tocfile, which would handle this automatically? you can write and format the toc however you need, so I'd only add another output stream if you actually need something distinct. otherwise, you're just wasting one of a limited number of such streams.