LaTeX miscellanea

Useful bits of information for \LaTeX users. If you’re a math dude, the first one is probably how to embed it’s source code into WordPress posts!

Article structure

When I initially wrote this, I used \LaTeX proper. However, I’ve recently started to use XeLaTeX, which is a sort sort of “superset” of LaTeX: it assumes that the input file is in UTF-8, and it makes it possible to directly fonts that are installed in the system. It is now a part of the TexLive package.
Here’s what I now usually put in the preamble(*) of LaTeX articles:

\documentclass[a4paper,9pt,twocolumn]{article}

%\usepackage[portuguese]{babel}     % i18n
\usepackage{xltxtra}                           % without this, foreign chars are silently supressed
\usepackage{extsizes}                        % for font sizes smaller than 10pt
\usepackage[top=2.5cm, bottom=2.5cm, left=1.5cm, right=1.5cm]{geometry}
                                                                                                                       
\usepackage{lmodern}      % "traditional font

%%% additional packages here

\usepackage[pagebackref=true,bookmarks=true,colorlinks=true,
linkcolor=blue,citecolor=cyan,linktocpage=true]{hyperref}

\pdfpagewidth 210mm
\pdfpageheight 297mm

\setlength{\columnsep}{20pt}

% ************** footnotes' stuff here **************
\symbolfootnote[sym #]{footnote text}     %makes footnote with symbol instead of number
\long\def\symbolfootnote[#1]#2{\begingroup
\def\thefootnote{\fnsymbol{footnote}}\footnotetext[#1]{#2}\endgroup}

% make regular \footnote command use symbols instead of numbers
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

% avoid having footnote text too small
\renewcommand{\footnotesize}{\small}
% ************** end footnotes' stuff **************

\usepackage{endnotes}              % for things that are best skipped on a first read

%opening
\title{\normalfont\Huge\textbf{title}}
\author{author\\\texttt{authors@email}}
\date{}

% add new commands here

\begin{document}
\maketitle              % need full-width title

\tableofcontents % if needed

(*) technically, what’s shown above goes beyond the preamble, because it starts the document proper. After what’s shown, one would typically add the abstract (“\begin{abstract}”) or the first section (e.g. “\section{Introduction}”).

The babel line is only needed if you’re not writing in English. The hyperref package if it used, must be THE LAST ONE to be included. It is only needed for dumping links into the PDF file that’s produced. (EDIT: it seems hyperref no longer uses the “a4paper” option, so I’ve removed it).

I remove the date from the generated title (hence the empty \date{} command) for reasons explained below. That’s also the reason for the nameless footnote; to add a numberless footnote, do it like this: \symbolfootnote[0]{your comment here}.

Finally, I set as default behaviour for “normal” footnotes (\footnote) to use symbols, and not numbers, because that way I can mixed footnotes with endnotes (which are numbered) without risk of confusion.

You can also do some more fun with the footnotes if you like, but what I’ve shown here does the trick for me (note the extra bold ‘text’, it’s for avoid leaving a mark, or the space for one, in the place in the main text where the footnote was added. Quite useful).

 

Using other fonts

Only works with XeLaTeX!

In the “additional packages” place, write as follows (replace fonts’ names accordingly):

% to add other fonts to document
\usepackage{fontspec}     % only needed if using custom fonts     
\defaultfontfeatures{Mapping=tex-text}

% and now load the fonts proper
\setromanfont [BoldFont={Gentium Basic Bold}, 
ItalicFont={Gentium Basic Italic}]{GentiumBasic} 
\setromanfont [Ligatures={Common}, BoldFont={Fontin Bold}, ItalicFont={Fontin Italic}]{Fontin}
\setsansfont [Ligatures={Common}, BoldFont={Fontin Sans Bold},
ItalicFont={Fontin Sans Italic}]{Fontin Sans}                        
\setmonofont [Scale=0.8]{Monaco}
% --- end code for other fonts ---

 

Permanent Document ID’s

I first came across the usage of unique Document ID’s when I read this paper from Daniel J. Bernstein. He describes it in more detail. I essentially do the same thing, but I use SHA instead MD5 (for no particular reason other than it generates longer ID’s…)

$ head /dev/urandom | sha1sum

I then add it to the first page of the document like this (assuming it’s written in LaTeX):

\symbolfootnote[0]{Date of this document: month day, year. Permanent ID of this document:
\textbf{\texttt{SHA1 generated ID here}}.\\ \\
The author hereby places this document in the public domain.}

 

Installing styles, and what not (Linux)

Here I’ll describe a way of installing LaTeX styles, BiBTeX styles, and a couple of other things in a straightforward way. I think this should work with most *nix systems.

The first thing to do, is discover where whatever you want to install should be installed. And the ideal way to do this is using a tool named kpsewhich, which should get installed when you install LaTeX. It can be used to do a lot of things ($ kpsewhich --help), but the one we’re interested in here, location of styles, uses the --show-path NAME option. The list of allowed names is part of the output of the --help option. So for instance, to discover where to place BiBTeX style files (*.bst), run:


kpsewhich --show-path bst

This will output a list of locations where BiBTeX style files are searched for. So if you have a file called mystyle.bst, create a folder named “mystyle” in the appropriate location (I use /home/user/texmf/bibtex/bst/), and put mystyle.bst inside the folder you just created. Then run “$ texhash .” (don’t forget the dot!) from the “appropriate location” folder you used. And you’re done!

 

Math stuff

That black-filled square that has become synonym of QED, can be done by defining this command (in the preamble):

\newcommand{\qed}{\hfill \mbox{\raggedright \rule{.07in}{.07in}}}

Some environments that can be useful are the following (adapted from here):

\newtheorem{theorem}{Theorem}[section]

\newtheorem{lemma}[theorem]{Lemma}

\newtheorem{proposition}[theorem]{Proposition}

\newtheorem{corollary}[theorem]{Corollary}

\newenvironment{proof}[1][Proof]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newenvironment{example}[1][Example]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

\newenvironment{remark}[1][Remark]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

 

Spacing

Sometimes, in particular with formulas that involve quantifiers, the spacing can be somewhat awkward. Here’s something that can help (straight from here):

In a `math’ environment, LaTeX ignores the spaces you type and puts
in the spacing that it thinks is best. LaTeX formats mathematics the
way it’s done in mathematics texts. If you want different spacing,
LaTeX provides the following four commands for use in math mode:

1. `\;’ – a thick space

2. `\:’ – a medium space

3. `\,’ – a thin space

4. `\!’ – a negative thin space