Ubuntu 18.04 搭建 Latex 编译环境

需要大量书写数学公式,对 Latex 的需求倍增。所以考虑在 Ubuntu 18.04 安装 Latex。

查看有哪些 Latex

可以使用 sudo apt search latex,这样我们可以获得大量的和 Latex 相关的安装包。

sudo apt search latex

常见的 latex 的包如下:

  • texlive-base - 136 MB
  • texlive-latex-recommended - 177 MB
  • texlive - 240 MB
  • texlive-latex-extra - 404 MB
  • texlive-full - 4714 MB

可以选择 texlive-full。但是我选择了最小的,这样功能虽然少点,但是节约空间。

升级系统

每次安装新软件包前记得升级系统。

sudo apt update
sudo apt upgrade

安装 texlive-base

sudo apt install texlive-latex-base

这样我们就可以完成安装。

安装 texlive-extra

再安装常用的附加功能。

sudo apt install texlive-latex-extra

这样最基础的 latex 功能就已经有了。

验证 Latex 安装

输入 latex -v,能获得输出说明安装成功。我机器上输入如下图。

latex -v
pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian)
kpathsea version 6.2.3
Copyright 2017 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.34; using libpng 1.6.34
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with poppler version 0.62.0

这说明我们可以使用 Latex 了。

第一个 Latex 脚本

自然又是 hello.tex。可以使用 vi 来完成,内容如下。

\documentclass{article}
\usepackage{hyperref}
\begin{document}

Hello world \LaTeX

\url{https://linuxconfig.org}

\end{document}

编译脚本

我们可以使用 pdflatex 这个命令来编译 latex 脚本。

pdflatex hello.tex

这样我们就可以在当前目录上看到 hello.pdf。pdf 的内容如下图:

中文支持

写 Latex 中常需要中文支持,我们需要安装中文包。

安装包

搜索 CJK 包

sudo apt search cjk

安装 CJK 包

sudo apt install latex-cjk-all

安装 xelatex

sudo apt install texlive-xetex

这样我们就可以使用 CJK 中文了。

中文样例

% !TeX program = xelatex
\documentclass{article}
\usepackage{xeCJK}
\usepackage{hyperref}
\begin{document}

Hello world \LaTeX

\url{https://linuxconfig.org}

你好,成功了
\end{document}

注意上面增加了两个部分:

1、指定使用 xelatex;

2、使用 xeCJK 包。

编译

由于制定了 xelatex,我们需要使用 xelatex 来编译中文。下面是我的机器编译的过程。

$ xelatex hello.tex
This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017/Debian) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./hello.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 26 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def))
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty)
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/tuenc.def))
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xunicode-addon.sty
(/usr/share/texlive/texmf-dist/tex/xelatex/xunicode/xunicode.sty
(/usr/share/texmf/tex/latex/tipa/t3enc.def)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/xetex.def)))))
(/usr/share/texlive/texmf-dist/tex/xelatex/xunicode/xunicode.sty
*** Reloading Xunicode for encoding 'TU' ***
) (/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xunicode-extra.def)
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.cfg))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hxetex.def
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/stringenc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))
*************************************************
* xeCJK warning: "fandol"
*
* Fandol is being set as the default font for CJK text.
* Please make sure it has been properly installed.
*************************************************
*************************************************
* fontspec warning: "script-not-exist"
*
* Font 'FandolSong-Regular' does not contain script 'CJK'.
*************************************************
(./hello.aux) (/usr/share/texmf/tex/latex/tipa/t3cmr.fd)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./hello.out) (./hello.out)
*************************************************
* fontspec warning: "script-not-exist"
*
* Font 'FandolFang-Regular' does not contain script 'CJK'.
*************************************************
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/se-ascii-print.def)
[1] (./hello.aux) )
Output written on hello.pdf (1 page).
Transcript written on hello.log.

这样就可以生成 hello.pdf。文件的内容如下图。

这样,我们一个最最基础的 Latex 环境就完成了。这个简单的功能,搞了好几天,主要还是对 Latex 不熟悉,自己也在学习中。其次就是网络上大部分的分享都不对,至少没有解决我碰到的问题。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力的老周

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值