程序员的 LaTeX 基础教程指引

转载

http://blog.zhenian.com/2011/08/04/basic_latex_tutorial_for_programmer/

零,唠叨:

我坚信,知识分享和经验分享能使人们生活更加美好。

在软件工程这个行业里,每天不断有新的知识产生,也在不断施行着工程实践。每天不断学习之成为许多软件工程师的共识。学习的同时也在分享着知识和经验。我接触到的主要分享有以下几种:

1,Blog:当下,最主流的分享方式是通过博客来进行。每天产生不讲其数的博文。

2,问题解答:包括Mail-list,问答社区,BBS 都是属于这个类型

3,演讲:一些技术沙龙,技术讲座,会定期组织专业者进行分享。除了与会者之外,其它人在网络上可以通过 幻灯,录音,录像重温。

4,出版或发布E-book

故而,想通过第4种方式分享你的知识或者经验的朋友,都应该去学习是LaTeX。

 

一,小介:

LaTex 是一种排版系统,它非常适用于生成高印刷质量的科技和数学类文档,同样适用于生成从简单的信件到完整的书籍的所有其它各类的文档,是使用TEX作为它的格式化引擎。

TEX 是由 Donald E. Knuth 编写的用于文章和数学公式排版的计算机程序。至于 Donald E. Knuth (中文名:高纳德) 是谁,我想作为了软件工程师中一员的你,是用不着我介绍的了。下面进入正题:

 

二,基于 Windows的LaTex环境:

使用集成环境 CTEX,可于 http://www.ctex.org/CTeXDownload 下载完整安装包,基本包括了所有的排版使用的宏,以及编辑器 WinEdt,以及 Ghostcript,Ghostgum等等工具。

 

三,主要参考文档:

参考位于 ${CTEX_ROOT}\CTeX\ctex\doc 下的:ch8.pdf,ctex-faq.pdf,graphics.pdf,lshort-cn.pdf,symbols.pdf 。据这几个文档,基本已经足够。

 

四,工程实践:

相关内容请从 lshort-cn.pdf 和ctex-faq.pdf开始。前者通读,后者快速过一次即可。

(以下,通过WinEdt编辑保存为tex文件,F9即可看到相应的编译排版过程,成功的话,会看到打开的PDF文档,不成功的话,也有会相应的提示说明。)

1,最基本结构:

\documentclass[10pt]{book}
\begin{document}
The first document by LaTeX.
\end{document}

 

2,添加作者标题

\documentclass[10pt]{book}
\author{gelosie.wang@gmail.com}
\title{Java Code Snippets}
\begin{document}
The first document by LaTeX.
\end{document}

 

3,添加中文支持

\documentclass[10pt]{book}
\author{gelosie.wang@gmail.com}
\title{Java Code Snippets}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{GBK}{kai}
The first document by LaTeX.
可以使用中文了
\end{CJK*}
\end{document}

 

4,章节段等文章结构

具体请参考  lshort-cn.pdf 中的叙述,主要使用\part \chapter \section \subsection 等等来定义文章结构 :

\documentclass[10pt]{book}
\author{gelosie.wang@gmail.com}
\title{Java Code Snippets}
\usepackage{CJK}
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
\begin{document}
\begin{CJK*}{GBK}{kai}
\maketitle
\tableofcontents
\part{Java语法}
\chapter{基础语法}
\section{注释}
\subsection{行注释}
本章主要出示一些最基础的Java语法相关的代码。
\end{CJK*}
\end{document}

5, 代码高亮

\documentclass[10pt]{book}
\author{gelosie.wang@gmail.com}
\title{Java Code Snippets}
\usepackage{CJK}
\usepackage[english]{babel}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
   %行号
   numbers=left,
   %背景框
   %framexleftmargin=10mm,
   %frame=none,
   %背景色
   %backgroundcolor=\color[rgb]{1,1,0.76},
   %backgroundcolor=\color[RGB]{245,245,244},
   %样式
   keywordstyle=\bf\color{blue},
   identifierstyle=\bf,
   numberstyle=\color[RGB]{0,192,192},
   commentstyle=\it\color[RGB]{0,96,96},
   stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},
   %显示空格
   showstringspaces=false
}
% THEOREMS -------------------------------------------------------
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
% ----------------------------------------------------------------
\begin{document}
\begin{CJK*}{GBK}{kai}
\maketitle
\tableofcontents
\part{Java语法}
\chapter{基础语法}
本章主要出示一些最基础的Java语法相关的代码。
\section{注释}

\begin{lstlisting}[language={Java}]
public static void main(String[] args) \{
    System.out.println("Connected to server ... sending echo string: " + args[1]);
\}
\end{lstlisting}

\end{CJK*}
\end{document}
% ----------------------------------------------------------------

6, 文件组织

可以使用 \include 指令,但不能嵌套。

所以,可以在主Tex定义相关的结构,把段落内容分到 include 中的文件来组织:

主Tex:

\documentclass[10pt]{book}
\author{gelosie.wang@gmail.com}
\title{Java Code Snippets}
\usepackage{CJK}
\usepackage[english]{babel}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
   %行号
   numbers=left,
   %背景框
   %framexleftmargin=10mm,
   %frame=none,
   %背景色
   %backgroundcolor=\color[rgb]{1,1,0.76},
   %backgroundcolor=\color[RGB]{245,245,244},
   %样式
   keywordstyle=\bf\color{blue},
   identifierstyle=\bf,
   numberstyle=\color[RGB]{0,192,192},
   commentstyle=\it\color[RGB]{0,96,96},
   stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},
   %显示空格
   showstringspaces=false
}
% THEOREMS -------------------------------------------------------
\newtheorem{thm}{Theorem}[chapter]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\theoremstyle{remark}
\newtheorem{rem}[thm]{Remark}
% ----------------------------------------------------------------
\begin{document}
\begin{CJK*}{GBK}{kai}
\maketitle
\tableofcontents
\part{Java语法}
\chapter{基础语法}
\include{chapter_one_intro}
\section{注释}
\include{some_code}
\end{CJK*}
\end{document}
% ----------------------------------------------------------------

chapter_one_intro.tex

一些介绍....................

some_code.tex

\subsection{代码样例}
\begin{lstlisting}[language={Java}]
public static void main(String[] args) \{
    System.out.println("Connected to server ... sending echo string: " + args[1]);
\}
\end{lstlisting}

 

只要掌握这些基本的点,就可以开始实践了。当遇到问题或者新需求,查阅文档或者 google 之!

 

五,一些参考资源

1,上文中所说的几个文档

2,中文TeX Wiki:http://wiki.ctex.org/index.php/%E9%A6%96%E9%A1%B5

3,ChinaTeX : http://www.chinatex.org/

4,一个 Lex 博客: http://latex.yo2.cn/

posted @ 2011-08-18 11:03  westfly  阅读(821)  评论(0编辑  收藏  举报