# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8679840564727783, "perplexity": 1965.5077399949769}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2015-27/segments/1435375096991.38/warc/CC-MAIN-20150627031816-00091-ip-10-179-60-89.ec2.internal.warc.gz"}