==============> 重剑无锋,大巧不工。


Code Snippets Processing

There is a package called listings, it is a very handy package for code snippets processing, include highlighting, formatting, numbering, etc.

The commonly used settings by myself:


  language=python,  % language, c, java, etc.
  frame=shadowbox,  % border and its style
  backgroundcolor=\color[rgb]{0.9,0.9,0.9}, rulesepcolor=\color{black},
  showspaces=false, showtabs=false, tabsize=4, showstringspaces=false,
  numberstyle=\small, % numbering and its style
  basicstyle=\ttfamily, % fonts and style
  xleftmargin=1.2cm, xrightmargin=0.5cm,
  upquote=true,    % quote style, for ' and "
  breaklines=true, % automatically break long lines
  %% stepnumber=1,
  %% numbersep=10pt,
  %% prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
  %% breakatwhitespace=false,
  %% aboveskip={1.5\baselineskip},
  %% columns=fixed,
  %% extendedchars=true,

A code snippet example:

>>> import django
>>> print django.get_version()

Network resource for listings:


Remove Border of ToC/Links/Footnotes

There is a discussion here.

The root cause is that the style is the default style of package hyperref, I really don't know why hyperref uses such an ugly style as its default style…

Many solutions are mentioned in above link, I prefer this one:


This can not only remove the ugly border, but also customize the link color.

Make A Title Multi Lines

Use a line break operator(double backslash) can achieve this:

\title{First line of title \\
Second line of title}\maketitle


Error of Package hyperref With XeLaTeX

When compiling with xelatex, an error occurs:

mktexmf: empty or non-existent rootfile! kpathsea: Running mktexmf
The command name is D:\TexLive\bin\win32\mktexmf
Cannot find

But it's strange that the error does not affect output, the pdf file is created normally!

However, the error is annoying, after searching the web, find a solution here:

This page is in Korean, but it does not affect too much, from the first reply, I find the solution:

tlmgr install zapfding

So, after package zapfding installed, the error is gone.

Another useful link:

Error of Package xunicode

The error is as following:

! I can't find file `t3enc.def'.

This is because xunicode requires package tipa (t3enc.def is a file of tipa).

So, install the missing package will solve the issue:

tlmgr install tipa


Use Different Font For Different Language

XeLaTeX allows usage of system fonts, the following code snippet can make ASCII characters use font Segoe UI, monospace font is Consolas, but Chinese characters will use font Microsoft YaHei:


\setmainfont[ItalicFont={* Italic},BoldFont={* Bold},BoldItalicFont={* Bold Italic}]{Segoe UI}
\setmonofont[ItalicFont={* Italic},BoldFont={* Bold},BoldItalicFont={* Bold Italic}]{Consolas}
\setCJKmainfont{Microsoft YaHei}


Error with Code Snippets in Beamer

A typical beamer frame may looks like this:

\frametitle{CreateThread Function}

Code Snippet 1

Code Snippet 2


No matter using listings package or begin{verbatim} to format the code, there will always be error:

Paragraph ended before \@xverbatim was complete \end{frame}  %% generated by \begin{verbatim} command
Paragraph ended before \lst@next was complete \end{frame}    %% generated by listings package

Add an optional parameter to begin{frame} will fix this issue: