Latex
文章目录
- Latex
- 安装
- VSCode 配置 latex
- Reference
安装
sudo apt-get install texlive-full
# 安装时间有点长,其中的xetex集成了中文字体的环境,使得中文文档的生成变得很容易,可以使用系统自带得字体,使用更好看得字体。
apt-cache search cjk
# 找到相关宏包,安装
#letex chinese language package
sudo apt-get install latex-cjk-all
终端:
...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for sgml-base (1.29.1) ...
Processing triggers for install-info (6.7.0.dfsg.2-5) ...
Processing triggers for fontconfig (2.13.1-2ubuntu3) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for tex-common (6.13) ...
Running updmap-sys. This may take some time... done.
Running mktexlsr /var/lib/texmf ... done.
Building format(s) --all.
This may take some time... done.
(base) qiancj@qiancj-HP-ZBook-G8:~$ latex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=latex)
restricted \write18 enabled.
**
终端支持输入xetex
和latex
直接编辑:
(base) qiancj@qiancj-HP-ZBook-G8:~$ xetex
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019/Debian) (preloaded format=xetex)
restricted \write18 enabled.
**^C
(base) qiancj@qiancj-HP-ZBook-G8:~$ latex
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=latex)
restricted \write18 enabled.
新建 test.tex文档进行测试,输入以下内容:
\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{xeCJK} %调用 xeCJK 宏包
\usepackage{listings}
\author{ Randy }
\date {2023.5.17}
\setmainfont{SimSun} % 宋体
%\setCJKmainfont{WenQuanYi Micro Hei Mono:style=Regular} %设置 CJK 主字体为 SimSun (宋体)
\title{三戒纪元}
\begin{document}
\maketitle
\begin{center}
\end{center}
\tableofcontents %添加目录
\tableofcontents
\begin{abstract}
this is abstract。
\end{abstract}
\section{Section1}
欢迎关注微信公众号【三戒纪元】。
\section{Section2}
hello world
% Lorem \cite{Lutz2017} ipsum dolor sit amet, consectetur adipisicing
% \bibliography{info}
\bibliographystyle{ieeetr}
\end{document}
命令行中输入以下的编译命令
xelatex test.tex
(base) qiancj@qiancj-HP-ZBook-G8:~$ xelatex test.tex
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019/Debian) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 2
L3 programming layer <2020-02-14>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/iftex/ifvtex.sty
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty)))
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def))
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty)
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK.cfg))
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg))
Package xeCJK Warning: Fandol is being set as the default font for CJK text.
(xeCJK) Please make sure it has been properly installed.
Package fontspec Warning: Font "FandolSong-Regular" does not contain requested
(fontspec) Script "CJK".
(/usr/share/texlive/texmf-dist/tex/xelatex/xecjk/xeCJK-listings.sty)
No file test.aux.
(/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: xetex
LaTeX Font Warning: Font shape `TU/SimSun(0)/b/n' undefined
(Font) using `TU/SimSun(0)/m/n' instead on input line 15.
No file test.toc.
(./test.toc) [1] (./test.aux)
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
)
Output written on test.pdf (1 page).
Transcript written on test.log.
目录下输出test.pdf
文件
VSCode 配置 latex
扩展工具中安装 LaTeX Workshop
settings.json中增加:
{
"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.view.pdf.viewer": "tab",
"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"
]
}
如果ubuntu中没有中文字体,则安装或者拷贝中文字体进系统
重启VSCode
新建 *.tex 文件,然后输入内容,点击View LaTeX pdf file
按钮,就能实时看到pdf内容
Reference
- 在Ubuntu(Linux)下配置Latex环境