diff options
Diffstat (limited to 'info/install-latex/chapter/wsl.tex')
-rw-r--r-- | info/install-latex/chapter/wsl.tex | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/info/install-latex/chapter/wsl.tex b/info/install-latex/chapter/wsl.tex new file mode 100644 index 0000000000..bb1c2f64a5 --- /dev/null +++ b/info/install-latex/chapter/wsl.tex @@ -0,0 +1,350 @@ +% !TeX root = ../main.tex + +\chapter{Windows Subsystem for Linux} + +目前微软推出了 Windows Subsystem for Linux (WSL) 供开发人员使用. +在这里简要介绍如何在 WSL 中安装 \TeX{} Live. +我选择的是微软商店中的 Ubuntu. +此篇安装教程仅供参考. +这里称 WSL 中使用的命令行为 \textsf{bash}. +\textbf{不建议}对操作系统了解不多的用户阅读本章内容. + +\section{安装 \TeX{} Live} + +在主系统% +\footnote{在 Windows 10 中直接进行的操作即为在主系统中的操作}% +中下载 +\href{https://mirrors.ctan.org/systems/texlive/Images/texlive2020.iso}{iso 镜像文件}, +可选择国内源以加快下载速度. +下载完毕后, 在 \textsf{cmd} 中验证文件是否正常. +下载及文件验证方法同 \ref{sec:windows:install}~节. + +在正式安装前, +用户需要在 \textsf{bash} 中执行 +\begin{lstlisting}[language=bash] + sudo apt-get install libfontconfig1 + sudo apt-get install ttf-mscorefonts-installer + sudo apt-get install fontconfig +\end{lstlisting} +这些命令是为了处理日后使用中可能出现的字体问题. +为避免安装速度过慢, +可仿照 \ref{subsec:ubuntu:xelatexfail}~节更改文件 \texttt{sources.list}. +注意 WSL 中无法启动 \textsf{gedit}, +因此需要将其替换为 \textsf{vim}, +即 +\begin{lstlisting}[language=bash] + sudo vim /etc/apt/sources.list +\end{lstlisting} +不熟悉 \textsf{vim} 的用户, +可参考 \ref{sec:no-vim}~节. + +接下来, 在主系统中将镜像挂载, +例如挂载到 \texttt{X:\textbackslash}, +而后进入 \textsf{bash} 并执行如下命令 +\begin{lstlisting}[language = bash] + sudo mkdir /mnt/x + sudo mount -t drvfs X: /mnt/x +\end{lstlisting} +如此便可在 \textsf{bash} 中找到挂载的光盘镜像. +之后执行 +\begin{lstlisting}[language = bash] + sudo /mnt/x/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} 使用默认配置安装. +如果用户对于 WSL 比较了解, 可以根据提示, 更改安装设置. +为简化起见, +以下内容均认为用户进行默认安装. +安装完毕后, 需继续在 \textsf{bash} 中执行 +\begin{lstlisting}[language = bash] + sudo umount /mnt/x + sudo rmdir /mnt/x +\end{lstlisting} +弹出已加载的光盘镜像. + +默认安装完成后, 用户需要设置环境变量. +继续在 \textsf{bash} 中执行 +\begin{lstlisting}[language = bash] + vim ~/.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{vim} 的用户可参考 \ref{sec:no-vim}~节. +退出 WSL 再进入, 执行 +\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} +即为安装成功. + +接下来仿照 Ubuntu 20.04 处理字体. +首先将配置文件复制到系统, +在 \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} +然后在 \textsf{Terminal} 执行 +\begin{lstlisting}[language=bash] + sudo fc-cache -fsv +\end{lstlisting} +刷新字体缓存. + +\section{卸载 \TeX{} Live} + +直接删除文件夹即可. +先在 \textsf{bash} 中执行 +\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} + +WSL 中的方法同 \ref{sec:ubuntu:version}~节. + +\section{升级宏包} + +WSL 中的方法同 \ref{sec:ubuntu:update}~节. + +\section{安装宏包} + +WSL 中的方法同 \ref{sec:ubuntu:installpackage}~节. + +\section{编译文件} + +编译一个最小示例 \texttt{main.tex}. + +在主系统的 \textsf{cmd} 中执行 +\begin{lstlisting}[language=bash] + mkdir D:\work-latex + cd /d D:\work-latex + notepad main.tex +\end{lstlisting} +建立文档, +内容为 +\begin{lstlisting}[language = {[LaTeX]TeX}] + \documentclass{article} + \begin{document} + Hello \LaTeX{} World! + \end{document} +\end{lstlisting} +接下来在 \textsf{cmd} 中执行 +\begin{lstlisting}[language=bash] + bash -i -c "pdflatex main" +\end{lstlisting} +实现编译. + +也可以直接在 WSL 中建立文档并编译, +在 \texttt{bash} 中依次执行 +\begin{lstlisting}[language=bash] + mkdir /mnt/d/work-latex + cd /mnt/d/work-latex + vim main.tex +\end{lstlisting} +建立文档, +内容同上, +然后在 \textsf{bash} 中执行 +\begin{lstlisting}[language=bash] + pdflatex main +\end{lstlisting} +实现编译. + +待编译完成后, 可看到在工作路径中生成了 \texttt{main.pdf} +文件和其他同名的辅助文件 \texttt{main.aux} 与 \texttt{main.log}. +在主系统中可以打开 \texttt{main.pdf} 查看内容. + +对于中文文档, +可以编写以下最小示例% +\footnote{注意使用 UTF-8 编码}% +\begin{lstlisting}[language={[LaTeX]TeX}] + \documentclass[UTF8]{ctexart} + \begin{document} + 你好 \LaTeX{} 世界! + \end{document} +\end{lstlisting} +在 \textsf{cmd} 中执行 +\begin{lstlisting}[language=bash] + bash -i -c "xelatex main" +\end{lstlisting} +或在 \textsf{bash} 中执行 +\begin{lstlisting}[language=bash] + xelatex main +\end{lstlisting} +等待系统完成编译过程. +\texttt{xelatex} 同样可以使用 WSL 内安装的字体% +\footnote{注意主系统中的字体默认不能直接被调用, +如果打算使用主系统中的字体, +见 +\href{https://github.com/OsbertWang/install-latex/issues/14}{github 上的讨论}}, +在 WSL 中安装字体的方法见附录~\ref{chp:appendix:wsl}. + +编译命令可添加参数, 这里与 \ref{sec:windows:compile}~节中的情形一致, 不再赘述. + +\section{尚未圆满解决的问题} + +将 \TeX{} Live 安装至 WSL 仍有悬而未决的问题. +由于 \textsf{bash} 默认是无窗口化的纯命令行, +因此用户无法直接通过命令 \texttt{texdoc} 打开相应的手册. +这里给出几种方法. + +\subsubsection{explorer 浏览} + +先找到手册所在路径, +例如寻找 \texttt{lshort-zh-cn} +\begin{lstlisting}[language=bash] + texdoc -l lshort-zh-cn +\end{lstlisting} +系统会显示 +\begin{lstlisting} + 1 /usr/local/texlive/2020/texmf-dist/doc/latex/lshort-chinese/lshort-zh-cn.pdf + = [zh] The document itself + Enter number of file to view, RET to view 1, anything else to skip: +\end{lstlisting} +这时按其他键 (如 \keys{x}) 退出. +然后分别执行 +\begin{lstlisting}[language=bash] + cd /usr/local/texlive/2020/texmf-dist/doc/latex/lshort-chinese/ + explorer.exe . +\end{lstlisting} +主系统的资源管理器便会打开. +这时用户便可以在主系统中使用 pdf 阅读器打开手册进行阅读. + +\subsubsection{everything 搜索} + +使用 \href{https://www.voidtools.com/zh-cn/}{everything}. +通过 \texttt{texdoc -l} 找到相应文件名, +而后直接搜索. +具体方法这里不再赘述. + +\subsubsection{借助其他工具} + +目前有很多开源的 WSL 辅助程序, +相关讨论见本手册的 \href{https://github.com/OsbertWang/install-latex/issues/13}{issue}. + +\section{不懂 \textsf{vim} 的处理方法}\label{sec:no-vim} + +\textsf{vim} 的使用方法与目前很多流行的编辑器不同, +因此这里给出不用 \textsf{vim} 的处理方法. +该方法借助 \href{https://code.visualstudio.com/}{VS Code} 的 \href{https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl}{Remote-WSL} 插件实现. + +先来更改 \texttt{.bashrc}. +将 \texttt{.bashrc} 备份为 \texttt{.bashrc.bak} +\begin{lstlisting}[language=bash] + cp ~/.bashrc ~/.bashrc.bak +\end{lstlisting} +用 VS Code 打开文档 +\begin{lstlisting}[language=bash] + code ~/.bashrc +\end{lstlisting} +并对其中内容进行更改并保存. +若更改错误, +可以执行 +\begin{lstlisting}[language=bash] + cp ~/.bashrc.bak ~/.bashrc +\end{lstlisting} +恢复文档. + +接下来更改 \texttt{sources.list}. +将 \texttt{sources.list} 备份为 \texttt{sources.list.bak} +\begin{lstlisting}[language=bash] + sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak +\end{lstlisting} +用 VS Code 打开文档 +\begin{lstlisting}[language=bash] + code /etc/apt/sources.list +\end{lstlisting} +并对其中内容进行更改, +并且另存为 +\begin{lstlisting} + ~/sources.list.sav +\end{lstlisting} +在 \textsf{bash} 中执行 +\begin{lstlisting}[language=bash] + sudo cp ~/sources.list.sav /etc/apt/sources.list +\end{lstlisting} +替换文档. +若发现文档有错误, +执行 +\begin{lstlisting}[language=bash] + sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list +\end{lstlisting} +恢复文档. + +使用 VS Code 同样可以编写 \texttt{tex} 文件, +这涉及到如何使用 \LaTeX{} 的编辑器, +这里不做展开.
\ No newline at end of file |