[Tex/LaTex] ! Missing \endcsname inserted in \begin {algorithmic}

algorithmicalgorithmicxalgorithms

file1.tex:

\documentclass[12pt,letterpaper]{report}

%%%%%%%%%%%%%%%% Xiaodi add:

\usepackage{longtable}
\newcommand{\argmin}{\arg\!\min}
\usepackage[dvips]{graphicx}
\usepackage{color,amsmath,latexsym,amssymb}
\usepackage{xspace}
\usepackage{pgf,tikz}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{algorithm} 
\usepackage{algpseudocode}
%\usepackage{siunitx,booktabs,multirow}
\usepackage{caption}
\usepackage{subcaption}
\captionsetup[algorithm]{font=footnotesize}
\usepackage{float}
%\usepackage{algcompatible}
\usepackage[toc,page]{appendix}
\newcounter{assum}
\numberwithin{equation}{section}
\usepackage{bm}

\begin{document}
\include{file2}
\end{document}

file2.tex (version 1)

\section{Test}
\begin{algorithm}
\begin{algorithmic}
\state Hi
\end{algorithmic}
\end{algorithm}

Error corresponding to version 1:
! Missing \endcsname inserted.

\protect
l.3 \begin
{algorithmic}
?

Best Answer

Minimising your example (which hardly depended on TiKZ or external graphics and what have you), you just need to add something to the algorithm you are defining. I haven't checked, but I assume that it is defined as a list environment, and that it therefore expects an \item. The relevant commands defined by the packages you are loading will themselves be defined in terms of \item, so that you do not need to call it directly (which makes the error a bit misleading if you are not used to this kind of thing).

For example, this works:

\begin{filecontents}{a.tex}
  Newton's method except for the computation of derivatives.\\
  \begin{algorithm}
    \begin{algorithmic}
      \State 1
    \end{algorithmic}
  \end{algorithm}
\end{filecontents}
\documentclass[12pt,letterpaper]{report}
\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{document}
  \input{a}
\end{document}