I'm writing my own .sty file. It contains its own table of contents and commands like \section{}, but nothing works because the output to the file for the table of contents does not work correctly
Here's what the output should look like:
\hyperref[mysection1]{\bfseries 3\hskip 1em\relax Section\dotfill \pageref {mysection1}}
\hyperref[mysection2]{\bfseries 3\hskip 1em\relax Section\dotfill \pageref {mysection2}}
аnd here's what it looks like:
\hyperref [mysection3]{\bfseries 3\hskip 1em\relax Section\dotfill \pageref {mysection3}}
\hyperref [mysection3]{\bfseries 3\hskip 1em\relax Section\dotfill \pageref {mysection3}}
Here is the code from .tex file:
\documentclass[10pt]{article}
\usepackage{cmap}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,russian]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{mysty}
\begin{document}
\mytableofcontents
\section{Section}
\section{Section}
\end{document}
Here is the code from mysty.sty file:
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{setspace}
\RequirePackage{hyperref}
\newwrite\myoutput
\immediate\openout\myoutput=toc.tex
\newcounter{sections}
\setcounter{sections}{1}
\renewcommand{\section}[1]{%
\vspace{2ex}
\label{mysection\the\value{sections}}%
\noindent\textbf{\arabic{sections}.\quad #1}%
\write\myoutput{\hyperref[mysection\the\value{sections}]{\bfseries\the\value{sections}\quad #1\dotfill\pageref{mysection\arabic{sections}}}}%
\stepcounter{sections}
\vspace{2ex}
}
\newcommand{\mytableofcontents}{%
\newpage\thispagestyle{empty}
\noindent\textbf{Table of Contents}
\input{toc}
\newpage
}
\endinput

\immediatebefore\write, a lot of errors will come out – Andrew D. Dec 03 '23 at 13:38\immediate\write. But why are you not using any of the facilities latex offers for section commands and writing the table of contents data? – David Carlisle Dec 03 '23 at 13:47\labeland\refsections. – David Carlisle Dec 03 '23 at 14:12