1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
|
% !TeX root = ../install-latex-guide-zh-cn.tex
\chapter{Ubuntu 20.04 系统}
\section{安装 \TeX{} Live}
这里只阐述如何用镜像安装.
为使用户顺利使用 \TeX{} Live 2022,
建议用户首先卸载从源内安装的 \TeX{} Live 的相关包,
具体方法见 \ref{sec:ubuntu:uninstall}~节.
下载
\href{https://mirrors.ctan.org/systems/texlive/Images/texlive2022.iso}{iso 镜像文件}
的方法见 \ref{sec:windows:install}~节.
下载完毕后, 打开 \textsf{Terminal} 窗口验证 MD5 值,
即执行以下命令
\begin{lstlisting}[language = bash]
cd ~/Downloads
md5sum texlive2022.iso
\end{lstlisting}
若显示
\begin{lstlisting}
adadcf7ea5224f174ec2abcea6923a42 texlive2022.iso
\end{lstlisting}
则镜像文件下载正确.
同样可验证 SHA512 值,
执行
\begin{lstlisting}[language = bash]
cd ~/Downloads
sha512sum texlive2022.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}]
b3d4d2e9b0e3d34a7ca0763fb5c669bb9a26518f86af5cc292c56f7d61ff25dc5fce3373f814d970d99b0d40df393ad594336cf1b35a95a9655289666d964d59 texlive2022.iso
\end{lstlisting}
将下载的光盘镜像进行装载
\begin{lstlisting}[language = bash]
sudo mkdir /mnt/texlive
sudo mount ./texlive2022.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 <=======
= help> https://tug.org/texlive/doc/install-tl.html <=======
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: 7262 MB (free: 239411 MB)
<D> set directories:
TEXDIR (the main TeX directory):
/usr/local/texlive/2022
TEXMFLOCAL (directory for site-wide local files):
/usr/local/texlive/texmf-local
TEXMFSYSVAR (directory for variable and automatically generated data):
/usr/local/texlive/2022/texmf-var
TEXMFSYSCONFIG (directory for local config):
/usr/local/texlive/2022/texmf-config
TEXMFVAR (personal directory for variable and automatically generated data):
~/.texlive2022/texmf-var
TEXMFCONFIG (personal directory for local config):
~/.texlive2022/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
<Q> quit
Enter command:
\end{lstlisting}
点击键盘 \keys{I} 进行默认安装.
如果用户对于 Ubuntu 系统比较了解,
可以根据提示,
更改安装设置,
如安装路径等.
为简化起见,
以下内容我们均认为用户采用默认安装.
安装完毕后, 将装载的光盘镜像弹出并删除文件夹
\begin{lstlisting}[language = bash]
sudo umount /mnt/texlive
sudo rm -r /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/2022/bin/x86_64-linux:$PATH
export MANPATH=/usr/local/texlive/2022/texmf-dist/doc/man:$MANPATH
export INFOPATH=/usr/local/texlive/2022/texmf-dist/doc/info:$INFOPATH
\end{lstlisting}
并保存退出.
这时再打开 \textsf{Terminal} 执行
\begin{lstlisting}[language=bash]
tex -v
\end{lstlisting}
若显示
\begin{lstlisting}
TeX 3.141592653 (TeX Live 2022)
kpathsea version 6.3.4
Copyright 2022 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/2022/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/2022/
\end{lstlisting}
在各处替换.
\subsection{在用户文件夹安装}\label{subsec:ubuntu-user-folder}
如果有用户打算在用户文件夹安装 \TeX{} Live,
那么可以不必调用权限,
直接执行
\begin{lstlisting}[language=bash]
/mnt/texlive/install-tl
\end{lstlisting}
只不过这时安装路径需要选择
\begin{lstlisting}[language=bash]
~/texlive/2022
\end{lstlisting}
安装完毕后,
继续修改环境变量为
\begin{lstlisting}
# Add TeX Live to the PATH, MANPATH, INFOPATH
export PATH=~/texlive/2022/bin/x86_64-linux:$PATH
export MANPATH=~/texlive/2022/texmf-dist/doc/man:$MANPATH
export INFOPATH=~/texlive/2022/texmf-dist/doc/info:$INFOPATH
\end{lstlisting}
有关字体的处理变为
\begin{lstlisting}[language=bash]
cp ~/texlive/2022/texmf-var/fonts/conf/texlive-fontconfig.conf ~/.fonts.conf/09-texlive.conf
\end{lstlisting}
然后执行
\begin{lstlisting}[language=bash]
fc-cache -fv
\end{lstlisting}
实际上,
无论将 \TeX{} Live 安装到哪里,
字体的配置文件都可以仿照上面只复制于用户文件夹中.
\subsection{\texttt{fc-cache} 无法执行}\label{subsec:fc-cache}
这种情况往往是缺少了 fontconfig,
用户可以在命令行中执行以下命令安装
\begin{lstlisting}[language=bash]
sudo apt install fontconfig
\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 update && sudo apt upgrade
\end{lstlisting}
换源并更新.
若更改错误,
可执行
\begin{lstlisting}[language=bash]
sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
\end{lstlisting}
恢复文件.
\section{卸载 \TeX{} Live}\label{sec:ubuntu:uninstall}
下面提供几种卸载方法,
卸载后需注意清理环境变量.
\subsection{卸载源内的版本}
如果要卸载从源内安装的 \TeX{} Live, 个人比较推荐使用 synaptic package manager.
在 \textsf{Terminal} 中执行
\begin{lstlisting}[language = bash]
sudo apt 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 remove --purge <package name>
\end{lstlisting}
的命令删除各个包.
删除时系统会提示使用
\begin{lstlisting}[language = bash]
sudo apt autoremove <package name>
\end{lstlisting}
来删除相应的依赖包.
\subsection{手动卸载}
如果是从光盘镜像安装,
直接删除文件夹即可.
先在\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/2022
rm -rf ~/.texlive2022
\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/2022/bin/x86_64-linux:$PATH
export MANPATH=/usr/local/texlive/2022/texmf-dist/doc/man:$MANPATH
export INFOPATH=/usr/local/texlive/2022/texmf-dist/doc/info:$INFOPATH
\end{lstlisting}
并保存退出.
同时在 \textsf{Terminal} 中执行
\begin{lstlisting}[language = bash]
sudo visudo
\end{lstlisting}
在 \texttt{secure\_path} 中删除
\begin{lstlisting}
/usr/local/texlive/2022/bin/x86_64-linux:
\end{lstlisting}
\subsection{使用 \texttt{tlmgr} 工具}
同样,
用户也可以使用 \texttt{tlmgr} 工具卸载%
\footnote{\texttt{sudo tlmgr} 无法使用的情况可以参考 \ref{sec:ubuntu:update}~节 解决},
\begin{lstlisting}[language=bash]
sudo tlmgr remove --all
\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/2022/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}
即安装了 \texttt{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}
\begin{lstlisting}[language=bash]
texdoc install-latex-guide-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,fontset=fandol]{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 install libfontconfig1
\end{lstlisting}
进行安装.
|