Some Misc Notes

Making Docs with Math and Diagrams

Make sure you have Pandoc and TeXLive installed:

apt install pandoc texlive

For diagrams, some ideas:

  • Draw them digitally using a pen display and export.
  • Use Inkscape. The A7 paper size works pretty well for medium-sized diagrams.
  • Draw them by hand and take a photo.
  • Create them using TikZ

Create your foo.md file:

\pagenumbering{gobble}

**My Title**

Some items:

 1. Note that \fbox{ $2\pi\phi = e^2$ } iff ...

\vspace{1cm}

 2. As you can see in this figure:

    ![](diagram-1.png)

 3. Last item.

\underline{And} display math:

$$\sum_{n = 0}^{\infty} \frac{1}{n^{2}}$$

The velocity vector of a bike:

$$
\mathbf{v_{\mathrm{bike}}} =
v_x \mathbf{\hat{x}} + v_y \mathbf{\hat{y}} + v_z \mathbf{\hat{z}}
$$

To display multiple equations aligned on equals signs:

\begin{align*}
a &= 1 \\
b &= a + 1 \\
c &= a + b + 1
\end{align*}

(Note, `align*` is to stop equation numbering; use `align` (sans star) if you
want the equations numbered.)

\begin{center}Centered, with small caps: \textsc{k.e.} = $\frac{1}{2} m v^2$\end{center}

Process the file with pandoc like so:

pandoc -o foo.pdf -V geometry:"margin=0.8in" -V fontsize=12pt foo.txt

or, if you want 2-column:

pandoc -s -o foo.pdf \
    -V geometry:"margin=0.8in,twocolumn" \
    -V fontsize=12pt foo.txt

Output from above sample:

Note, if your doc were to have a % My Title at the top, you’d end up with a lot of nice whitespace at the top of your output page.

I keep a short mkdn-to-pdf.py script around for creating a pdf from a text file:

#!/usr/bin/env python3

import sys, os, re, subprocess

if len(sys.argv) != 2:
    print("""Please pass the name of the .txt file to convert.
    Exiting.""")
    sys.exit()

md_fnm = sys.argv[1]

if not md_fnm.endswith(".txt"):
    print("Input filename must end with \".txt\". Exiting.")
    sys.exit()

if not re.fullmatch(r'[\w.,-]+', md_fnm):
    print("""Please keep input filename simple. Ex., no spaces, unicode, etc.
    Exiting.""")
    sys.exit()

pdf_fnm = md_fnm[:-4] + ".pdf"

pandoc_cmd = ["pandoc", "-s", "-o", pdf_fnm,
              "-V", "geometry:margin=0.8in",
              "-V", "fontsize=12pt",
              md_fnm]

print(md_fnm, "-->", pdf_fnm)
subprocess.check_call(pandoc_cmd)