/LaTeX-Templates

A collection of LaTeX templates in English/Chinese, with VS Code settings for LaTeX Workshop.

Primary LanguageTeXMIT LicenseMIT

LaTeX Templates

A collection of LaTeX templates in English / Chinese, with VS Code settings for LaTeX Workshop. (screenshots)

Table of Contents

Editor Preparation

1. Preliminaries

Download and install a TeX distribution (e.g., TeX Live) on your device.

Install TeX Live

Windows: download and invoke the TeX Live installer install-tl-windows.exe. Or install TeX Live using Chocolatey:

choco install texlive --params="'/scheme:full'"

macOS: install MacTeX using Homebrew:

brew install --cask mactex

Linux: manual installation:

wget -O - http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz |
    tar -xz --strip-components=1 --one-top-level=install-tl-unx &&
    cd install-tl-unx &&
    sudo ./install-tl

(Optional) Install dependencies for minted and latexindent

# Install Pygments for code highlighting with minted in LaTeX
pip3 install Pygments  # for Windows / macOS / Linux
brew install pygments  # for macOS

# Install dependencies for latexindent
cpan -i -T File::HomeDir Log::Log4perl Log::Dispatch::File \
        YAML::Tiny Unicode::GCString

2. Install VS Code and Extensions

Visual Studio Code is strongly recommended as the editor for LaTeX projects. You can download and install it from the official site at https://code.visualstudio.com.

Recommended extensions:

  • LaTeX Workshop: boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
  • LaTeX Utilities: An add-on to LaTeX Workshop that provides some fancy features.
  • Local History (optional): maintain local history of files.

You can find them in Visual Studio Code Marketplace (shortcut: Ctrl / Cmd + Shift + X).

3. Setup Editor for LaTeX Projects

# Clone this repository
git clone --depth=1 https://github.com/XuehaiPan/LaTeX-Templates.git

# Open the project with VS Code
code LaTeX-Templates

Then install recommended extensions in ".vscode/extensions.json", and copy the settings in ".vscode/settings.json" to your user settings. Refer to XuehaiPan/Dev-Setup/my-vscode-settings as a reference.

Usage

4. Compile and Preview with LaTeX Workshop

code --new-window Assignment   # open a template folder using VS Code

Open the main.tex file in a VS Code tab, then compile it with LaTeX-Workshop extension tool in the left panel, or use keyboard shortcut Ctrl / Cmd + Alt + B. See the wiki page of LaTeX-Workshop for more details about the extension features.

Some useful keyboard shortcuts (may be overridden by keymap settings):

  • View LaTeX PDF file (Ctrl / Cmd + Alt + V)

  • Build with last used recipe (Ctrl / Cmd + Alt + B)

  • Clean up auxiliary files* (Ctrl / Cmd + Alt + C)

  • SyncTeX from cursor in TeX file to PDF (Ctrl / Cmd + Alt + J)

  • SyncTeX from PDF to TeX file (hold the Ctrl / Cmd key and click on the PDF in the preview panel)

  • Format source files using latexindent (Ctrl / Cmd + Shift + I)

    * You don't need to do cleanup frequently, please do it only when necessary (e.g., on build failed). (Keep these auxiliary files can speed up the next compilation.)

* Manual Compilation

cd Assignment  # navigate to a template folder first

Compile with Latexmk (Recommended)

latexmk -xelatex -synctex=1 -shell-escape \
    -interaction=nonstopmode -file-line-error \
    -output-directory=out main
  • clean up auxiliary files*

    latexmk -c -output-directory=out
  • build and do cleanup if failed

    latexmk -xelatex -synctex=1 -shell-escape \
        -interaction=nonstopmode -file-line-error \
        -output-directory=out main ||
        latexmk -c -output-directory=out

Compile with XeLaTeX and Biber

Execute xelatex multiple times to resolve cross-references in the document.

# XeLaTeX ➞ Biber ➞ XeLaTeX × 2
xelatex -synctex=1 -shell-escape \
    -interaction=nonstopmode -file-line-error \
    -output-directory=out main
biber --output-directory=out main
xelatex -synctex=1 -shell-escape \
    -interaction=nonstopmode -file-line-error \
    -output-directory=out main
xelatex -synctex=1 -shell-escape \
    -interaction=nonstopmode -file-line-error \
    -output-directory=out main

Screenshots

Templates


Assignment Essay
Presentation NeurIPS 2021

Workspace


  • set "latex-workshop.view.pdf.viewer": "tab"

View PDF in a VS Code tab.

  • set "latex-workshop.view.pdf.viewer": "external" // or "browser"

View PDF in the external viewer or a web browser (for multi-monitor setup).