zoukankan      html  css  js  c++  java
  • ubuntu latex的minted 安装

    提示:minted包有一个bug,见文末。。

    ---------

     

    简介(转自: http://blog.houqp.me/minted-better-alternative-package-for-lstlisting/

    ------

    曾几何时,我一直在使用lstlisting宏包高亮代码,鉴于我从来就没在Word里面享受过这样的功能,我一直感到很满意。直到今天我遇到了minted宏包。minted的[项目主页]托管于Google Code。

    使用非常的简单,例如:
    \begin{minted}{c}
    printf("Hello World.");
    \end{minted}

    minted在后台调用的是pygmentize,所以输出的结果非常漂亮,自然也就支持多种主题。minted提供很多可配置的参数,更多选项请参考[官方文档]。

    有一点要注意的是编译时需要加上-shell-escape参数。

    ------

    安装

     minted的project home: http://code.google.com/p/minted/

    主要按照上面文档的介绍安装就可以了。。 安装时会要求安装 minted.sty, 这里有一个简单的方法:

    http://www.cnblogs.com/longdouhzt/archive/2012/10/11/2720045.html


    安装完minted.sty 就大功告成了~~

    --------

    使用

    查看支持的语言: $ pygmentize -L lexers
      如 C, NASM

    注意用小写 如\begin{minted}{nasm}

     

    几个可能有用的配置:

    1. 背景:

    \definecolor{bg}{rgb}{0.95,0.95,0.95}
    \begin{minted}[bgcolor=bg]{php}
    <?php
      echo "Hello, $x";
    ?>
    \end{minted}
    

    2. 行号

    linenos  (boolean)
    (default: false)
    Enables line numbers. In order to customize the display style of line numbers, you
    need to redefine the \theFancyVerbLine macro:

    \renewcommand{\theFancyVerbLine}{\sffamily
    \textcolor[rgb]{0.5,0.5,1.0}{\scriptsize
    \oldstylenums{\arabic{FancyVerbLine}}}}
    \begin{minted}[linenos,
    firstnumber=11]{python}
    def all(iterable):
      for i in iterable:
        if not i:
          return False
      return True
    \end{minted}
    

    ...以后再补充吧

    ---------------------------

    最近用minted包发现一个bug:

    Long listings are not splitted across pages.
    即代码太长,一页放不下时,minted不会自动分页,而是直接把超过一页的部分截了。。囧。。

    两个可能的解决方法:
    (1) 手动分页:
    http://tex.stackexchange.com/questions/51165/code-over-two-pages-and-continue-counting-lines

     1 \begin{program}[H]
     2 \begin{minted}[bgcolor=lightgray,linenos=true,fontfamily=courier,fontsize=\footnotesize,frame=single]{javascript}
     3  \\Code Part 1 : numbers going from 1..28
     4 \end{minted}
     5 \caption{Same Caption}
     6 \label{prog:samelabel}
     7 \end{program}
     8 
     9 \newpage
    10 
    11 \begin{program}[H]
    12 \ContinuedFloat
    13 \begin{minted}[bgcolor=lightgray,linenos=true,fontfamily=courier,fontsize=\footnotesize,frame=single,firstnumber=29]{javascript} 
    14  \\Code Part 2 change firstnumber value
    15 \end{minted}
    16 \caption{Same Caption}
    17 \label{prog:samelabel}
    18 \end{program}


    (2) mdframed (没试过)
    http://tex.stackexchange.com/questions/23663/minted-truncates-the-code-if-it-doesnt-fit-into-one-page

  • 相关阅读:
    丁丁又病了
    领导之所以是领导
    丁丁的进步
    最近比较烦
    批量更新数据表
    转帖:《EnterLib PIAB深入剖析》系列博文汇总
    XML DOM介绍
    转大白话系列之C#委托与事件讲解大结局
    using
    jQuery工作原理解析以及源代码示例
  • 原文地址:https://www.cnblogs.com/longdouhzt/p/2720161.html
Copyright © 2011-2022 走看看