My LaTeX solution implementation

LaTeX, it is a kind of based on the TeX typesetting system, lesley lambert, a computer scientist by the United States in the early 1980 s development, using the format processing in the system, even if the user is not typesetting and programming knowledge can give full play to the powerful functions provided by TeX, don’t need to go to design or check one by one, Can produce many book-quality prints in a matter of days or even hours. This is especially true for generating complex tables and mathematical formulas. It is therefore ideal for producing high print quality technical and mathematical documents. The system is also suitable for generating all other kinds of documents, from simple letters to complete books. ———— Wikipedia

  • 1. Introduction
  • 2. Install and configure the software
    • 2.1 TeX Live
      • 2.1.1. TeX Live download
      • 2.1.2. TeX Live installation
    • 2.2 VS Code
      • 2.2.1. VS Code download and install
    • 2.3. LaTeX Workshop
      • 2.3.1. LaTeX Workshop download and installation
      • 2.3.2. Basic configuration for LaTeX Workshop
      • 2.3.3. Preview the compiled PDF file using SumatraPDF
        • 2.3.3.1. Download and install
        • 2.3.3.2. Basic Configurations
        • 2.3.3.3. Configuring forward Search (LaTeX →PDF)
        • 2.3.3.4. Configuring Reverse Search (PDF →LaTeX)
      • 2.3.4. Other Settings
  • 3. Verify the configuration scheme

1. Introduction

To put it simply: LaTeX is based on TeX, and its main purpose is to facilitate typesetting. In academia, especially in mathematics, computer science and other subjects, papers are written in LaTeX because it is very beautiful to write mathematical formulas in it. After learning a little bit about LaTeX, you will find that LaTeX works much like web pages, where the source file (.tex or.html) is rendered by the engine (Tex or browser) to produce the final effect (PDF file or page). They are very similar, including the rules of grammar and the way they work. So, as with HTML, getting started is simple.


Tsinghua University LaTeX template


\usepackage{foo}
include


Literary programming in LaTeX

Common file types for LaTeX templates Brief introduction to functions
.dtx Documented LaTeX Sources, an important part of the macro package
.ins Installation, control TeX from the.dtx file release macro package files
.cfg Config, the configuration file, can be generated from the above two files
.sty Style files, use\usepackage{... }Command to load
.cls Class files\documentclass{... }Command to load
.aux Auxiliary file, which does not affect normal use
.bst Abstract Style file, used to control the reference style

Class and style seem to be very similar. They are indeed functionally similar, but there are also differences. Here’s the difference between.cls and.sty files. My story of configuring the LaTeX solution is a bit convoluted. At first, I thought that it was not time to write a paper with strict layout, so I did not need to worry about learning LaTeX. For now, Markdown is good enough for me, but when I learned how to convert Markdown to Pdf with Pandoc, I was prompted to install pdfLaTeX, so I decided to move up my LaTeX learning schedule. Part of the reason is that Markdown uses LaTeX syntax when writing mathematical formulas. After looking up some information, I decided to use TeX Live + VS Code + LaTeX Workshop. On the one hand, my main editor is VSCode; On the other hand, the CTeX package recommended for LaTeX by Liu Haiyang is not recommended for people like me because it is “old, error-prone, pirated, over-encapsulated and does not support cross-platform”. To be specific:

  • MikTeX, wrapped in CTeX, has had some problems implementing XeTeX, which causes XeLaTeX to run abnormally slow, and the font library, which causes errors when using some mathematical fonts.
  • The default editor that CTeX encapsulates, WinEdt, is closed source software and is actually using pirated software.
  • The default editor for CTeX encapsulation, WinEdt, has changed the default encoding to GBK, which will cause a lot of problems in later use, which is bad for beginners.
  • WinEdt, the default editor encapsulated by CTeX, integrates too many features and changes so much of LaTeX’s default behavior that unannounced changes are not good for beginners to understand LaTeX.
  • The CTEX Forum has been closed for an indefinite period since November 21, 2018. The final version of the CTeX package has been fixed to version 2.9.2.164, which is no longer updatable and, in fact, no longer necessary.
  • CTeX can only run on Windows because it encapsulates MikTeX.
  • CTeX was introduced because of the complexity of the font configuration of the CJK package to save the cost of configuration for the initial user. Now, thanks to the XeTeX engine and the xeCJK macro package, the CJK package is a thing of the past. ZHM can be used in combination with CJK to dynamically configure fonts conveniently. As a result, the advantages CTeX used to have are actually no longer advantages, and the old problems caused by the various domestic periodical templates are becoming an aggravating factor hindering the progress of the TeX community in China.

