WPS插入LaTeX伪代码

更新:

原文已经搬运至网站:https://www.link2sea.com/archives/305,后续也将在该网站进行更新。

查看博主更多文章请前往:https://www.link2sea.com/

下面是原文:

2018-05-20 原文:

本来一直都是用word写论文,最近需要插入伪代码,网上搜了下可以安装一个插件,叫做 Aurora,具体方法参考百度经验“如何在WPS或word中插入伪代码”

 

但是上文没有给参考程序,于是博主直接找的 LaTeX 写伪代码的程序,但是并不能运行,出现有错误,后来看了几篇 Aurora 写伪代码的博客,对照着 LaTeX 的程序作了对比明白的之间的差异。

这是一篇可以实现的博客:“如何在word中插入latex公式和伪代码”

 

先说一下在 LaTeX 上写伪代码,有很多例子,参考博客:“Latex写算法的伪代码排版”,我是在TeXworks编辑的,但是有一点要注意,就是要用 XeLaTeX 命令,用默认的 pdfLaTeX 会出错。

 

下边举一个例子说明 LaTeX 和 Aurora 的区别,很重要的就是 Aurora 上没有以下这些语句,而 usepackage 要在 properties 里面的 packages 里面添加,而且 begin{algorithm}[h] 中的 h 应该为大写的 H 。

\documentclass[11pt]{ctexart}  
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}  
\usepackage{algorithm}  
\usepackage{algorithmicx}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  

\begin{document}  
 
\end{document}  

我的 packages 里面的内容如下:

\usepackage{amsmath}
\usepackage{amssymb}
% \usepackage{euler}
\providecommand{\abs}[1]{\left\lvert#1\right\rvert}
\providecommand{\norm}[1]{\left\lVert#1\right\rVert}
\usepackage{bbm}
\usepackage{CJK}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{amsmath,bm,graphicx,multirow,bm,bbm,amssymb,psfrag,algorithm,subfigure,color,mdframed,wasysym,subeqnarray,multicol}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}

仅供参考,反正可以用,没有深入研究过这个东西。

下面是一个例子,先上效果图

LaTeX 中的代码为:

\documentclass[11pt]{ctexart}  
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}  
\usepackage{algorithm}  
\usepackage{algorithmicx}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  

\begin{document}  
\begin{algorithm}[h]  
  \caption{An example for format For \& While Loop in Algorithm}  
  \begin{algorithmic}[1]  
    \For{each $i\in [1,9]$}  
      \State initialize a tree $T_{i}$ with only a leaf (the root);  
      \State $T=T\cup T_{i};$  
    \EndFor  
    \ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$}  
      \label{code:TrainBase:getc}  
      \State $T=T\cup PosSample(c)$;  
      \label{code:TrainBase:pos}  
    \EndFor;  
    \For{$i=1$; $i<n$; $i++$ }  
      \State $//$ Your source here;  
    \EndFor  
    \For{$i=1$ to $n$}  
      \State $//$ Your source here;  
    \EndFor  
    \State $//$ Reusing recent base classifiers.  
    \label{code:recentStart}  
    \While {$(|E_n| \leq L_1 )and( D \neq \phi)$}  
      \State Selecting the most recent classifier $c_i$ from $D$;  
      \State $D=D-c_i$;  
      \State $E_n=E_n+c_i$;  
    \EndWhile  
    \label{code:recentEnd}  
  \end{algorithmic}  
\end{algorithm}  
\end{document}  

而在 Aurora 中的代码为

\begin{algorithm}[H]  
  \caption{An example for format For \& While Loop in Algorithm}  
  \begin{algorithmic}[1]  
    \For{each $i\in [1,9]$}  
      \State initialize a tree $T_{i}$ with only a leaf (the root);  
      \State $T=T\cup T_{i};$  
    \EndFor  
    \ForAll {$c$ such that $c\in RecentMBatch(E_{n-1})$}  
      \label{code:TrainBase:getc}  
      \State $T=T\cup PosSample(c)$;  
      \label{code:TrainBase:pos}  
    \EndFor;  
    \For{$i=1$; $i<n$; $i++$ }  
      \State $//$ Your source here;  
    \EndFor  
    \For{$i=1$ to $n$}  
      \State $//$ Your source here;  
    \EndFor  
    \State $//$ Reusing recent base classifiers.  
    \label{code:recentStart}  
    \While {$(|E_n| \leq L_1 )and( D \neq \phi)$}  
      \State Selecting the most recent classifier $c_i$ from $D$;  
      \State $D=D-c_i$;  
      \State $E_n=E_n+c_i$;  
    \EndWhile  
    \label{code:recentEnd}  
  \end{algorithmic}  
\end{algorithm}

由于关于 Aurora 的资料太少了,所以不太好使用。知道了它与 LaTeX 的区别后就可以搜索 LaTeX 的语法来在wps实现想要的效果了!

  • 10
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值