Simple Document Templates


MWE $\LaTeX$ and pandoc examples

To get started

  1. Download FOSS (free and open source) tools:

    • $\LaTeX$: a typesetting system often used by academians and researchers. It gives documents with a more impressive appearance.

      • Windows: Mik$\TeX$ → click Download in the navbar
      • Linux: install $\TeX$ Live directly from the TUG ($\TeX$ User Group)
      • Mac OS: Mac$\TeX$ (I’ve never used that.)
    • pandoc: a document markup language converter (e.g. ↔︎ , $\LaTeX$ ↔︎ , )

      Click Installing in the navbar.

  2. (Optional, recommended) VS Code icon pandoc logo Download VS Code and plugin vscode-pandoc.

  3. While waiting for the download, you may start some basic tutorials.

    • Markdown: a markup language with simple syntax. It allows you to focus on typing contents without having to leave the keyboard to do the styling. There’re numerous online tutorials. Here’s an example.
    • (optional) $\LaTeX$: a markup language for math equations. Again, there’re many online tutorials, for example
    • (optional) $\LaTeX$ mhchem package: an extension for rendering chemical equations.
    • (optional) $\LaTeX$ chemfig package: an extension for rendering chemical figures. You may see Overleaf’s chemfig tutorial.
  4. (Optional) Download additional $\LaTeX$ packages if necessary.

    • (Recommended) Download amsmath in your $\LaTeX$ package manager.

    • Download mhchem in your $\LaTeX$ package manager.

      Here’s the procedure on MikTeX Console.

      MikTeX console

    • Download chemfig in your $\LaTeX$ package manager.

Remarks: Even though $\TeX$Live supports Windows, but Mik$\TeX$’s installation size is much smaller (so that the installation time is much shorter), and it supports on-the-fly installation for missing packages.

Articles

Basics

  1. Save the Markdown source file using a text editor (say, Notepad).
  2. pandoc icon / Compile the source file using pandoc.
  3. View the compiled document using a suitable document viewer.

Basic structure of the Markdown source file:

  1. (Optional) Header
  2. Body

Markdown source file to be saved.

---
title: Sample document title
author: Vincent Tam
date: 23rd March, 2023
---

Document body goes below the YAML header.

Click to view PDF in new tab.

Simplest example: English articles

I’ve chosen VS Code as the text editor for easier compilation.

  1. VS Code icon Open VS Code and save the file (using `+S`).
    ---
    title: Sample Document Title
    author: John Doe
    date: 23rd March, 2023
    ---
    
    # Section One
    
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua. Ut aliquam purus sit amet luctus
    venenatis lectus magna. Dictum non consectetur a erat nam at.
    
    Scelerisque viverra mauris in aliquam sem fringilla ut. Mi quis hendrerit dolor
    magna eget est lorem ipsum. Ullamcorper malesuada proin libero nunc consequat
    interdum varius sit. Ultricies mi quis hendrerit dolor magna eget est.
    
    # Section Two
    
    Aliquam sem et tortor consequat. Nisl purus in mollis nunc sed id semper risus
    in. At risus viverra adipiscing at in tellus. Etiam sit amet nisl purus. Lacus
    suspendisse faucibus interdum posuere lorem ipsum dolor sit.
    
    | left | center | right |
    | :--- | :---: | ---: |
    | first cell | second cell | third cell |
    | abc | def | ghi |
    
    1. first item
    1. second item
    
    - item A
    - item B
    
    > Direct quote: Sit amet tellus cras adipiscing enim eu. Nisl nunc mi ipsum
    > faucibus vitae aliquet. Amet nisl purus in mollis nunc sed id semper.
    > Elementum nisi quis eleifend quam adipiscing vitae. Duis convallis convallis
    > tellus id interdum velit laoreet id donec.
    
  2. / Compile using plugin vscode-pandoc.

    1. Press <F1> key, then type “pandoc”.

      vscode-pandoc screenshot
    2. Select “pdf”/“docx” either with up ↑/down ↓ or by mouse click.

      vscode-pandoc screenshot
  3. Output files:

