I am trying to modify the title of table of content and make every title of sections uppercase. But strange compilation errors occurred.
The .tex file looks like the following one:
\documentclass{article}
\usepackage{szx}
\begin{document}
\section*{fgh}
vbn
\tableofcontents
\section{zxc}
qwe
\end{document}
And I have tried 3 different szx.sty file, neither of them works.
The first one uses xparse package:
\ProvidesPackage{szx}
\usepackage{xparse}
\RequirePackage{titlecaps}
\let\@szx@oldsection\section
\newcommand{\@szx@sectionstar}[1]{\@szx@oldsection*{\titlecap{#1}}}
\newcommand{\@szx@section}[1]{\@szx@oldsection{\titlecap{#1}}}
\RenewDocumentCommand{\section}{s}{\IfBooleanTF{#1}{\@szx@sectionstar}{\@szx@section}}
\let\@szx@TocName\contentsname
\renewcommand*{\contentsname}{\centering{\@szx@TocName}}
The second one uses \DeclareRobustCommand:
\ProvidesPackage{szx}
\RequirePackage{titlecaps}
\let\@szx@oldsection\section
\DeclareRobustCommand{\@szx@sectionstar}[1]{\@szx@oldsection*{\titlecap{#1}}}
\DeclareRobustCommand{\@szx@section}[1]{\@szx@oldsection{\titlecap{#1}}}
\DeclareRobustCommand{\section}{\@ifstar\@szx@sectionstar\@szx@section}
\let\@szx@TocName\contentsname
\DeclareRobustCommand*{\contentsname}{\centering{\@szx@TocName}}
The last one uses makerobust package:
\ProvidesPackage{szx}
\RequirePackage{makerobust}
\RequirePackage{titlecaps}
\let\@szx@oldsection\section
\newcommand{\@szx@sectionstar}[1]{\@szx@oldsection*{\titlecap{#1}}}
\newcommand{\@szx@section}[1]{\@szx@oldsection{\titlecap{#1}}}
\MakeRobustCommand{\@szx@sectionstar}
\MakeRobustCommand{\@szx@section}
\renewcommand{\section}{\@ifstar\@szx@sectionstar\@szx@section}
\MakeRobustCommand{\section}
\let\@szx@TocName\contentsname
\renewcommand*{\contentsname}{\centering{\@szx@TocName}}
\MakeRobustCommand{\contentsname}
The error messages were the same and looks like:
Use of \titlecap doesn't match its definition. \tableofcontents
Argument of \@firstoftwo has an extra }. \tableofcontents
Paragraph ended before \@firstoftwo was complete. \tableofcontents
Something's wrong--perhaps a missing \item. \tableofcontents
Undefined control sequence. \tableofcontents
Illegal parameter number in definition of \the@@@string. \tableofcontents
Undefined control sequence. \tableofcontents
Incomplete \iffalse; all text was ignored after line 12.

\section. Using a formatting command in the code for\contentsnameis definitely a bad idea. – egreg Nov 04 '16 at 09:07