LaTeX环境配置TeXlive2021+Texworks/TeXstudio/VS Code/Sublime Text on Windows WSL or Fedora
1 TeXlive2021 安装
- 目标:安装TeXlive2021+Texworks或TeXstudio
- 系统:Windows WSL(Ubuntu) 以及 Fedora
- 准备文件:TeXlive2021镜像
- 国内镜像源:
https://mirrors.ustc.edu.cn/ https://mirrors.tuna.tsinghua.edu.cn/
1.1 Windows WSL篇(安装TeXlive)
1.1.1 配置Windows WSL(Ubuntu)
-
安装WSL 控制面板->程序->程序和功能->适用于Linux的Windows子系统 应用商店安装Ubuntu(20.04 LTS) -
换源更新 开始菜单->Ubuntu 命令行执行: sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list
替换以下内容,Ctrl+O写入文件保存退出 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
更新 sudo apt-get update
sudo apt-get upgrade
Windows资源管理器装载ISO,在WSL中加载 sudo mkdir /mnt/img
sudo mount -t drvfs X(系统中盘符): /mnt/img
sudo mnt/img/install-tl
1.1.2 安装TeXlive
- 安装TeXlive后,设置环境变量:
sudo /usr/local/texlive/2021/bin/x86_64-linux/tlmgr path add
- 使用Windows字体
sudo apt install fontconfig
sudo nano /etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/mnt/c/Windows/Fonts</dir>
</fontconfig>
刷新字体缓存sudo fc-cache -fv
1.2 Fedora篇(安装TeXlive)
1.2.1 配置Fedora
- 更换国内YUM源
sudo sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.ustc.edu.cn/fedora|g' \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-modular.repo \
/etc/yum.repos.d/fedora-updates.repo \
/etc/yum.repos.d/fedora-updates-modular.repo
缓存更新,安装更新包,安装perl-tksudo dnf update -y
sudo dnf install perl-tk -y
1.2.2 安装TeXlive (2选1)
1.3 配置
1.3.1 更新TeXlive(tlmgr)
sudo tlmgr option repository https://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet
sudo -E tlmgr update --self
sudo -E tlmgr update --list
sudo -E tlmgr update --all
1.3.2 字体配置(Win/Fedora相同)
-
HaranoAjiFonts: https://github.com/trueroad/HaranoAjiFonts -
日文字体配置 查看可用字体 kanji-config-updmap-sys --ja status
输出: CURRENT family for ja: haranoaji (variant: <empty>)
Standby family : ipa
Standby family : ipaex
更改 kanji-config-updmap-sys --ja haranoaji
中文配置 kanji-config-updmap-sys --sc fandol
2 各TeX编辑器配置
2.1 编译配置
2.1.1 TeXStudio
【Windows】
- 选项->Command(在所有需要的命令前加上wsl)
Latexwsl uplatex -synctex=1 -interaction=nonstopmode %.tex
Dvipdfwsl dvipdfmx %.dvi
- 选项->Build
Build&View(uplatex->dvi to pdf)txs:///latex | txs:///dvipdf | txs:///view-pdf
自定义(uplatex->dvips->ps to pdf)txs:///latex | txs:///dvips | txs:///ps2pdf | txs:///view-pdf
【Fedora】 略
2.1.2 TeXworks
【Windows】 (TeXworks无法使用WSL里的TeXlive,会出现“没有正确配置”提示,只能使用Windows系统下安装版MikTeX或TeXlive)
【Fedora】 (TeXworks首选项->排版->处理工具->添加) 名称:uplatexmk 程序:latexmk 参数(自上而下顺序,一行一个参数) 名称 -latex=uplatex -kanji=utf8 $synctexoption %O %S -e $dvipdf=‘dvipdfmx %O -o %D %S’ -pdfdvi $fullname
运行后查看PDF文件 默认:uplatexmk
2.1.3 VS Code+Latex Workshop
【Windows】 略 (不太建议用同一个工具,比如自己用Win+Fedora双系统时,VSCode账户会自动同步setting中的命令设置,导致每次只有一边系统可以进行编译。)
【Fedora】 settings.json中末尾追加
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.autoBuild.run": "never",
"latex-workshop.latex.clean.fileTypes": [
"*.aux", "*.bbl", "*.blg", "*.idx", "*.ind", "*.lof", "*.lot", "*.out", "*.toc", "*.acn", "*.acr", "*.alg", "*.glg", "*.glo", "*.gls", "*.ist", "*.fls", "*.log", "*.fdb_latexmk", "*.synctex.gz",
// for Beamer files
"_minted*", "*.nav", "*.snm", "*.vrb",
],
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-e",
"$latex=q/uplatex %O -synctex=1 -interaction=nonstopmode -file-line-error %S/",
"-e",
"$bibtex=q/upbibtex %O %B/",
"-e",
"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/",
"-e",
"$makeindex=q/upmendex %O -o %D %S/",
"-e",
"$dvipdf=q/dvipdfmx %O -o %D %S/",
"-norc",
"-gg",
"-pdfdvi",
"%DOC%"
]
}
]
2.1.4 Sublime Text (4126)
【Windows】 Tools->Build System->New Build System中新建并保存
- 安装版默认路径
C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages\User\BUILDSYSTEMNAME.sublime-build - 便携版默认路径
X:\Sublime Text\Data\Packages\User\BUILDSYSTEMNAME.sublime-build - 内容:
{"cmd" : ["cmd", "/c", "wsl uplatex -no-guess-input-enc -kanji=utf8 -synctex=1 -interaction=nonstopmode $file_name && cmd /c wsl dvipdfmx ${file_base_name}.dvi"],
"shell": true,
"working_dir": "${file_path}",
}
(wsl uplatex和wsl dvipdfmx之间用&&连接,$file_name包含扩展名,$file_base_name不包含扩展名)
【Fedora】 0. linux下latexmk的dvipdfmx参数尝试了很多,都不顺利,因此改变思路。
-
新建~/.latexmkrc nano ~/.latexmkrc
文件内容(默认使用uplatex,dvipdfmx等都写进配置里) #!/usr/bin/env perl
$latex = 'uplatex -synctex=1 -halt-on-error';
$latex_silent = 'uplatex -synctex=1 -halt-on-error -interaction=batchmode';
$bibtex = 'upbibtex';
$dvipdf = 'dvipdfmx %O -o %D %S';
$makeindex = 'upmendex %O -o %D %S';
$max_repeat = 5;
$pdf_mode = 3; # generates pdf via dvipdfmx
# Prevent latexmk from removing PDF after typeset.
# This enables Skim to chase the update in PDF automatically.
$pvc_view_file_via_temporary = 0;
# Use Evince as a previewer
$pdf_previewer = "evince";
-
SublimeText->Tools->Build System->New Build System中新建并保存 {
"cmd" : ["latexmk", "-pvc", "${file_name}"],
"shell": false,
"working_dir": "${file_path}",
}
注意linux下shell一定改为false,否则会引发 \write18 enabled提示无法继续编译 -
Sublime Text中写好文件后编译,默认情况下用Evince打开。好处是WYSIWYG。只要保持PDF窗口打开,每次在Sublime Text编辑窗口中保存好更新的tex文件,PDF就会自动重新编译。
2.2 颜色配置
2.3.1 TeXStudio
略
2.3.2 TeXworks
【Fedora】
-
配色 fedora文本编辑器背景色,前景色 路径(任意):~/.config/texworks (新建) user.css QTextEdit {
background-color: #003333;
color: #FFF8DC;
}
-
Fedora(GNOME)下Texworks修改桌面快捷方式: sudo nano /usr/share/applications/texworks.desktop
原: Exec=texworks %F
改: Exec=texworks -stylesheet /home/flakrp/.config/texworks/user.css %F
Ctrl+O 保存退出 -
TeXworks语法高亮颜色(Latex): (TeXworks首选项->编辑器->语法高亮->Latex) 命令行: sudo nano ~/.local/share/TUG/TeXworks/configuration/syntax-patterns.txt
[LaTeX]
#special characters
#993333;B N [$#^_{}&]
#LaTeX environments
#6699FF;B N \\(?:begin|end)\s*\{[^\}]*\}
#LaTeX packages
darkblue N \\usepackage\s*(?:\[[^\]]*\]\s*)?\{[^\}]*\}
#control sequences
#0099FF;B N \\(?:[\p{L}@]+|.)
#comments
#66CC99 Y %.*
%%%%%%%语法说明(texworks manual p37)%%%%%%%%%% <foreground_colour>/<background_colour>; Examples(Hex颜色开头空一格): Ex. red white/#000000 ;B blue;I #000000/#ffff00;U %%%%%%%%%%%%%%%%%%%%%%%
2.3.3 VS Code
Marketplace里安装: @id:vscode.theme-solarized-dark
|