Improved example: A4 multilingual articles (without CJK)

  1. Follow the instructions in Setting additional pandoc options to set the value of the option pandoc.pdfOptString to --pdf-engine=lualatex, so that the document can contain characters like ‘é’, ‘ç’, ‘à’, etc.

  2. Save the follow Markdown source code to VS Code.

    ---
    documentclass: article
    geometry: margin=1in
    papersize: a4
    fontsize: 12pt
    mainfont: Times New Roman
    title: Better Article Sample
    author: John Doe
    date: 23rd March, 2023
    ---
    
    # Section Ωαβ
    
    Lôrém ipsùm dolor sit amet, çonsectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua. Ut aliquam purus sit amet luctus
    venenatis lectus magna. Dictum non consectetur a erat nam at.
    
    Scelerisque viverra mauris in aliquam sem fringilla ut. Mi quis hendrerit dolor
    magna eget est lorem ipsum. Ullamcorper malesuada proin libero nunc consequat
    interdum varius sit. Ultricies mi quis hendrerit dolor magna eget est.
    
    # Section Two
    
    Aliquam sem et tortor consequat. Nisl purus in mollis nunc sed id semper risus
    in. At risus viverra adipiscing at in tellus. Etiam sit amet nisl purus. Lacus
    suspendisse faucibus interdum posuere lorem ipsum dolor sit.
    
    | left | center | right |
    | :--- | :---: | ---: |
    | first cell | second cell | third cell |
    | abc | def | ghi |
    
    1. first item
    1. second item
    
    - item A
    - item B
    
    > Direct quote: Sit amet tellus cras adipiscing enim eu. Nisl nunc mi ipsum
    > faucibus vitae aliquet. Amet nisl purus in mollis nunc sed id semper.
    > Elementum nisi quis eleifend quam adipiscing vitae. Duis convallis convallis
    > tellus id interdum velit laoreet id donec.
    
  3. / Compile using plugin vscode-pandoc.

  4. Output files:

We changed the mainfont to Times New Roman for Windows. In fact, it can be any font installed on the OS. (You may find them out by hitting the key, then type “font”, and hit Fonts.) The default version of Computer Modern is a bitmapped font. You may see the printed sample of this font at the end of the section Cheatsheets.

CJK articles

  1. Download an additional $\LaTeX$ package for CJK fonts, say noto.

  2. Save the follow Markdown source code to VS Code.

    ---
    documentclass: article
    geometry: margin=1in
    papersize: a4
    fontsize: 12pt
    mainfont: Times New Roman
    CJKmainfont: Noto Sans CJK SC
    title: CJK Article Sample
    author: John Doe
    date: 23rd March, 2023
    header-includes: |
      \ltjsetparameter{jacharrange={-2}}
    ---
    
    # Section Ωαβ
    
    Lôrém ipsùm dolor sit amet, çonsectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua. Ut aliquam purus sit amet luctus
    venenatis lectus magna. Dictum non consectetur a erat nam at.
    
    - 繁體中文
    - 简体中文
    - こんにちは
    - 조선글
    
    # Section Two
    
    Aliquam sem et tortor consequat. Nisl purus in mollis nunc sed id semper risus
    in. At risus viverra adipiscing at in tellus. Etiam sit amet nisl purus. Lacus
    suspendisse faucibus interdum posuere lorem ipsum dolor sit.
    
    | left | center | right |
    | :--- | :---: | ---: |
    | first cell | second cell | third cell |
    | abc | def | ghi |
    
    1. first item
    1. second item
    
    - item A
    - item B
    
    > Direct quote: Sit amet tellus cras adipiscing enim eu. Nisl nunc mi ipsum
    > faucibus vitae aliquet. Amet nisl purus in mollis nunc sed id semper.
    > Elementum nisi quis eleifend quam adipiscing vitae. Duis convallis convallis
    > tellus id interdum velit laoreet id donec.
    
  3. / Compile using plugin vscode-pandoc.

  4. Output files:

We added the CJKfont: Noto Sans CJK SC in the header. You may check the folder C:\Users\[your_user_name]\AppData\Local\Programs\MiKTeX\fonts\ (or fonts/ under your Mik$\TeX$’s path).

$ ls ~/AppData/Local/Programs/MiKTeX/fonts/opentype/public/notocjksc/
NotoSansCJKsc-Black.otf      NotoSansMonoCJKsc-Regular.otf
NotoSansCJKsc-Bold.otf       NotoSerifCJKsc-Black.otf
NotoSansCJKsc-DemiLight.otf  NotoSerifCJKsc-Bold.otf
NotoSansCJKsc-Light.otf      NotoSerifCJKsc-ExtraLight.otf
NotoSansCJKsc-Medium.otf     NotoSerifCJKsc-Light.otf
NotoSansCJKsc-Regular.otf    NotoSerifCJKsc-Medium.otf
NotoSansCJKsc-Thin.otf       NotoSerifCJKsc-Regular.otf
NotoSansMonoCJKsc-Bold.otf   NotoSerifCJKsc-SemiBold.otf

Remarks: The following two lines come from my recent $\TeX$.SE question.

header-includes: |
  \ltjsetparameter{jacharrange={-2}}

