2017年3月12日星期日

Ubuntu 安装 LaTeX 环境

1. 准备工作



  • 下载 Texlive2015.iso 镜像,Texlive2015
  • 删除以前的版本(若之前没有安装过,可忽略此项)
$ sudo apt-get purge tex-common

2. 安装

  • 挂载镜像文件:右击texlive2015.iso文件,选择打开方式为“磁盘映像挂载器”,打开后左侧设备目录下出现“TeXLive2015”,将鼠标放在其上会出现/media/username/TeXLive2015
  • 进入挂载点目录
$ cd /media/username/TeXLive2015
  • 运行安装程序
$ sudo install-tl
  • 输入I即开始安装。

3. 配置环境变量

  • 安装完成后查看是否有该文件
$ ls /usr/local/texlive/2015/bin/x86_64-linux/xelatex
  • 在/etc/profile文件中添加几行文本
$ sudo gedit /etc/profile
  • 在文件末尾添加如下三行文本:
    export MANPATH=/usr/local/texlive/2015/texmf-dist/doc/man:$MANPATH
    export INFOPATH=/usr/local/texlive/2015/texmf-dist/doc/info:$INFOPATH
    export PATH=/usr/local/texlive/2015/bin/x86_64-linux:$PATH
  • 输入如下代码,使得环境变量生效
$ source \etc\profile
  • 测试
$ xelatex --version
XeTeX 3.14159265-2.6-0.99992 (TeX Live 2015)

4. 安装Windows字体

  • 从Windwos系统中复制仿宋(simfang.ttf),黑体(simhei.ttf),楷体(simkai.ttf),隶书(simli.ttf),幼圆(simyou.ttf),并将其放入/usr/share/fonts/WinFonts/目录下。(Note:Windows 7系统中没有宋体(simsun.ttf),注意后缀为.ttf,可从网上下载 simsong.ttf)
$ sudo mkdir /usr/share/fonts/WinFonts/
    # 将前述6个字体复制到该文件下
$ cd /usr/share/fonts/WinFonts/    $ sudo chmod 777 *
$ sudo mkfontscale
$ sudo mkfontdir
$ sudo fc-cache-fsv
$ fc-list:lang=zh-cn #检查结果中是否有前述6个中文字体
  • 配置xelatex 的字体配置文件
  • 为了在整个系统中使用 TeX Live 的字体,将配置文件 texlive-fontconfig.conf 复制到 /etc/fonts/conf.d/ 目录下,并命名为 09-texlive.conf
$ sudo cp /usr/local/texlive/2015/texmf-var/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-textlive.conf
$ sudo fc-cache -fsv
  • 编译一个中文PDF

5. 新建一个tex文档 main.tex


      \documentclass[10pt,UTF8]{ctexbook}
    %\usepackage{latexsym}
    \usepackage{amsmath}
    \usepackage{amssymb}
   
    \usepackage{graphics}
    \usepackage{epsfig}
   
    \topmargin=0pt\oddsidemargin=0pt\evensidemargin=0pt
    \textwidth=16.5cm\textheight=23cm\raggedbottom
   
    \newtheorem{thh}{Theorem}
    \newtheorem{dff}{Definition}
    \newtheorem{pr}{Proposition}
    \newtheorem{lm}{Lemma}
    \newtheorem{cl}{Collary}
    %\mathindent=1.5cm
    \begin{document}
   
    \date{}
    \title{  {\bf\large{标题}}
    \footnote {\footnotesize 脚注}}
    \author{作者\\({\footnotesize 作者单位})
    \\{\footnotesize e-mail:邮箱} }
    \maketitle
   
        \chapter{第一章}
   
    \section{第一节}
   
    这是一个中文书 document class。
   
    \end{document}

cd 到main.tex文件所在目录下,用xelatex生成PDF

    $ xelatex main.tex

OK,安装完毕。

6. 参考文档



LaTeX的学习之路上布满大坑小坑,大家且填且珍惜!

没有评论:

发表评论