![AIP 提供的 LaTex 模板无法插入伪代码](https://linux22.com/image/452881/AIP%20%E6%8F%90%E4%BE%9B%E7%9A%84%20LaTex%20%E6%A8%A1%E6%9D%BF%E6%97%A0%E6%B3%95%E6%8F%92%E5%85%A5%E4%BC%AA%E4%BB%A3%E7%A0%81%20.png)
为了向 Chaos 屈服,我下载了Latex 模板AIP 请求。但是当我要插入如下伪代码时
\begin{algorithm}
%\textsl{}\setstretch{1.8}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\caption{STVMD based on STFT}
\label{alg1}
\begin{algorithmic}[1]
\STATE Initialization:$\left\{ {s_{k,t}^1} \right\},\left\{ {\omega _{k,t}^1} \right\},\lambda _t^1,n \leftarrow 0$
\STATE ${s_{r,t}}\left( \omega \right) = \int_0^{ + \infty } {{s_r}\left( \tau \right){w_h}\left( {t - \tau } \right)} \exp \left( {j\omega \tau } \right)d\tau $ (via STFT)
\REPEAT
\STATE $n \leftarrow n + 1$
\STATE Update $ s_{k,t}^{n + 1} $ based on Equation~(\ref{eqn_8})
\STATE Update $\omega _{k,t}^{n + 1}$ based on Equation~(\ref{eqn_9})
\STATE Update $\lambda _t^{n + 1} $ based on Equation~(\ref{eqn_10})
\UNTIL $\sum\limits_{k=1}^P {{{\left\| {s_{k,t}^{n + 1}\left( \omega \right) - s_{k,t}^n\left( \omega \right)} \right\|_2^2} \mathord{\left/
{\vphantom {{\left\| {s_{k,t}^{n + 1}\left( \omega \right) - s_{k,t}^n\left( \omega \right)} \right\|_2^2} {\left\| {s_{k,t}^n\left( \omega \right)} \right\|_2^2}}} \right.
\kern-\nulldelimiterspace} {\left\| {s_{k,t}^n\left( \omega \right)} \right\|_2^2}}} < \varepsilon $
\STATE Update ${s_k}\left( t \right)$ based on Equation~(\ref{eqn_11_12}) (via ISTFT)
\ENSURE decomposed modes $ \left\{ {{s_k}\left( t \right)} \right\}$, $\left\{ {{\omega _k}\left( t \right)} \right\}$
\end{algorithmic}
\end{algorithm}
但编译时抛出了奇怪的错误:
! Missing \endcsname inserted.
<to be read again>
\c@float@type
l.123 \end{algorithm}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
! Missing number, treated as zero.
<to be read again>
\endcsname
l.123 \end{algorithm}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
! Extra \endcsname.
<recently read> \endcsname
l.123 \end{algorithm}
I'm ignoring this, since I wasn't doing a \csname.
(./aipsamp.bbl
简而言之! 缺少插入 \endcsname。,!缺失数字,视为零。和!缺失数字,视为零。
我搜索了整个互联网,但没有找到解决此错误的办法,任何人都可以帮忙AIP LaTex 模板中的伪代码? 多谢。
完整的文档示例为
% ****** Start of file aipsamp.tex ******
%
% This file is part of the AIP files in the AIP distribution for REVTeX 4.
% Version 4.1 of REVTeX, October 2009
%
% Copyright (c) 2009 American Institute of Physics.
%
% See the AIP README file for restrictions and more information.
%
% TeX'ing this file requires that you have AMS-LaTeX 2.0 installed
% as well as the rest of the prerequisites for REVTeX 4.1
%
% It also requires running BibTeX. The commands are as follows:
%
% 1) latex aipsamp
% 2) bibtex aipsamp
% 3) latex aipsamp
% 4) latex aipsamp
%
% Use this file as a source of example code for your aip document.
% Use the file aiptemplate.tex as a template for your document.
\documentclass[%
aip,
% jmp,
% bmf,
% sd,
% rsi,
amsmath,amssymb,
%preprint,%
reprint,%
%author-year,%
%author-numerical,%
% Conference Proceedings
]{revtex4-1}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
%\usepackage[mathlines]{lineno}% Enable numbering of text and display math
%\linenumbers\relax % Commence numbering lines
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage{etoolbox}
\usepackage{algorithm}
\usepackage{algorithmic}
%\usepackage{algorithmicx}
%\usepackage{algpseudocode}
%% Apr 2021: AIP requests that the corresponding
%% email to be moved after the affiliations
\makeatletter
\def\@email#1#2{%
\endgroup
\patchcmd{\titleblock@produce}
{\frontmatter@RRAPformat}
{\frontmatter@RRAPformat{\produce@RRAP{*#1\href{mailto:#2}{#2}}}\frontmatter@RRAPformat}
{}{}
}%
\makeatother
\begin{document}
\preprint{AIP/123-QED}
\title[Sample title]{Sample Title:\\with Forced Linebreak}
% Force line breaks with \\
\author{A. Author}
\altaffiliation[Also at ]{Physics Department, XYZ University.}%Lines break automatically or can be forced with \\
\author{B. Author}%
\email{[email protected].}
\affiliation{
Authors' institution and/or address%\\This line break forced with \textbackslash\textbackslash
}%
\author{C. Author}
\homepage{http://www.Second.institution.edu/~Charlie.Author.}
\affiliation{%
Second institution and/or address%\\This line break forced% with \\
}%
\date{\today}% It is always \today, today,
% but any date may be explicitly specified
\begin{algorithm}
%\textsl{}\setstretch{1.8}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\caption{STVMD based on STFT}
\label{alg1}
\begin{algorithmic}[1]
\STATE Initialization:$\left\{ {s_{k,t}^1} \right\},\left\{ {\omega _{k,t}^1} \right\},\lambda _t^1,n \leftarrow 0$
\STATE ${s_{r,t}}\left( \omega \right) = \int_0^{ + \infty } {{s_r}\left( \tau \right){w_h}\left( {t - \tau } \right)} \exp \left( {j\omega \tau } \right)d\tau $ (via STFT)
\REPEAT
\STATE $n \leftarrow n + 1$
\STATE Update $ s_{k,t}^{n + 1} $ based on Equation~(\ref{eqn_8})
\STATE Update $\omega _{k,t}^{n + 1}$ based on Equation~(\ref{eqn_9})
\STATE Update $\lambda _t^{n + 1} $ based on Equation~(\ref{eqn_10})
\UNTIL $\sum\limits_{k=1}^P {{{\left\| {s_{k,t}^{n + 1}\left( \omega \right) - s_{k,t}^n\left( \omega \right)} \right\|_2^2} \mathord{\left/
{\vphantom {{\left\| {s_{k,t}^{n + 1}\left( \omega \right) - s_{k,t}^n\left( \omega \right)} \right\|_2^2} {\left\| {s_{k,t}^n\left( \omega \right)} \right\|_2^2}}} \right.
\kern-\nulldelimiterspace} {\left\| {s_{k,t}^n\left( \omega \right)} \right\|_2^2}}} < \varepsilon $
\STATE Update ${s_k}\left( t \right)$ based on Equation~(\ref{eqn_11_12}) (via ISTFT)
\ENSURE decomposed modes $ \left\{ {{s_k}\left( t \right)} \right\}$, $\left\{ {{\omega _k}\left( t \right)} \right\}$
\end{algorithmic}
\end{algorithm}
\bibliography{aipsamp}% Produces the bibliography via BibTeX.
\end{document}
%
% ****** End of file aipsamp.tex ******
答案1
根据回答,你可能需要在 \begin{algorithm} 之后使用 [H](大写 H!)