1. Ubuntu LaTeX 環境配置
安裝 TeXLive
這里直接安裝 texlive-full
完全體,避免后續缺少依賴。安裝包較大,需要等待一段時間。
主要使用TeXLive中的XeLaTeX,XeLaTeX已經集成了中文環境。
sudo apt-get install texlive-full
安裝 cjk 宏包
sudo apt-cache search cjk
添加字體
這里我以添加宋體為例:
從Windows下 C:\Windows\Fonts\
目錄中拷貝 simsun.ttc
,或從互聯網上下載宋體字體。
Ubuntu下進入 /usr/share/fonts/
文件夾,為了避免與Ubuntu系統自帶字體沖突,新建文件夾 winfonts
。
cd /usr/share/fonts/
sudo mkdir winfonts
將准備好的 simsun.ttc
文件移動至 winfonts
文件夾下,並刷新字體庫
sudo mkfontscale
sudo mkfontdir
sudo fc-cache
字體添加完畢后,可以通過 fc-list :lang=zh
查看中文字體的安裝情況,如下
$ fc-list :lang=zh
... // 省略一些輸出
/usr/share/fonts/winfonts/simsun.ttc: SimSun,宋體:style=Regular,常規 // 表示宋體已經加載完成,字體名為 SimSun
... // 省略一些輸出
測試中文LaTeX環境
新建文件 test.tex
,並輸入測試樣例。
\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{xeCJK}
\usepackage{listings}
\author{xqmeng}
\date{2020.11.05}
\setmainfont{SimSun}
\title{LaTeX 中文測試}
\begin{document}
\maketitle
\begin{center}
\end{center}
\section{段落}
你好,世界。
Hello world.
\end{document}
使用 XeLaTex
編譯 test.tex
:
xelatex test.tex
順利的話可以看到生成了 test.pdf。
2. VSCode LaTeX Workshop
VSCode 商店中搜索 LaTeX workshop,並安裝
修改 setting.json
按
F1
,搜索 Open Settings,進入 setting.json
向 settings.json
中添加以下關於 LaTeX Workshop 的內容
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.recipes": [
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "latexmk",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex -> bibtex -> pdflatex*2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}],
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"%DOC%"
]
},
{
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}],
"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"
]
在 VSCode 中打開 test.tex
文件,可以 build
,並在 build
完成后使用 VSCode 預覽。