Office之word中插入Latex伪代码

latex一直是一个高冷的排版工具,写出的伪代码可读性强,样式美观。
但有时我们必须要使用word,那么怎么在word里插入Latex的伪代码呢?

  1. 下载Aurora.Aurora是一个很好用的公式和伪代码编辑器。
  2. 安装后打开word,如果有插件直接在插件里打开,没有的话就在插入-对象-Aurora equation打开
  3. 导入包:Properties\rightarrowpackages粘贴一下的包:
\usepackage{amsmath}
\usepackage{amssymb}
% \usepackage{euler}
\usepackage{amsfonts}
\usepackage{mathrsfs}

\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

\usepackage{multirow}
\usepackage{CJK}
\usepackage{algorithm}
\usepackage{algorithmic}

\providecommand{\abs}[1]{\left\lvert#1\right\rvert}
\providecommand{\norm}[1]{\left\lVert#1\right\rVert}
  1. 正文可以复制代码(以下为参考示例)
\begin{algorithm}[H]
	\caption{Doppler Profile Extraction}
\begin{algorithmic}[1]
	\REQUIRE{Spectrogram matrix $P$, centre frequency bin $cf$}
	\ENSURE{Doppler shift profile $DopShift$}\\
	\STATE{colNum=getColumNum($P$);} \\
	\STATE{$DopShift$(1:colNum)=$cf$;}  //initialization \\
	\FOR{i=1:colNum}
		\STATE row=getNonNullRows(col(i)); // get non-null rows of the $i$th col\\
	\IF{isNotEmpty(row)}
		\STATE{meanValue=mean(row);}\\
       \ElSE
              \STATE{meanValue\textgreater cf}\\
              \STATE{$DopShift$(i)=max(row);}\\
              \STATE{$DopShift$(i)=min(row);}\\
       \ENDIF
	\ENDFOR
	\STATE{$DopShift$ = SMA($DopShift$);} // SMA represents smoothed moving average filter\\
       \STATE{Return $DopShift$;}
\end{algorithmic}
\end{algorithm}

几点说明:

  • Aurora的伪代码并不是严格的latex语法,需要稍作修改。具体不同请看上述代码示例;
  • 命令要大写,如STATE;
  • 如果出现问题,请仔细检查自己的代码是否和上述示例一致。

得到结果预览如下:
Office之word中插入Latex伪代码