2. Install and configure the software

2.1 TeX Live

TeX Live, TL for short, is a TeX system maintained by the International TeX User Group (TUG). Generally speaking, it is the most “authentic” TeX system, supporting different operating system platforms, configuring all the compilation environment and various macro packages. For TeX users at any stage, TeX Live can be used to maintain consistency across TeX files across operating systems and across users.

2.1.1. TeX Live download

TeX Live can be installed in two ways.

  • Network installation: The installation package is small in size, but the required content is constantly downloaded from the server during the installation. Ensure that the network is smooth. Also, if the Internet is very slow, it can take a while to use the network setup.
  • For a local installation, the installation package is large but contains everything you need for the installation. Therefore, the installation does not need to be connected to the Internet.

Since TeX Live network installation requires simultaneous download, the download speed in China is slow. Therefore, you are advised to download the ISO file directly to obtain the complete installation file at one time to facilitate the installation process. Attached is a mirror image of Tsinghua University.

2.1.2. TeX Live installation

  1. The downloaded file is an ISO CD-ROM image, which, in general, macOS/Windows 10 / most Linux can be mounted directly by double-clicking. However, if older versions of Windows exist, such as Windows 7 / XP, you will need to use a virtual CD/DVD-ROM drive for mounting.
  2. To avoid user permission issues, you can run install-tl-advanced.bat in administrator mode (right click -> Run as administrator). Go to the first box and click Advanced. (Note: The installation will take up about 5 GB of disk space. You are advised to switch the installation directory to disk D or another disk with large space.)
  3. See the installation interface below.
  4. In order to control the size of TeX Live, we can choose to change the n. of Collections option and remove Texworks (older editor, not recommended) and some language packs that we don’t use everyday. The Settings are as follows:
  5. Then click “Install”. After a lengthy installation, TeX Live was installed.

    After the installation is complete, you can call Commond and enter them separately in the command line window

tex -v
latex -v
xelatex -v
pdflatex -v
Copy the code

To get the environment information of the installed TeX! If the version information output is normal, then TeX Live installation is successful!

2.2 VS Code

Visual Studio Code (VS Code for short) is an open source Code editor developed by Microsoft for Windows, Linux, and macOS. It supports testing and has Git version control built in. There are also development environment capabilities, such as code completion (similar to IntelliSense), code snippets, and code refactoring. The editor supports user personalization, such as changing theme colors, keyboard shortcuts, and various properties and parameters, as well as extension management built into the editor.

2.2.1. VS Code download and install

The official website download and installation guide has been more perfect. A download link and post-installation instructions are attached here. VS Code is easy to download and install, but the key is to configure some high-quality plug-ins to suit your needs.

2.3. LaTeX Workshop

LaTeX Workshop is a plug-in for VS Code that provides LaTeX language support for VS Code.

2.3.1. LaTeX Workshop download and installation

In VSCode’s extension management, search for LaTeX, and the first result is the plug-in we want to install.

2.3.2. Basic configuration for LaTeX Workshop

Copy and paste the following Code into the VS Code setting.json file.

  • LaTeX Workshop’s default compilation tool is Latexmk, so I changed it to Xelatex, which is commonly used in Chinese environments. (Replace %DOC% with %DOCFILE% in tools to support files in Chinese)
"latex-workshop.latex.tools": [
    {
        "name": "xelatex",
        "command": "xelatex",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "-pdf",
            "%DOCFILE%"
        ]
    },
    {
        "name": "pdflatex",
        "command": "pdflatex",
        "args": [
            "-synctex=1",
            "-interaction=nonstopmode",
            "-file-line-error",
            "%DOCFILE%"
        ]
    },
    {
        "name": "bibtex",
        "command": "bibtex",
        "args": [
            "%DOCFILE%"
        ]
    }
],
Copy the code
  • To configure the build chain, as wellsetting.jsonConfiguration file. The first recipe is the default compilation tool. If you want to use Bibtex, click the tick in the lower left corner of the VS Code interface, click “Build LaTeX Project”, and choose “xe->bib-> XE -> XE”. Alternatively, use the right-hand bar. The default Recipe can be compiled with “xe->bib->xe->xe”, but it will be slower because it takes more time to compile.
"latex-workshop.latex.recipes": [
    {
        "name": "xelatex",
        "tools": [
            "xelatex"
        ]
    },
    {
        "name": "xe->bib->xe->xe",
        "tools": [
            "xelatex",
            "bibtex",
            "xelatex",
            "xelatex"
        ]
    }
    {
        "name": "pdflatex",
        "tools":[
            "pdflatex"
        ]
    }
],
Copy the code

