• 用上Latex实现编辑伪代码


    【需求】在用word写小论文的时候想插入漂亮的伪代码,搜索发现有latex这个排版软件可以实现。

    【思路】

    1、利用Aurora插件在word中插入对象时打开latex编辑。(这个出现“problems running latex”多种方法均未被解决,遂放弃,仍想试试的见http://hqium.blog.163.com/blog/static/253625026201712110504726/#)

    2、利用CTeX里面的WinEdt编辑。(直接用Latex,但怎么将生成的结果导入到word未研究,或者直接用Latex排版小论文)

    【下载】

    [MiKTeX] https://miktex.org/download

    [Aurora2.2]  http://www.xiazaiba.com/html/31107.html

    [Aurora 2.x keygen] http://download.csdn.net/detail/studentalei/4600437

    [CTeX] http://www.ctex.org/CTeXDownload

    [algorithm宏包] https://www.ctan.org/

    【步骤】

    1、如果按照思路1安装前三个,如果按照思路2安装CTeX。

      找了一个例子[1],在winedt新建文档,粘贴编码保存,选择XeLaTex运行(首次使用出现了‘algorithm.sty’ not found的问题)

    2、所以要给MikTex安装对应宏包(package),利用Miktex Package Manager(在工具栏Tex里面有)找到algorithm自动安装出现一直连不上服务器的问题“The remote package redository is not online.”,后根据知乎[2]改用从本地文件夹安装还是根据博客[3]更换镜像都出现了问题:包括“本地地址does not seem to be a local package repository”、“Windows API error 87: 鍙傛暟閿欒�銆?” 【由于最后失败就不详细说明了,可能只是我个人问题,想试试该方法的自行打开文末网址[2][3]】

    3、按照【下载】里的地址找到algorithm宏包下载到本地并解压,新建一个文件夹放一下(我的是:E:Miktex_pacalgorithms)

    4、打开命令提示符界面(windows+R ,cmd),进入路径(E:,cd Miktex_pacalgorithms),输入”latex algorithms.ins”, 经过一段时间编译,生成algorithm.sty。(下载宏包解压后自带了pdf帮助文档,如果没有就再输入”latex algorithms.dtx”生成)

    5、将生成的algorithm.sty文件放到LaTeX能够识别的路径下(我的是”C:CTEXMiKTeX exlatex”),新建一个文件夹algorithms,放进去。

    6、找到MikTex Options(在CTeX的工具栏Tex里面有,或者在开始找到MikTex里面的Setting(Admin)),点击general选项卡的Refresh FNDB按钮,等待~

     

    7、然后重新运行步骤1的编码,成功就会看到工具栏的pdf变成红色,点击打开pdf。(编码例子有中文的,没有显示出来,后续研究)

    参考资料:

    [1] http://blog.csdn.net/yeyang911/article/details/41758039

    [2] https://www.zhihu.com/question/26584112

    [3] http://www.nexoncn.com/read/ed4f5ad1d8d480de07e3b3a2.html

    [4] http://www.cnblogs.com/csucat/p/5142459.html

     【方便附上编码测试】

    documentclass[11pt]{article}
    usepackage{CJK}
    usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
    usepackage{algorithm}
    usepackage{algorithmicx}
    usepackage{algpseudocode}
    usepackage{amsmath}
    
    floatname{algorithm}{算法}
    
    enewcommand{algorithmicrequire}{	extbf{输入:}}
    
    enewcommand{algorithmicensure}{	extbf{输出:}}
    
    egin{document}
    egin{CJK*}{UTF8}{gkai}
        egin{algorithm}
            caption{用归并排序求逆序数}
            egin{algorithmic}[1] %每行显示行号
                Require $Array$数组,$n$数组大小
                Ensure 逆序数
                Function {MergerSort}{$Array, left, right$}
                    State $result gets 0$
                    If {$left < right$}
                        State $middle gets (left + right) / 2$
                        State $result gets result +$ Call{MergerSort}{$Array, left, middle$}
                        State $result gets result +$ Call{MergerSort}{$Array, middle, right$}
                        State $result gets result +$ Call{Merger}{$Array,left,middle,right$}
                    EndIf
                    State Return{$result$}
                EndFunction
                State
                Function{Merger}{$Array, left, middle, right$}
                    State $igets left$
                    State $jgets middle$
                    State $kgets 0$
                    State $result gets 0$
                    While{$i<middle$ 	extbf{and} $j<right$}
                        If{$Array[i]<Array[j]$}
                            State $B[k++]gets Array[i++]$
                        Else
                            State $B[k++] gets Array[j++]$
                            State $result gets result + (middle - i)$
                        EndIf
                    EndWhile
                    While{$i<middle$}
                        State $B[k++] gets Array[i++]$
                    EndWhile
                    While{$j<right$}
                        State $B[k++] gets Array[j++]$
                    EndWhile
                    For{$i = 0 	o k-1$}
                        State $Array[left + i] gets B[i]$
                    EndFor
                    State Return{$result$}
                EndFunction
            end{algorithmic}
        end{algorithm}
    end{CJK*}
    end{document}  
  • 相关阅读:
    7、单向一对多的关联关系(1的一方有n的一方的集合属性,n的一方却没有1的一方的引用)
    6、JPA_映射单向多对一的关联关系(n的一方有1的引用,1的一方没有n的集合属性)
    解决ubuntu的screen已经处于Attached状态,无法再打开窗口
    关于.ssh出错,无法从远程git仓库拉代码
    给程序添加git commit信息
    ubuntu服务器常用命令
    uint128_t 添加 c++ 重载类型强制转换
    Visual Studio 查看宏展开
    EOS dice移到1.8版本的修改汇总
    ubuntu 添加字体
  • 原文地址:https://www.cnblogs.com/hqium/p/6439312.html
Copyright © 2020-2023  润新知