ubuntu latex的minted 安装
提示:minted包有一個(gè)bug,見文末。。
---------
簡(jiǎn)介(轉(zhuǎn)自: http://blog.houqp.me/minted-better-alternative-package-for-lstlisting/ )
------
曾幾何時(shí),我一直在使用lstlisting宏包高亮代碼,鑒于我從來就沒在Word里面享受過這樣的功能,我一直感到很滿意。直到今天我遇到了minted宏包。minted的[項(xiàng)目主頁]托管于Google Code。
使用非常的簡(jiǎn)單,例如:\begin{minted}{c}
printf("Hello World.");
\end{minted}
minted在后臺(tái)調(diào)用的是pygmentize,所以輸出的結(jié)果非常漂亮,自然也就支持多種主題。minted提供很多可配置的參數(shù),更多選項(xiàng)請(qǐng)參考[官方文檔]。
有一點(diǎn)要注意的是編譯時(shí)需要加上-shell-escape參數(shù)。
------
安裝
minted的project home: http://code.google.com/p/minted/
主要按照上面文檔的介紹安裝就可以了。。 安裝時(shí)會(huì)要求安裝 minted.sty, 這里有一個(gè)簡(jiǎn)單的方法:
http://www.cnblogs.com/longdouhzt/archive/2012/10/11/2720045.html
安裝完minted.sty 就大功告成了~~
--------
使用
查看支持的語言: $ pygmentize -L lexers
如 C, NASM
注意用小寫 如\begin{minted}{nasm}
幾個(gè)可能有用的配置:
1. 背景:
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\begin{minted}[bgcolor=bg]{php}
<?php
echo "Hello, $x";
?>
\end{minted}
2. 行號(hào)
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}
...以后再補(bǔ)充吧
---------------------------
最近用minted包發(fā)現(xiàn)一個(gè)bug:
Long listings are not splitted across pages.
即代碼太長(zhǎng),一頁放不下時(shí),minted不會(huì)自動(dòng)分頁,而是直接把超過一頁的部分截了。。囧。。
兩個(gè)可能的解決方法:
(1) 手動(dòng)分頁:
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
總結(jié)
以上是生活随笔為你收集整理的ubuntu latex的minted 安装的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP Spartacus 的 cx-p
- 下一篇: 范仁义js课程---66、队列的方法