Recently, when I was sorting out my favorites and knowledge collection, I always felt that it was not very good to put many documents locally, evernote and Youdao Note. When I encountered problems, I would always Google first. I never thought that sometimes I had spent a lot of time sorting out, and I might have sorted out the same knowledge point in several local documents. Or you may have related problems in different notes, resulting in confusing information. Therefore, I plan from now on will collect their own things sorted out, all put in the blog, easy to find and unified update. Today we will update the LaTeX collation record.
Introduction to the
1. When Donald E. Knuth (Gartner) saw The proofs for The second volume of his multi-volume book “The Art of Computer Programming” in The late 1970s, he was disgusted by The low quality of The proofs typeset by computers. So I decided to develop a high-quality computer typesetting system by myself, and thus there was TeX.
2. The first version of TeX came out in 1978. The source program of TeX was written in Pascal, because Knuth wanted TeX to be transplanted into other operating systems as easily as possible. Pascal was the programming language best suited to this requirement. As a result, TeX is now implemented in almost all computer systems.
3. Another important feature of TeX is that its output is device-independent. TeX output files are called DVI files, which are “Device Independent”. Once TeX processes your file, your DVI file can be sent to any output device such as printer, screen, etc and always get the same result regardless of the limitations of those output devices. This means that all elements in the DVI file, from page Settings to character positions in the text, are fixed and cannot be changed.
4. TeX is now frozen by its developer Knuth and is basically no longer in development. But new variations keep appearing,
- LaTeX: Developed by Lamport in 1984 for use in thesis books, LaTeX contributed greatly to the spread of TeX, becoming the mainstream TeX document typesetting command thanks to its standard format control. LaTeX is the age of LaTeX.
- PDFTeX: 1997, developed by H.T. Thanh, fully compatible with standard TeX, but capable of giving PDF output. It can also output standard DVI.
- XeTeX: Jonathan Kew in 2005e-TeXAdd toUnicodeSupports, and connects to, a variety of Mac OS X technologies.XeTeXIn 2005/6, it was released in Windows and Linux versions, and finally integrated inTeXLive 2007Among others, it is a sign that it is widely recognized. inXeTeXChinese, using multiple languages, become very easy.
- LuaTeX: Successor to Aleph and PDFTeX in 2007, mainly developed by Taco Hoekwater, is a combination of Lua scripting language and TeX.
5. LaTex hairstyles:
- TeXLive: ** [official] ** is a TeX system developed by the international TeX user organization TUG that supports different operating system platforms. The Windows version is also called fpTeX, the Unix/Linux version is known as teTeX, and the Mac version is known as MacTeX. ISO image download address: click me
- MiKTeX: Originally a distribution for Windows, it has since been extended to support Linux and MacOS. It has an integrated editor, TeXworks.
- CTex: This is something that many people talk about when they talk about Chinese LaTeX, but THE CTex distribution is a folk development based on MiKTeX for early LaTeX that didn’t support Chinese. It’s MiKTeX itself. But now that XeTeX and other Texs supported by Unicode have matured, the CTeX version is no longer recommended.
- CTeX macro set: CTeX macros are not the same as CTeX distribution/package. CTeX macros are Chinese Support TeX libraries, which are required for the use of Chinese, so do not confuse them. CTeX is generally referred to today as the CTeX macro set.
Release version
Distributions of LaTeX are the various standard implementations. It is mainly TeXLive and MiKTeX, and other versions are based on these two major versions. Both distributions are fully platform-supported. MacTeX is actually an implementation of TeXLive on MacOS, so it’s classified here as TeXLive. The instructions are as follows:
- TeXLive: tug.org/texlive,**
- MacTeX: tug.org/mactex, actually owned by TeXLive, given a new name due to late Support for MacOS, comes with TeXShop;
- MiKTeX: www.miktex.org, come with TeXWorks;
CTeX: www.ctex.org/HomePage, XeTeX before the folk Chinese support version, based on MiKTeX, no longer maintained. Currently used for Chinese documentsXeTeX + CTeXMacro package can be supported.
If you need to install it, you can actually find it on the official website. For convenience, here are the download addresses for different distributions on different platforms:
-
TeXLive
- Windows: tug.org/texlive/win…
- MacOS: tug.org/mactex/
- Linux: www.tug.org/texlive/qui…
-
MiKTeX, this resource is simple, the same page to choose different systems
- Windows: miktex.org/download
- MacOS: miktex.org/download
- Linux: miktex.org/download
The editor
LaTeX, like the Java language, requires you to configure your environment and then choose your favorite editor or IDE to write “code.” Of course, all text editors can write “code” in other languages, such as LaTeX or Java. By IDE, I mean the integration of language localization features, such as compilation, special notation, and so on.
LaTeX distributions come with an editor. With TexLive, there’s a TexShop editor for MacOS, and a TexWorker editor for Windows. In addition, there is a third LaTeX editor. I have compiled all the instructions below, including the ones I recommend for my personal use. It is a matter of personal preference and you can choose according to your own preference.
- TeXMaker: www.xm1math.net/texmaker/, platform, all free, strongly recommend 👍 👍 👍;
- TeXStudio: texstudio.sourceforge.net/, platform, all free, recommend 👍 👍;
- WinEdit: www.winedt.com/index.html, only support Windows, charging, choose 👍 👍 🍚;
- TeXWorks: www.tug.org/texworks/, MiKTeX comes with an editor, free 👍;
- TeXShop: pages.uoregon.edu/koch/texsho… , TeXLive comes with an editor, free 👍;
I personally recommend the first two, because the third one is charged and not cross-platform, the reason for writing the third one is mainly because many blogs or users on the network recommend the third one, which I also feel good when I use it, but every time I use it, I have to use it on Windows, which is quite troublesome. Of course, if you use Windows and have the money, WinEdt does have better experience and features.
The installation
-
Windows/MacOS: You are advised to install TeXLive. Select an installation package based on your operating system. The Mac system corresponds to MacTeX.
-
MacOS: Automatically adds commands to environment variables after installation and comes with TeXShop editor.
$ which latex /Library/TeX/texbin/latex Copy the code
-
MacOS: TeXShop is a built-in editor for MacTeX. I personally prefer to install another editor, TeXMaker, which has many built-in visual symbols and can be clicked and inserted. It is simple and convenient.
-
Windows: TeXMaker and WinEdt are recommended. Developed specifically for TeX, they offer many convenient features that help improve typography efficiency
-
Compilation recommendation: Use PDFlatex (English document) or Xelatex (Chinese document) to compile and generate the corresponding PDF file.
use
Basic framework
1. Basic structure
\documentclass[a4paper]{article} % Specifies the document type
Introduction area: global Settings, macro package calls, etc
\begin{document}
% Body part
Hi, this is my first \LaTeX{} file.
\end{document} % end
Copy the code
- LaTeX source files: body + command + comments.
- Typesetting command (command for short) : string beginning with a backslash.
- Note symbol: percent sign %
- The document type:
\documentclass{... }
(Papers, books, slides, posters) - The environment:
\beigin{... }
At the beginning,\end{... }
At the end. - The attached:
\documentclass[]{}
Reference templates, which provide article templates by default.
2. Typesetting commands
-
The arguments in square brackets are optional (called options), and the arguments in curly brackets are required
\command \command[option]{arguments} % Some common commands: \documentcalss.\title.\author.\date.\usepackage \begin{environment name},\end{environment name}% Compose an environment Copy the code
-
Define a new command
\newcommand{new command}{command content}\renewcommand{existing command}{command content}For example, % \newcommand{\eps} {\varepsilon} Eps $$\ % > epsilon Copy the code
-
Document type: \documentclass[option]{documentclass}
- Is at the top of the source file and specifies the overall structure and layout of the document. You must select only one
- Article, book, beamer, cTexart, cTexBook, cTexbeamer
- Common options:
- 10pt(default), 11pt, 12pt → Specifies the size of the base font
- Letterpaper (default value), a4Paper, a5Paper,… → Specify paper size
- Single-sided options: Oneside, Twoside, OpenRight, Openany
- Mathematical formulas: LEqno (formula number on the left), FLEqn (interline formula on the left)
- Introductory area: the area between \ documentClass and \begin{document}
- The introduction area is used to place global control commands, such as: calling macro packages, setting page sizes,…
- Commands placed in the introduction area apply to the entire document
- Is at the top of the source file and specifies the overall structure and layout of the document. You must select only one
3. Chinese typesetting
-
The CTEX macro set provides three Chinese document classes: Texart, cTexBook, and cTexBeamer
-
Compile with Xelatex! Compile with Xelatex! Compile with Xelatex!
\documentclass[12pt,a4paper]{ctexart} \usepackage{amsmath} % AMS mathematical formula macro package \usepackage{amssymb} % AMS math symbol macro package \usepackage{amsfonts} % AMS Math font macro package \usepackage{graphicx} Illustration macro package \usepackage{xcolor} Color macro package \begin{document} Euler's formula is$$ e^{ix} = \cos(x) + i\sin(x).$$ \end{document} Copy the code
Common packages and commands
1. Code and comments:
Page layout: page width, page height, header height, footer height, various margins, etc
% \ usepackage [a4paper, scale = 0.8, hcentering bindingoffset = 8 mm] {geometry} % A4 size, scaling of 80%, set up a little more odd page blank on the right
\usepackage{geometry} % page layout macro package
Custom header footer: \ Pagestyle, \ thisPagestyle
\usepackage{francyhdr} % Header footer advanced customization macro package
%
\usepackage{amsmath} % AMS mathematical formula macro package
\usepackage{amssymb} % AMS math symbol macro package
\usepackage{amsfonts} % AMS Math font macro package
\usepackage{amsthm, bm} The % of mathematics
%
\usepackage{algorithm} % algorithm
\usepackage{algpseudocode} % pseudo code
\usepackage{listings} % blocks of code in various languages
%
\usepackage{graphicx} Illustration macro package
\usepackage{subfigure} Use subimage or subtable macros
\usepackage{subcaption} % Picture description
%
\usepackage{courier} % font
\usepackage{fontspec} % font
%
\usepackage{titlesec} % chapter custom macro package
\usepackage{titletoc} % directory customization macro package
\usepackage{cite} % reference macro package
\usepackage{natbib} % reference file custom macro package
\usepackage{longtable, diagbox, colortbl, booktabs} % table customization macro package
%
\usepackage{list} % Unordered list custom macro package
\usepackage{enumitem} % Ordered list custom macro package
%
\usepackage[Option list]{hyperref}% hyperlink macro package
\usepackage{xcolor} Color macro package
%
% ====================== Common commands =================
%%%%%%%%%% Title section: title, author, date, footnote, etc command %%%%%%%%%%
\title{title}% title
\author{the}% the author
\date{date}% date
% \date{} % will not output the date if it is left blank. If it is left blank, the default date will be added automatically
\thanks{... }% footnote, which must be placed inside {} of the command above
\maketitle % essential, generate the title command, the above command is only declared, this sentence can be generated
% % % % % % % % % % % % % in % % % % % % % % % % % %
\begin{abstract} % starts, the book type has no digest
%... .
\end{abstract} % end
% % % % % % % % % % % % % directory % % % % % % % % % % % % %
\tableofcontents % Generate directory
% \ setCounter {tocDepth}{level number} % sets the level of sections generated in the directory
%%%%%%%%%%% command %%%%%%%%%%%
\part % article
\chapter % chapter: There is no chapter in article, but there is a chapter in book
\section.\subsection.\subsubsection % section
\paragraph.\subparagraph % paragraph
%%%%%%%%%% References %%%%%%%%%%%
\begin{bibliography}{ref sample}\bibitem[Ref.]{label} Literature entry\bibitem[Ref.]{label} Literature entry\end{thebibliography}
%%%%%%%%%% Form command %%%%%%%%%%%
\begin{tabular}[vertical position]{column format}%first line \\
%last line \\
\end{tabular}
%%%%%%%%%% Number command %%%%%%%%%%
% Unordered number
\begin{itemize}
\item[Label] Item content\end{itemize}
% Ordered number
\begin{enumerate}
\item[Label] Item content\end{enumerate}
% % % % % % % % footnote % % % % % % % % %
\footnote{footnote text}% Auto-numbered footnote, immediately after the text to be annotated
\footnote[tag]{footnote text}% Manually specify a footnote tag
Copy the code
2. Special instructions
-
Short title: used for display in directories and headers. The default is the same as the title
-
Chapter commands with an asterisk: Do not participate in automatic numbering
Chapter command [short title]{title} chapter command *{title}Copy the code
-
Chapters, for example,
-
Text alignment (left by default)
- Left:
\raggedright
Or useflushleft
The environment - Right alignment:
\raggedleft
Or useflushright
The environment - Centered text:
\centering
Or usecenter
The environment
- Left:
-
The font size
-
Both English and Chinese are applicable
-
Ctex provides the following commands and size commands
\heiti, \songti, \fangsong, \kaishu, \lishu, \youyuan, \yahei Copy the code
-
hyperlinks
1. \usepackage[option list]{hyperref}
- Make links where there are cross-references (table of contents, bookmarks, references, formulas, etc.)
- Provides links to external files, Internet addresses, and email addresses
- Common options (also available
\ HyperSetup {options list}
To set up)bookmarks
→ Create a bookmark. The default is trueCJKbookmarks
→ Support bookmarks in Chinese, Japanese and Korean characterscolorlinks
→ Use color display link, red box by defaultlinkcolor
→ Color of internal common links (such as page numbers), the default is redcitecolor
→ The color of the reference link is green by defaulturlcolor
→ The color of the URL link is magenta by defaultbreaklinks
→ Allow in the link break line, the default is not allowed
2. Examples:
\usepackage{hyperref}
\hypersetup{CJKbookmarks=true, % Support Chinese bookmarks
colorlinks=true, % use color links
citecolor=blue, % reference tag color
linkcolor=blue, % Internal normal link color
urlcolor=blue, % Url link color
breaklinks=true } % allows line breaks at links
Copy the code
3. Create web links: \ URL and \href
\url{The url}
\href{The urlText} {}Copy the code
-
Url → Generate the url and output its content on the page
-
\href → Generate the url and output the text content on the page
color
www.jianshu.com/p/d184caa2c…
\documentclass{article}
\usepackage{xeCJK}
\usepackage{mathpazo}
\usepackage{color,xcolor}
% predefined color---black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, white, yellow.
\definecolor{light - gray} {gray} {0.95}% 1. The gray scale
\definecolor,0.5 RGB} {orange} {{1, 0}% 2.rgb
\definecolorRGB} {orange} {{255127, 0}% 3.RGB
\definecolor{orange}{HTML}{FF7F00} % 4.HTML
\definecolor,0.5 {orange} {cmyk} {0, 1, 0}% 5.cmyk
\begin{document}
%\pagecolor{yellow} % Sets the background color to yellow
\textcolorGreen} {green} {The % 1. The method
{\color{orange}} orange% 2. The method 2
\colorbox{red}{\color{black} Black text on red background}\fcolorbox{red}{green}{red box green background}% Box color + background color
\color{blue! 20}\color{blue! 20! black}\color{blue! 20! black! 30! green}%a mixture of (20*0.3) percent blue, (100-20)*0.3) percent black and (100-30) percent green
{\color[rgb]{1,0,0} This text will appear red-colored} % direct use
\textcolor[rgb]{0,1,0}{This text will appear green-colored} % direct use
\end{document}
Copy the code
The related resources
- LaTeX Studio: www.latexstudio.net (Templates, methods, tutorials)
- LaTeX Template Collection: www.latextemplates.com (various templates)
- LaTeX color definition: latexcolor.com
- Ecnu LaTeX official website: math.ecnu.edu.cn/~latex (Rich teaching resources)
- East China Normal University — Pan Jianyu : Math.ecnu.edu.cn/~jypan/Teac…(various shares, tutorials, materials) 👍👍👍
- Many screenshots of this article come from Pan Jianyu’s PPT.
- Wuhan University — Huang Zhenghua: aff.whu.edu.cn/huangzh (various teaching materials)
- [British] LaTeX usage tip: latex-cookbook.net
- [Britain] TeX Users Group: www.tug.org
- [English] LaTeX Packages: www.ctan.org
reference
- www.ctex.org/documents/s…
- www.latexstudio.net/page/introd…
- liam.page/texlive/
- www.latexstudio.net/archives/51…
- Math.ecnu.edu.cn/~jypan/Teac…