Blog 1

Random Talk on Random Thoughts

My $\rm \LaTeX$ Macros for Math Writing

Basically, I just copied all the custom macros defined in the local configuration file MathJaxLocal.js and adapted it for mymacros.sty.

Sample output

sample

Using the macros

Since I want both the simplicity of Markdown syntax and the convenience of using Vim-$\rm \LaTeX$, I use .tex as the file extension of the pandoc document. If you mind the wrong syntax highlighting, you may use .mkd or whatever way you want.

My sample pandoc document
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
title: Write Efficiently in Markdown!
author: Vincent Tam
date: \today
geometry: margin=1in
header-includes:
- \usepackage{mymacros}
---

# Section 1: sample code block

Use the *following* command to generate a PDF file.

    $ pandoc -f markdown+yaml_metadata_block foo.tex -o foo.pdf

The file extension `.tex` is for using Vim-\LaTeX.

## Subsection 1.1: sample math

Suppose that $\vect{x} \ne \zeros \in \C^n, \Q^n, \Z^n, \N^n$.  Then
we have

(@foo) $$\int_{0}^{1} 1 \ud x = \abs{1} =
\normlr{\frac{\vect{x}}{\norm{\vect{x}}}}.$$

# Section 2: sample list

One can refer to (@foo).  Here's a numbered list.

1. Sample link to pandoc's [markdown syntax][pandoc_markdown]
2. Sample link to my blog: <https://vincenttam.github.io>
    - Sample item: my introduction is under `/about`.
    - Sample item: the blog archive is under `/archive`.
3. Sample item.

# Section 3: sample picture

It's **not** so easy to insert pictures in \LaTeX, while it's *simple* in
Markdown.

![Title](fig1.png)

[pandoc_markdown]: http://johnmacfarlane.net/pandoc/demo/example9/pandocs-markdown.html

Here’s the sample output PDF file and the picture used in the document. I refered to the following pages while writing the above example.

  1. Pandoc markdown syntax
  2. Using YAML metadata block as header.1
  3. Adding numbered equations in pandoc.2

Source code for the macros

My custom macros (mymacros.sty) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\usepackage{amsmath}
\usepackage{amsfonts}

\newcommand{\field}[1]{\mathbb{#1}}
\newcommand{\C}{\field{C}}
\newcommand{\F}{\field{F}}
\newcommand{\N}{\field{N}}
\newcommand{\Q}{\field{Q}}
\newcommand{\R}{\field{R}}
\newcommand{\Z}{\field{Z}}

\newcommand{\zeros}{\mathbf{0}}
\newcommand{\ud}{\,\mathrm{d}}

\newcommand{\vect}[1]{\boldsymbol{\mathbf{#1}}}
\newcommand{\abs}[1]{\lvert#1\rvert}
\newcommand{\abslr}[1]{\left\lvert#1\right\rvert}
\newcommand{\norm}[1]{\lVert#1\rVert}
\newcommand{\normlr}[1]{\left\lVert#1\right\rVert}

\newcommand{\lcm}{\mathop{\mathrm{lcm}}}
\newcommand{\interior}{\mathop{\mathrm{int}}}
\newcommand{\exterior}{\mathop{\mathrm{ext}}}
\newcommand{\volume}{\mathop{\mathrm{vol}}}

\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathop{\mathrm{Var}}}
\newcommand{\Cov}{\mathop{\mathrm{Cov}}}
\newcommand{\Binom}{\mathop{\mathrm{Binom}}}
\newcommand{\Exp}{\mathop{\mathrm{Exp}}}
\newcommand{\Poi}{\mathop{\mathrm{Poi}}}

\newcommand{\GL}{\mathrm{GL}}
\newcommand{\SL}{\mathrm{SL}}
\newcommand{\Aut}{\mathrm{Aut}}
\newcommand{\id}{\mathop{\mathrm{id}}}

\newcommand{\Re}{\mathop{\mathrm{Re}}}
\newcommand{\Im}{\mathop{\mathrm{Im}}}
\newcommand{\Res}{\mathop{\mathrm{Res}}}
Sample output (test-macros.tex) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass[varwidth]{standalone}
\usepackage{mymacros}
\begin{document}
\[
  \int_{0}^{1} 1 \ud x = \abs{\id_{\Q}(1)} =
  \normlr{\frac{\vect{x}}{\norm{\vect{x}}}},
\]
where $\vect{x} \ne \zeros \in \C^n, \Z^n, \N^n$.\\
$\lcm(a,b)=ab/\gcd{(a,b)}$\\
$\interior A=\exterior (\R^n \setminus A) \ne \volume C$\\
$\SL(n,\F) \lhd \GL(n,\F)$\\
$X \sim \Binom(n,p), Y \sim \Poi(\lambda t)$\\
$Z \sim \Exp(\lambda), \E[Z] = \Var[Z] = \lambda$
\end{document}

The use of the varwidth option before the standalone class is for line breaks and the displayed equation at the first line in the sample output.3 Loading the amsfonts packages avoid an “undefined control sequence error”.4


  1. See this page for details. 

  2. See this page for details. 

  3. See this page for details. 

  4. See this page for details. 

Comments