# error while using amsmath package

I try to run this:

   \documentclass{article}
\usepackage{amsmath}
\renewcommand\thesection{\arabic{section}.}
\makeatletter
\renewcommand{\section}{
\@startsection
{section}{1}{0mm}
{\baselineskip}%
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}
}%
\makeatother
\begin{document}
\tableofcontents
\section{A}
\end{document}


and I get a message that something's wrong with '.toc' file, so what's wrong? Why does this not like amsmath package?

-
@egreg's answer was quicker by half a second, and more complete so I removed mine. –  David Carlisle Mar 31 '12 at 22:40
Please consider accepting the answer by clicking the tick button below the voting arrows on the left side. By doing so you will conclude the question. If there is still something missing in the answer please state so. –  Martin Scharrer May 7 '12 at 13:12

It subtly depends on the fact that amsmath redefines \@ifnextchar. In practical terms, you have a spurious space that the kernel version of that internal command removes, while the amsmath version doesn't.

\makeatletter
\renewcommand{\section}{%
\@startsection
{section}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother


Notice particularly the last % that masks the end-of-line (equivalent to a space, here). The end-of-lines from the \@startsection line until the last one need not to be masked, because \@startsection will be looking for arguments and so ignore the spaces. Putting % there does no harm, anyway.

By the way, redefining \thesection is not the best method for adding a period after the section number in a heading:

\makeatletter
\makeatother


is better, because \ref won't produce the number followed by a period when referring to a section number. So, here's the complete example:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand{\section}{%
\@startsection
{section}{1}{0mm}
{\baselineskip}
{\baselineskip}
{\fontsize{14}{14}\centering\bfseries\MakeUppercase}%
}
\makeatother
\begin{document}
\tableofcontents
\section{A}
\end{document}

-
'because \ref won't produce the number followed by a period when referring to a section number' it's just an answer to the next question I had, thanks! ;) –  Pavasaris Mar 31 '12 at 22:22
@myname Welcome to TeX.SX, where somebody has a crystal ball that sometimes works. :) –  egreg Mar 31 '12 at 22:23