Add dots to ams table of contents

amsarttable of contents

I have written this table of contents in amsart, and I am wondering if there is a simple way to adapt my code to include dots between the headings ("a","b","c") and the page number. There exist lots of ways to put dots in tables of contents on this site, but since the table of contents code I've got at the moment is particularly simple, I am curious if it can be edited simply to get dots.

\documentclass[hidelinks,12pt,a4paper]{amsart}


\makeatletter \def\l@subsection{\@tocline{2}{0pt}{4pc}{6pc}{}}
\def\l@subsubsection{\@tocline{3}{0pt}{8pc}{8pc}{}} \makeatother



\begin{document}

\author{author} \title{title} \maketitle
\renewcommand\contentsname{\vspace{-1cm}} \tableofcontents


\section{a}

\section{b}

\subsection{c}


\end{document}

enter image description here

Best Answer

Try this code:

a

\documentclass[hidelinks,12pt,a4paper]{amsart}

% ******************************************* added <<<<<<<<<<<<
\usepackage{xpatch}
\makeatletter   
\xpatchcmd{\@tocline}
{\hfil\hbox to\@pnumwidth{\@tocpagenum{#7}}\par}
{\ifnum#1<0\hfill\else\dotfill\fi\hbox to\@pnumwidth{\@tocpagenum{#7}}\par}
{}{}
\makeatother    
% *******************************************   

\makeatletter
 \def\l@subsection{\@tocline{2}{0pt}{4pc}{6pc}{}}
\def\l@subsubsection{\@tocline{3}{0pt}{8pc}{8pc}{}}
 \makeatother
    
\begin{document}
    
    \author{author} \title{title} \maketitle
    \renewcommand\contentsname{\vspace{-1cm}} \tableofcontents      
    
    \section{a}
    
    \section{b}
    
    \subsection{c}
    
    
\end{document}