Now you can use VS Code to edit a LaTeX document and compile it into a PDF file. Press CTRL+ALT+B to compile it, and then press CTRL+ALT+V to open the PDF file.

2.3.3. Preview the compiled PDF file using SumatraPDF

SumatraPdf is a lightweight PDF reader available as open software and available in both installed and portable versions. VS Code’s built-in PDF viewer is simple and less convenient, while Adobe Reader is relatively bulky and slow to open. Sumatra PDF is small, powerful, and fast to start, making it the most suitable PDF reader for this solution. Moreover, it can also make up for LaTeX’s disadvantage of “what you see is not what you get.”

2.3.3.1. Download and install
  • Install 32 – bit download link, portable 32 – bit download link
  • Install 64-bit download link, portable 64-bit download link
2.3.3.2. Basic Configurations

To preview the compiled PDF file using SumatraPDF, copy and paste the following code into the setting.json configuration file. Viewer set Reader to an external reader, and Command to the path of sumatrapdf. exe. The value can be changed as required.

"latex-workshop.view.pdf.viewer": "external",
"latex-workshop.view.pdf.external.viewer.command":"D:/tools/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.viewer.args": [
    "--unique",
    "%PDF%"
],
Copy the code
2.3.3.3. Configuring forward Search (LaTeX → PDF)

Copy and paste the following code into the setting.json configuration file to configure the forward search. Command is still the location of Sumatrapdf. exe. The value can be changed as required.

"latex-workshop.view.pdf.external.synctex.command":"D:/tools/SumatraPDF/SumatraPDF.exe",
"latex-workshop.view.pdf.external.synctex.args": [
    "-forward-search",
    "%TEX%",
    "%LINE%",
    "%PDF%",
],
Copy the code

Click “Left TeX toolbar” → “Navigate, Select,and Edit” → “SyncTeX from Cursor” or use the shortcut keys CTRL+ALT+J to search forward.

2.3.3.4. Configuring Reverse Search (PDF → LaTeX)

Open Sumatra PDF, go to The Settings -> Options dialog box, and add the following command under “Set reverse search command line” :

"Code.exe" "resources/app/out/cli.js" -g "%f":"%l"
Copy the code

Replace “code.exe” and “resources\app\out\cli.js” with the location where VS Code is installed on your own computer, for example:

"D:/tools/Microsoft VS Code/Code.exe""D:/tools/Microsoft VS Code/resources/app/out/cli.js" -g "%f":"%l"
Copy the code

Double-click anywhere in the PDF to jump to the source code for the corresponding content in VSCode.

It is best not to clean up temporary files with the gz suffix generated by Xelatex, otherwise forward and reverse searches cannot be performed.

2.3.4. Other Settings

Since the LaTeX compilation process produces auxiliary files that are not useful and look bad, the first parameter specifies that the auxiliary files are automatically cleared after the PDF file is generated. The second parameter is to save or not to automatically compile LaTeX files. Since VSCode has an automatic save function, it will compile LaTeX files every time it is automatically saved. This will cause the computer to automatically compile the documents every once in a while, which is unnecessary.

"latex-workshop.latex.autoClean.run": "onBuilt",
"latex-workshop.latex.autoBuild.run": "never",
Copy the code

3. Verify the configuration scheme

Create a new.tex file in VS Code and copy and paste the following Code into the Code area:

\documentclass{article} \usepackage{ctex} \begin{document} \title{My \LaTeX} \author{I} \maketitle \section {Chinese} \songti {this is song song} \heiti {this is in black} \kaishu {this is regular script} \fangsong {this is song song} \yahei {this is yahei} \section{Pythagorean theorem} Pythagorean theorem can be described in modern language as follows: The square of the hypotenuse of a right triangle is equal to the sum of the squares of the sides. $\ Angle C=90^\circ $ AB^2 = BC^2 + AC^2 ? That's the Pythagorean theorem. \end{document}Copy the code

Press CTRL+ALT+B, and then press CRTL+ALT+V (if not, click the icon in the upper right corner) to call Sumatra PDF reader to view the compiled PDF file. Double-click the PDF at the appropriate location to jump to the LaTeX source code in VSCode, and press CTRL+ALT+J to view the corresponding location of the PDF.

This article mainly refers to some web resources 1. LaTeX Quickstart 2. For LaTeX, use VSCode to write for LaTeX.