Check out my first novel, midnight's simulacra!

LaTeX

From dankwiki

These days, I always use XeTeX (as opposed to e.g. pdflatex), usually in conjunction with the Memoir class and polyglossia package (as opposed to e.g. babel), though I might use LuaTeX instead. Code can generally run through both and result in similar output. XeTeX is significantly slower than pdflatex, and cannot use the full capabilities of the microtype package (as of 2023-09, anyway). Nonetheless, it's a far better way to deal with Unicode and modern fonts. LuaTeX seems another valid option, and might perhaps be more actively developed. It's currently about as slow as XeTeX.

Note that Amazon's createspace package cannot be used with XeTeX, at least as of 2023-08.

I have a blog post from 2023-09-24 about LaTeX in 2023.

General

  • Use the microtype package for most documents. It improves typography via several means.
    • It is only partially supported outside of pdflatex; LuaTex supports it better than XeTeX as of 2023-10 (see the table in the documentation, page 6).
  • Use the realscripts package for most documents. It improves sub- and superscripts when using OpenType fonts with appropriate features (normally the glyphs are simply drawn at a smaller size). It doesn't work well in certain environments or in certain cases, in which case use a '*' suffix to revert to the previous definitions. It's best to use this from the beginning of a document so that you check each placement.
    • As of late 2023, it does not work well with siunitx in my experience. You'll want to define text-subscript-command and text-superscript-command to be commands which use \textsuperscript* etc., though this does seem to work.
  • 72.27 points equals 1 inch equals 25.4 millimeter
  • Invoke with -halt-on-error for better life quality
    • You probably want -shell-escape as well. I've never found a situation where it's bad.

LuaLaTeX/XeTeX notes

  • LuaLaTeX needs the Harfbuzz renderer to handle complex languages, and it's superior in any case.
    • I think this is the default as of 2020 ("LuaHBTex")

Punctuation

Quotation Marks

  • Use `` for the left mark, and two apostrophes for the right.
  • If you're nesting single quotes within double quotes (e.g. for a quote within a quote), you might run into problems when the interior quote ends or begins with the exterior one, e.g. ''' (which is rendered as a double right quote followed by a single right quote). To properly nest, use e.g. '\thinspace''.
  • If you want an actual old-skool quotation mark (for emulating old terminals, perhaps), try \textquotedbl.
    • For an old-skool apostrophe, \textquotesingle.

Hyphens/Dashes

  • Hyphens separate the parts of a compound word. Use a single '-', without spaces.
  • En dashes separate the bounds of a range, usually numerics. Use two '-' characters, without spaces.
  • Em dashes separate distinct thoughts. Use three '-' characters, without spaces.
  • Minus signs are a mathematical entity. Use a single '-' in math mode.
  • To get two actual hyphens, try -{}-.

Periods

To get correct spacing:

  • Use ".\ " if the period does not end the sentence.
  • Use "\@. " if the period ends the sentence, and follows a capital letter.

Ellipses

Use \ldots (or \cdots for line-centered dots).

  • Don't use three periods (bad spacing) or the Unicode character '…' (HORIZONTAL ELLIPSIS, U+2026).
  • What about \dots? fixme

Tildes

Generally, \textasciitilde{} is the way to go. In math mode, use \sim.

  • When typesetting a url, the url and hyperref packages handle tildes properly.

Backslashes

Use \textbackslash{} to render a backslash in text.

Lists

Enclose bulleted lists within a \begin{itemize} and \end{itemize} block. Each element is preceded by \item.

  • enumerate will give numbers instead of bullets
  • description generates labeled items. Provide each label in square brackets: \item[label]

Tables

Appearance

Fonts

  • Bold: \textbf{boldfaced text}
  • Italics: \textit{italicized text} (it is advised to end most italicized sequences with "\/")
  • Monospace: \texttt{typewriter-stylized text}

LuaTeX and XeTeX support modern (TTF, OTF, etc.) fonts naturally. Use -otf versions of packages with these engines if they're available (e.g. kpfonts-otf rather than kpfonts).

Spacing

  • The default margins are generally 1.5" or more, more suitable for books than other documents. For 1" margins, add \usepackage{fullpage}.
  • Double-spacing can be achieved (in the main body) via \usepackage{doublespace}
    • Return to single-spacing via \begin{singlespace} and \end{singlespace} blocks.
  • \vfill, \vspace{amount} and \pagebreak

Special Forms

To include monospaced documents (code, emails, etc) use \VerbatimInput on a filename argument. This requires the moreverb package.

  • Important attributes include fontsize, frame, framerule, label, and numbers

To do a background color/image with text, to set a block of text away from the main body, to do anything funky like that, tcolorbox is the way. For instance, to stretch an image semitransparently behind text without any extra whitespace or background color:

\begin{tcolorbox}[enhanced,
                  size=minimal,
                  interior style={fill overzoom image=IMAGEFILE,fill image opacity=0.25},
                  opacityback=0,
                  beforeafter skip=0pt]
 ...text goes here...
\end{tcolorbox}

Unicode

Basic LaTeX doesn't support UTF-8 beyond expanding macros based on lexical sequences. If this is intended, use the utf8 parameter to the inputenc package.

You should just use XeTeX or LuaTeX. Both aim to be a fully Unicode-aware TeX engines. You shouldn't need to specify any utf8-specific stuff in your preamble.

BibTeX

Checkers

Of these, ChkTeX seems more fully-featured than lacheck. Neither is actively maintained.

  • ChkTeX
    • Watch out for some idiosyncrasies of ChkTeX. In particular, its error #38 is a false positive using the standard rules of American English.
    • Rule emission can be controlled with command-line options or ~/.chktexrc
      • I use -n 38
      • This has the (more descriptive) .chktexrc equivalent QuoteStyle = Traditional (default: Logical)
  • lacheck

See Also