diff options
Diffstat (limited to 'info/install-latex/chapter/ubuntu.tex')
-rw-r--r-- | info/install-latex/chapter/ubuntu.tex | 368 |
1 files changed, 368 insertions, 0 deletions
diff --git a/info/install-latex/chapter/ubuntu.tex b/info/install-latex/chapter/ubuntu.tex new file mode 100644 index 0000000000..eea15220a5 --- /dev/null +++ b/info/install-latex/chapter/ubuntu.tex @@ -0,0 +1,368 @@ +% !TeX root = ../main.tex + +\chapter{Ubuntu 20.04 系统} + +\section{安装 \TeX{} Live} + +这里只阐述如何用镜像安装. +为使用户顺利使用 \TeX{} Live 2020, +建议用户首先卸载从源内安装的 \TeX{} Live 的相关包, +具体方法见 \ref{sec:ubuntu:uninstall}~节. + +下载 +\href{https://mirrors.ctan.org/systems/texlive/Images/texlive2020.iso}{iso 镜像文件} +的方法见 \ref{sec:windows:install}~节. +下载完毕后, 打开 \textsf{Terminal} 窗口验证 MD5 值, +即执行以下命令 +\begin{lstlisting}[language = bash] + cd ~/Downloads + md5sum texlive2020.iso +\end{lstlisting} +若显示 +\begin{lstlisting} + a31c500c7830d901363c5fa0e65cc18d texlive2020.iso +\end{lstlisting} +则镜像文件下载正确. +同样可验证 SHA512 值, +执行 +\begin{lstlisting}[language = bash] + cd ~/Downloads + sha512sum texlive2020.iso +\end{lstlisting} +正确的返回结果为 +\begin{lstlisting}[language=bash,literate={a}{a}{1} {b}{b}{1} {c}{c}{1} {d}{d}{1} {e}{e}{1} {f}{f}{1}] + 7c94bbcff5318e540dc0b03010896185d8985bcc2c2ac11906e831ec583fd574bf9720fce5efc29470c80bafe12f42ddaa392b96c460a27eda94f93c12e7b57d texlive2020.iso +\end{lstlisting} + +将下载的光盘镜像进行挂载 +\begin{lstlisting}[language = bash] + sudo mkdir /mnt/texlive + sudo mount ./texlive2020.iso /mnt/texlive +\end{lstlisting} +接下来执行 +\begin{lstlisting}[language = bash] + sudo /mnt/texlive/install-tl +\end{lstlisting} +进行安装. +在屏幕上应该能见到以下内容 +\begin{lstlisting} + ======================> TeX Live installation procedure <===================== + + ======> Letters/digits in <angle brackets> indicate <======= + ======> menu items for actions or customizations <======= + + Detected platform: GNU/Linux on x86_64 + + <B> set binary platforms: 1 out of 6 + + <S> set installation scheme: scheme-full + + <C> set installation collections: + 40 collections out of 41, disk space required: 6516 MB + + <D> set directories: + TEXDIR (the main TeX directory): + /usr/local/texlive/2020 + TEXMFLOCAL (directory for site-wide local files): + /usr/local/texlive/texmf-local + TEXMFSYSVAR (directory for variable and automatically generated data): + /usr/local/texlive/2020/texmf-var + TEXMFSYSCONFIG (directory for local config): + /usr/local/texlive/2020/texmf-config + TEXMFVAR (personal directory for variable and automatically generated data): + ~/.texlive2020/texmf-var + TEXMFCONFIG (personal directory for local config): + ~/.texlive2020/texmf-config + TEXMFHOME (directory for user-specific files): + ~/texmf + + <O> options: + [ ] use letter size instead of A4 by default + [X] allow execution of restricted list of programs via \write18 + [X] create all format files + [X] install macro/font doc tree + [X] install macro/font source tree + [ ] create symlinks to standard directories + [X] after install, set CTAN as source for package updates + + <V> set up for portable installation + + Actions: + <I> start installation to hard disk + <P> save installation profile to 'texlive.profile' and exit + <H> help + <Q> quit + + Enter command: +\end{lstlisting} +点击键盘 \keys{I} 进行默认安装. +如果用户对于 Ubuntu 系统比较了解, +可以根据提示, +更改安装设置, +如安装路径等. +为简化起见, +以下内容我们均认为用户采用默认安装. +安装完毕后, 将挂载的光盘镜像弹出并删除文件夹 +\begin{lstlisting}[language = bash] + sudo umount /mnt/texlive + sudo rm /mnt/texlive +\end{lstlisting} + +安装完成后, 用户需要设置环境变量. +继续在 \textsf{Terminal} 中执行 +\begin{lstlisting}[language = bash] + gedit ~/.bashrc +\end{lstlisting} +在打开的文件末尾添加 +\begin{lstlisting} + # Add TeX Live to the PATH, MANPATH, INFOPATH + export PATH=/usr/local/texlive/2020/bin/x86_64-linux:$PATH + export MANPATH=/usr/local/texlive/2020/texmf-dist/doc/man:$MANPATH + export INFOPATH=/usr/local/texlive/2020/texmf-dist/doc/info:$INFOPATH +\end{lstlisting} +并保存退出. +这时再打开 \textsf{Terminal} 执行 +\begin{lstlisting}[language=bash] + tex -v +\end{lstlisting} +若显示 +\begin{lstlisting} + TeX 3.14159265 (TeX Live 2020) + kpathsea version 6.3.2 + Copyright 2020 D.E. Knuth. + There is NO warranty. Redistribution of this software is + covered by the terms of both the TeX copyright and + the Lesser GNU General Public License. + For more information about these matters, see the file + named COPYING and the TeX source. + Primary author of TeX: D.E. Knuth. +\end{lstlisting} +即为安装成功. + +接下来处理字体. +在 \textsf{Terminal} 中执行 +\begin{lstlisting}[language=bash] + sudo cp /usr/local/texlive/2020/texmf-var/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf +\end{lstlisting} +将配置文件复制到系统, +然后继续执行 +\begin{lstlisting}[language=bash] + sudo fc-cache -fsv +\end{lstlisting} +刷新字体缓存. +这样一来, \TeX{} Live 中的字体才能够被正确调用. +更多内容请参考 \href{https://www.tug.org/texlive/doc/texlive-zh-cn/texlive-zh-cn.pdf}{texlive-zh-cn}. + +如果用户更改了安装路径, +要注意将 +\begin{lstlisting} + /usr/local/texlive/2020/ +\end{lstlisting} +在各处替换. + +\section{卸载 \TeX{} Live}\label{sec:ubuntu:uninstall} + +如果要卸载从源内安装的 \TeX{} Live, 个人比较推荐使用 synaptic package manager. +\textsf{terminal} 中执行 +\begin{lstlisting}[language = bash] + sudo apt-get install synaptic +\end{lstlisting} +即可安装. +安装后打开, 搜索 \textsf{texlive} 即可看到与之相关的包, 右键标记以删除即可. +当然, 用户也可以直接使用 +\begin{lstlisting}[language = bash] + dpkg -l | grep 'TeX Live' +\end{lstlisting} +找到相应的包名 \texttt{<package name>}, 之后使用类似 +\begin{lstlisting}[language = bash] + sudo apt-get remove --purge <package name> +\end{lstlisting} +的命令删除各个包. +删除时系统会提示使用 +\begin{lstlisting}[language = bash] + sudo apt-get autoremove <package name> +\end{lstlisting} +来删除相应的依赖包. + +如果是从光盘镜像安装, +直接删除文件夹即可. +先在\textsf{terminal} 中执行 +\begin{lstlisting}[language = bash] + kpsewhich -var-value TEXMFROOT +\end{lstlisting} +来查询安装路径, +进而通过 \texttt{sudo rm -rf} 命令进行删除. +默认安装的用户直接运行 +\begin{lstlisting}[language = bash] + sudo rm -rf /usr/local/texlive/2020 + rm -rf ~/.texlive2020 +\end{lstlisting} +当然删除后还要清理掉环境变量. + +\section{跨版本升级 \TeX{} Live}\label{sec:ubuntu:version} + +在 \href{https://www.tug.org/texlive/upgrade.html}{tug.org} +网站上提供了相应的方法. +但网站也声明: +默认情况下, +请通过执行新安装来获取新版本的 \TeX{} Live% +\footnote{原文是: By default, +please get the new TL by doing a new installation instead of proceeding here}. + +\section{升级宏包}\label{sec:ubuntu:update} + +首次升级前, +在 \textsf{terminal} 中执行 +\begin{lstlisting}[language = bash] + sudo visudo +\end{lstlisting} +将 +\begin{lstlisting} + /usr/local/texlive/2020/bin/x86_64-linux: +\end{lstlisting} +添加在 \texttt{secure\_path} 中% +\footnote{这里只讨论默认安装的情况}. +然后依次 \keys{\ctrl + X}, \keys{Y}, \keys{\enter} 保存退出. + +接下来在 \textsf{terminal} 中执行 +\begin{lstlisting}[language = bash] + sudo tlmgr option repository ctan +\end{lstlisting} +让系统自动选择源, +同样可以使用大陆地区的源升级, +详情见附录~\ref{chp:appendix:mirror}. +执行命令 +\begin{lstlisting}[language = bash] + sudo tlmgr update --list +\end{lstlisting} +可查看目前源上可升级的宏包都有哪些. +高级用户可以根据自己的需求选择升级特定宏包. +建议初级用户执行 +\begin{lstlisting}[language = bash] + sudo tlmgr update --self --all +\end{lstlisting} +同时升级 \texttt{tlmgr} 本身和全部宏包. + +\section{安装宏包}\label{sec:ubuntu:installpackage} + +Ubuntu 20.04 下安装宏包的要求与 Windows 10 下没有多少区别, 只需注意权限, 例如 +\begin{lstlisting}[language = bash] + sudo tlmgr install mcmthesis +\end{lstlisting} +即安装了 mcmthesis. + +\section{调出宏包手册}\label{sec:ubuntu:texdoc} + +与 Windows 10 类似, +当正确安装后, +用户可以调出宏包手册以查阅相应内容. +例如在 \textsf{terminal} 中执行 +\begin{lstlisting}[language=bash] + texdoc texlive-zh-cn +\end{lstlisting} +或 +\begin{lstlisting}[language=bash] + texdoc lshort-zh-cn +\end{lstlisting} +就可分别调出 \texttt{texlive-zh-cn.pdf} 和 \texttt{lshort-zh-cn.pdf}. + +\section{编译文件} + +首先, 用户需要在工作路径建立一个 \texttt{tex} 文件. +在 \textsf{Terminal} 中执行 +\begin{lstlisting}[language = bash] + mkdir ~/Documents/work-latex + cd ~/Documents/work-latex/ + gedit main.tex +\end{lstlisting} +在打开的文件输入一个最小示例 +\begin{lstlisting}[language = {[LaTeX]TeX}] + \documentclass{article} + \begin{document} + Hello \LaTeX{} World! + \end{document} +\end{lstlisting} +保存并退出. +接下来执行 +\begin{lstlisting} + pdflatex main +\end{lstlisting} +等待系统完成编译过程. +待编译完成后, +我们即可看到在 \texttt{\~{}/Documents/work-latex} 中出现了 +\texttt{main.pdf} 文件和其他同名的辅助文件 \texttt{main.aux} 与 +\texttt{main.log}. +执行 +\begin{lstlisting}[language=bash] + evince main.pdf +\end{lstlisting} +即可打开 \texttt{pdf} 文件. + +对于中文文档, 可以在 \texttt{gedit} 中编写以下最小示例% +\footnote{gedit 默认使用 UTF-8 编码}% +\begin{lstlisting}[language={[LaTeX]TeX}] + \documentclass[UTF8]{ctexart} + \begin{document} + 你好 \LaTeX{} 世界! + \end{document} +\end{lstlisting} +保存并退出. +接下来执行 +\begin{lstlisting}[language=bash] + xelatex main +\end{lstlisting} +等待系统完成编译过程. +\texttt{xelatex} 可以使用系统内安装的字体, +安装字体的方法可参考附录~\ref{chp:appendix:wsl}. + +编译命令可添加参数, 这里与 \ref{sec:windows:compile}~节中的情形一致. + +\subsection{无法使用 \texttt{xelatex} 命令}\label{subsec:ubuntu:xelatexfail} + +有些用户反映安装完毕后无法使用 \texttt{xelatex} 命令. +这或许是因为缺失 libfontconfig , 用户可在命令行中执行 +\begin{lstlisting}[language=bash] + sudo apt-get install libfontconfig1 +\end{lstlisting} +进行安装. + +为提升安装速度, 可考虑更换 Ubuntu 源, 例如更换至清华大学. +在 \textsf{Terminal} 中执行 +\begin{lstlisting}[language = bash] + sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak +\end{lstlisting} +备份 \texttt{sources.list} 文件. +接下来执行 +\begin{lstlisting}[language = bash] + sudo gedit /etc/apt/sources.list +\end{lstlisting} +将文件替换为以下内容% +\footnote{本段文字可至% + \href{https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/}{清华大学镜像网站}% + 获取} +\begin{lstlisting} + # 默认注释了源码镜像以提高 apt update 速度, 如有需要可自行取消注释 + deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse + # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse + deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse + # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse + deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse + # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse + deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse + # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse + + # 预发布软件源, 不建议启用 + # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse + # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse +\end{lstlisting} +然后执行 +\begin{lstlisting}[language = bash] + sudo apt-get update && sudo apt-get upgrade +\end{lstlisting} +换源并更新. +若更改错误, +可执行 +\begin{lstlisting}[language=bash] + sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list +\end{lstlisting} +恢复文件. |