latex
19期 2012年4月30日

latex

本集介绍latex的一些基本使用技巧,如果你是个程序员,希望把自己的电子书作成pdf的话,你会对本集感兴趣的。
本期要点

install

terminal
lsb_release -a
sudo apt-get install texlive

bare bone

test.tex
\documentclass[11pt, a4paper]{book}
\begin{document}
This is the content
\end{document}
terminal
xelatex test.tex
evince test.pdf

top matter

test.tex
\title{Linux Guide for Chinese Beginners}
\author{Peter Wang}
\date{2012.4.1}
\maketitle

main content

test.tex
\chapter{name of chapter}
\section{name of section}
text go here
\subsection{name of subsection}
text go here

packages

test.tex
\usepackage[urlcolor = blue, colorlinks = true]{hyperref}
...
\url{http://google.com}
terminal
texdoc hyperref

add graphics

test.tex
\usepackage{graphicx}
...
\begin{figure}[htb]
\centering
\includegraphics{./figures/1.1.png}
\caption{Local version control diagram}
\end{figure}

change page layout

test.tex
\usepackage{fullpage}

code blocks

test.tex
{\footnotesize \begin{quote}\begin{verbatim}
#include <stdio.h>

int main()
{
    printf("hello\n");
    return 0;
}
\end{verbatim}\end{quote}}

add table of contents

test.tex
\tableofcontents\newpage

NOTE: need to run xelatex test.tex twice!!

so you need to re-run LaTeX one extra time to ensure that all ToC pagenumber
references are correctly calculated.

Chinese support

terminal
fc-list :lang=zh|grep CN
sudo apt-get install ttf-arphic-uming
test.tex
\usepackage{xeCJK}
\setCJKmainfont{AR PL UMing CN}

end result with Chinese support

test.tex
\documentclass[11pt, a4paper]{book}
\usepackage[urlcolor = blue, colorlinks = true, linkcolor = black ]{hyperref}
\usepackage{graphicx}
\usepackage{fullpage}
\usepackage{xeCJK}
\setCJKmainfont{AR PL UMing CN}
\begin{document}
\title{Linux Guide for Chinese Beginners}
\author{Peter Wang}
\date{2012.4.1}
\maketitle
\tableofcontents\newpage

\chapter{ 中文 name of chapter}
\section{name of section}
text go here 中文 中文 中文
\begin{figure}[htb]
\centering
\includegraphics{./figures/1.1.png}
\caption{Local version control diagram}
\end{figure}
\subsection{name of subsection}
text go here
{\footnotesize \begin{quote}\begin{verbatim}
#include <stdio.h>

int main()
{
    printf("hello\n");
    return 0;
}
\end{verbatim}\end{quote}}

\end{document}
10评论
lidashuang 大约 1 年前

太赞了,正需要用这个。

happypeter 6 个月前

markdown 文件到幻灯片的转换,现在的一个方案是:

  1. 先用 md 写好幻灯片内容
  2. 用 pandoc 将 md 转成 latex 文件,http://happycasts.net/episodes/20
  3. 参考 https://www.writelatex.com 将已有的 latex 文件调整为幻灯片格式
  4. 利用 https://www.writelatex.com 得到 pdf 输出。
admin 6 个月前

https://github.com/limingth/NCCL/blob/master/slides/md2pdf.sh
一个 md 到 pdf 的 slides 生成方案。

set -x
echo $1
pandoc -t beamer --slide-level 3 ../Unit-1/$1.md -o talk.tex
xelatex main.tex
cp main.pdf $1.pdf
rm main.pdf
rm *.out *.log *.nav *.toc *.vrb *.aux *.snm
northcamel 6 个月前

很棒的视频,有时候看几个小时的书籍或者资料,不如看一个10分钟的视频效果好。

andyque 4 个月前

感谢@happypeter 的视频,我根据此视频写了一篇博客

happypeter 4 个月前

@andyque 学习了