Cheatsheets

Here’s a sample template with

  • A4 paper (210mm × 297mm)
  • font: Times New Roman (also in math mode)
  • font size: 10pt
  • margin: 0.5cm
  • line spacing reduced by 0.25×
  1. save the source file using the name test.md in any text editor (say Notepad). You may replace test to any name you like. The extension name .md stands for Markdown.

    ---
    fontsize: 10pt
    geometry: a4paper, margin=.5cm
    mainfont: Times New Roman
    header-includes:
    - |
      ```{=latex}
      \usepackage{fontspec}
      \usepackage{amsmath}
      \usepackage{mhchem}
      \usepackage{chemfig}
      \usepackage{setspace}
      \renewcommand{\baselinestretch}{.75}
      ```
    ---
    
    # Section
    
    Lorem ipsum dolor sit amet, **consectetur adipiscing elit**, sed do *eiusmod*
    tempor incididunt ut labore et dolore magna aliqua. Parturient montes nascetur
    ridiculus mus mauris.
    
    Diam éµçà enim lobortis scelerisque. Cursus metus aliquam eleifend mi. Eget
    lorem dolor sed viverra ipsum nunc aliquet bibendum. Dui vivamus arcu felis
    bibendum ut tristique. Leo integer malesuada nunc vel risus commodo.
    
    
    1. \ce{Hg^2+ ->[I-] HgI2 ->[I-][text below] [Hg^{II}I4]^2-}
    1. \ce{Zn^2+ 
        <=>[+ 2OH-][+ 2H+]
        $\underset{\text{amphoteres Hydroxid}}{\ce{Zn(OH)2 v}}$
        <=>[+ 2OH-][+ 2H+]
        $\underset{\text{Hydroxozikat}}{\ce{[Zn(OH)4]^2-}}$
      }
    
    # Chemical figures
    
    See chemfig package for more info.
    
    | left | right | center |
    | :--- | ---: | :---: |
    | v shape | quick fox | \chemfig{A-[7]B-[1]C} |
    | heptagon | number one two | \chemfig{A*7(-B=C~D>E<F>:G<:)}
    
    save text file notepad

    Save text file to Notepad

    GIF prepared by (GPL-licensed) LICECap

  2. Open the terminal.

    • Windows: type key, then input “cmd” and choose Command Prompt.
    • Linux: press and hold three keys in the sequence <Ctrl>, <Alt> and t, then release them.
    • Mac OS: press <Ctrl><Space> and type “terminal” and hit return.
  3. Change to the folder/directory containing the above source file by using cd [target_directory], say

    cd Documents
    

    If the path is too long, a more practical way would be to open the file explorer and drag the target folder onto the terminal.

    drag folder to command prompt

    Drag folder to Command Prompt

    GIF prepared by (GPL-licensed) LICECap

  4. Type this command in the terminal, then hit enter to run the command.

    pandoc test.md -o test.pdf
    
  5. Compiled PDF test.pdf (click to open in new tab)

Since it’s a cheatsheet, one might want a condensed/narrow font, so that one can put more info inside the document.

This template allows using any system font (found on Windows by typing the key then input “fonts”).

pandoc generated PDF with Blackadder ITC font

LuaLaTeX allows using system fonts

pandoc generated PDF with Blackadder ITC font

Click here to view in new tab

I’ve chosen fontspec (compiled with Lua$\LaTeX$) over fontenc (compiled with PDF$\LaTeX$) since Lua$\LaTeX$ and Xe$\LaTeX$ allow direct input of characters like ‘é’, ‘δ’, etc.

I’ve changed the default font (the default version of Computer Modern) due to its poor quality when rescaled and printed on paper.

Computer Modern font printed

The above photo recalled a webpage that I read a decade ago: Doing LaTeX Right. The cause of such imperfection is that the default font is a bitmapped font.

Slides

Markdown source code file structure

% Title
% Author
% Date

# Slide 1 Title

- point 1
- point 2

# Slide 2 Title

- point 1
- point 2
- etc

Some $\LaTeX$ snippets

(From a Discord demand) Proof with

Column Content
LHS left-aligned explanation
RHS equations aligned to ‘=’ sign

two column proof

\begin{alignat*}{3}
& \text{step one} & & \qquad &  v&=x \\
& \text{2nd step explanation} & & &       dv&=\int_0^\pi \sin x \,\dd{x} \\
& \text{another line line} & & & \Bbb{C} \oplus \Bbb{N} &= {\cal M} \cap {\bf T}_A
\end{alignat*}

Example modified from a $\TeX$.SE answer.


(Last modified on September 4, 2024)