2009年3月20日星期五

listings宏包的设置

经过一个上午的尝试,我采用如下的方法来定义listings宏包,可得到一个格式优美的源程序PDF渲染效果。


在导言区的命令是

\usepackage{xcolor} % 颜色增强
\definecolor{lightgrey}{HTML}{D0CFCF}% 亮灰色
\definecolor{lightblue}{HTML}{D5EDF1}% 亮蓝色
\definecolor{greyblue}{HTML}{0A499B}% 灰蓝色
\definecolor{greygreen}{HTML}{19400B}% 灰绿色
\usepackage{listings}
\lstset{basewidth={0.5em,0.35em},basicstyle=\small,keywordstyle=\color{greyblue}, commentstyle=\color{greygreen}, frame=shadowbox, rulesepcolor=\color{lightgrey},numbers=left, numberstyle=\tiny,breaklines=true,framesep=5pt,rulesep=5pt,framexleftmargin=5mm}%
\lstnewenvironment{tex}{\lstset{language={[LaTeX]TeX}}}{}%TeX 代码
\lstnewenvironment{cpp}{\lstset{language={[ISO]C++},mathescape,escapechar='}}{}%C++ 代码
\lstnewenvironment{matlab}{\lstset{language={MatLab},mathescape,escapechar='}}{}%MatLab 代码
\lstnewenvironment{html}{\lstset{language={HTML},escapechar='}}{}%HTML
\lstnewenvironment{makefile}{\lstset{language={[gnu]make},escapechar='}}{}%Gnu Make
\lstnewenvironment{python}{\lstset{language={python},escapechar='}}{}%Python
\lstnewenvironment{vbscript}{\lstset{language={VBScript},escapechar='}}{}% VBScript


在主体部分的样例为

\begin{cpp}
#include
using namespace std;
int main(void)
{
// '\textit{创建一个简单的程序}'
std::cout << "hello" << endl; // sample code $\alpha$
return 0;
}
\end{cpp}


如果需要文本环绕的话,则可采用 wrapfigure 宏包,代码如下:

\begin{wrapfigure}{L}{0.5\textwidth}
\begin{cpp}
#include
using namespace std;
int main(void)
{
// '\textit{创建一个简单的程序}'
std::cout << "hello" << endl; // sample code $\alpha$
return 0;
}
\end{cpp}
\end{wrapfigure}


令人遗憾的是,我尚不能写一个通用的环境,其能将 latex 代码的渲染效果与 latex 源代码 并行显示

2009年3月18日星期三

升级到 Python 3.1 的兼容问题

Python 3.1 已经发布了。兴冲冲地将陪伴了我多年的 2.X 版本卸载了,安装上 Python 3.1。结果一些旧 Py 脚本无法正常运行。其原因是 Python 3.1 并不与 2.X 相兼容。看来在日新月异的今天,保持“兼容性”与追求“创新性”间的矛盾越来越大了。理解理解,不妨将旧程序的移植作为学习的动力
IBM DevelopWorks 中国网站上有一组介绍 Python 3 的入门文章,由此进入