缺少插入 $,缺少插入 \endgroup

缺少插入 $,缺少插入 \endgroup

我正在用 latex 编写算法。出现了一些错误。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{Demo}
\author{Subhadip Patra }
\date{March 2020}


\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}

\maketitle

\section{Testing}
\begin{algorithm}
\begin{algorithmic}[1]
\caption{Selection of chromosome for mating pool}
\WHILE{size of mating pool \neq nPop}
    \STATE Randomly choose $p_1$ and $p_2$.
    \IF{$WS(p_1) <WS(p_2)$}
        \STATE Choose $p_1$ for mating pool.
    \ELSE
        \STATE Choose $p_2$ for mating pool.
    \ENDIF 
\ENDWHILE
\end{algorithmic}
\end{algorithm}


\end{document}

答案1

添加-$$\neq

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}

\begin{document}
    \begin{algorithm}
        \begin{algorithmic}[1]
            \caption{Selection of chromosome for mating pool}
            \WHILE{size of mating pool $\neq$ nPop}
            \STATE Randomly choose $p_1$ and $p_2$.
            \IF{$WS(p_1) <WS(p_2)$}
            \STATE Choose $p_1$ for mating pool.
            \ELSE
            \STATE Choose $p_2$ for mating pool.
            \ENDIF 
            \ENDWHILE
        \end{algorithmic}
    \end{algorithm}
\end{document}

相关内容