Latex
Contents
Latex#
Author: Fu Yin
Update: July 29, 2022
Reading: 60 min
Introduction#
TEX
is software developed by Donald E. Knuth for typesetting words and mathematical formulas.
LaTeX
is a Format
that uses the TEX
software as the typesetting engine, which can be roughly interpreted as an encapsulation of TEX
.
Do you know the concept of “Distribution”, “Compiler”, “Macro-package”, and “Editor” in LaTeX?
Layout Engine(排版引擎):
a program that compiles source code and generates documents, such as
pdftex
,xetex
, andluatex
. Sometimes also called the compiler.
Format(格式):
a set of code that defines a set of commands.
LaTeX
is one of the most widely used formats.
Compiling Command(编译命令):
a program which combines
Engine
andFormat
to read source files and outputs PDFs. For example, thexelatex
command is that combines thexetex Engine
andLaTeX Format
.
Compiling Command |
Concept |
---|---|
|
The engine of the underlying invocation is actually |
|
The engine of the underlying invocation is actually |
|
The engine for the underlying invocation is |
|
The engine for the underlying invocation is |
Note
The Compiling Command latex
and the Format LaTeX
are often confused.
Macro-package(宏包):
LaTeX code package to enable extended functionality, such as
fontspec
andnatbib
Distribution(发行版):
a collection of compilers, macro packages, editors, and other tools, such as
TeX Live
,MacTeX
andMikTeX
Editor(编辑器):
a tool for editing LaTeX source files, such as
TeXShop
,TeXworks
,WinEdt
andVSCode
The following are the major Distribution
s in different systems:
Distribution |
Linux |
macOS |
Windows |
---|---|---|---|
TeX live |
yes |
yes |
yes |
MacTeX |
yes |
||
MikTeX |
yes |
yes |
yes |
The common file format in LaTex
:
.tex
: source file.bib
: the references document, and the.bbl
is the file after usingBibTex
compiling`.sty
: the package file, usually imported using\usepackage
.cls
: the class file, usually imported through the\documentclass
command at the beginning of the document
A learning Latex chinese website
Install#
The full LaTeX
distribution are recommended, and install it via TexLive on Linux, and via MacTex on MacOS.
MacTex Webpage: https://www.tug.org/mactex/
MacTex Mirror in USTC: http://mirrors.ustc.edu.cn/CTAN/systems/mac/mactex/MacTeX.pkg
Note
The full software of MacTex is very large, and it takes about 7.98G space. However, the lightweight TinyTeX (< 100MB) is not recommended because it need install all the packages by yourself.
How to uninstall?
If you want to upgrade LaTeX
to the latest version and want to reclaim space by erasing the old distribution, you need to uninstall it and reinstall. (Scrolling Update
are not recommended)
Why tlmgr
command cannot be used for upgrade?
The Latex distribution is updated once a year. After each update, the tlmgr
command cannot be used because the remote repository has been changed to the latest version. For example the version from “2021” to “2022”, so the corresponding remote repository cannot be found.
The uninstallation instructions provided by the official website:
# Uninstalling TeX
sudo rm -r /usr/local/texlive/2022 # In general, we can also see that there is another directory called "texmf-local" under TexLive path. It is just an empty directory tree according to offical website. If you are obsessive-compulsive, delete it.
# Uninstalling the GUI Applications
sudo rm -r /Applications/Tex
# Uninstalling the TeX Distribution Data Structure
sudo rm -r /Library/TeX
Configration#
Latexmk#
If you use cross-references
or use BibTeX
for your bibliography, you often have to run compiling command such as xelatex
to do those work, which need compile multiple times.
The following code is about how to compile the document with BibTex
references, refer to the example.
xelatex -shell-escape file.tex
bibtex file.aux
xelatex -shell-escape file.tex
xelatex -shell-escape file.tex
Why it need compile multiple times?
TEX
needs to refer to the document itself (tex
->tex
). Those information can only be known once you run it one time. For example, I want to know what page Chapter 2 starts on, and what a particular formula is in the document.TEX
needs to use the output of other programs, and the input of other programs isTEX
’s output (tex
->other
->tex
). For example,references
(tex -> bibtex -> tex),indexes
, etc..
Latexmk, a Perl
script, only needs compile one time. It completely automates the process of generating a LaTex
document. Latexmk
is part of MacTeX
and MikTeX
and it is bundled with many Linux Distributions.
Running latexmk
latexmk file.tex
Cleaning Up
latexmk -c
Specify "xelatex" Compile
latexmk -xelatex file.tex
Makefile#
You can run make
and make clean
for your main.tex
document. The following is the content of Makefile
file:
$ cat Makefile
MAIN = main
LATEXMK = latexmk -xelatex -shell-escape
all: main clean
main:
$(LATEXMK) $(MAIN).tex
clean:
latexmk -c $(MAIN).tex
rm -r _minted-main
rm -r *.bbl
VSCode#
Download the plugin, LaTex Workshop
, in VSCode Extensions.
For each Latex project, put the
.vscode/settings.json
file in the root directory.Please check
latex-workshop.latex.tools
andlatex-workshop.latex.recipes
options in.vscode/settings.json
file.
Here is my .vscode/settings.json
file:
{
"latex-workshop.intellisense.package.enabled": true,
"latex-workshop.intellisense.unimathsymbols.enabled": true,
"latex-workshop.latex.build.forceRecipeUsage": true,
"latex-workshop.latex.recipes": [
{
"name": "latexmk -xelatex",
"tools": ["latexmk -xelatex"]
}
],
"latex-workshop.latex.tools": [
{
"name": "xelatex",
"command": "xelatex", // "/Library/TeX/texbin/xelatex"
"args": [
"-shell-escape", // use pygments to highlight syntax code
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOCFILE%"
]
},
{
"name": "latexmk -xelatex",
"command": "latexmk", // "/Library/TeX/texbin/latexmk"
"args": [
"-xelatex",
"-shell-escape", // use pygments to highlight syntax code
"-file-line-error",
"-halt-on-error",
"-interaction=nonstopmode",
"-synctex=1",
"-pv-",
"-pvc-",
"-outdir=%OUTDIR%",
"%DOCFILE%"
],
"env": {}
}
]
}
Overleaf#
Overleaf is a collaborative cloud-based LaTeX editor used for writing, editing and publishing scientific documents. It partners with a wide range of scientific publishers to provide official journal LaTeX templates, and direct submission links.
Tutrial#
The detailed manual, please refer to the book: 一份不太简短的 LaTeX2e 介绍(lshort-zh-cn).
Latex-Template-Rice-USTC is my
Latex
project , which is a template including book, thesis, and assignment for Rice and USTC university. You can use it via Overleaf https://www.overleaf.com/latex/templates/latex-template-rice-ustc/tkdscxhkympdCV is my academic CV powered by
LaTeX
.
Reference#
Book: 一份不太简短的 LaTeX2e 介绍(lshort-zh-cn)
Book: LaTeX 入门(亚马逊)