Fonts for Math in LaTeX

Similar to fonts for textual content, there are formatting styles or fonts that can be used on math expressions in LaTeX. For example, the set of real numbers R is typically written with what is called a blackboard bold font.

The formatting styles for math in LaTeX are:

mathnormal: This is the default for math expressions. The letters are italicized a bit. No need to apply it explicitly.
mathrm:     Non-italicized version of normal.
mathit:     Italicized like normal, but suits words better.
mathbf:     Bold. Use for vectors and so on.
mathsf:     Sans serif.
mathtt:     Fixed-width.
mathfrak:   Fraktur. Used for lie algebras.
mathcal:    Calligraphic.
mathbb:     Used for real sets.
mathscr:    Script.

A table of these fonts applied on symbols can be seen here.

Tried with: Ubuntu 14.04

Vim-LaTeX plugin for Vim

There are many LaTeX plugins for Vim which can make editing and compiling LaTeX files easier. The most popular among these plugins is Vim-LaTeX. It can be installed from its Github page here using your favorite Vim plugin manager.

The main features I use in Vim-LaTeX is:

  • Compile currently open LaTeX file by typing \ll. Compilation errors are displayed in a buffer below and you can jump to the error line from there.

  • View compiled PDF file by typing \lv.

Tried with: Vim 7.4 and Ubuntu 14.04

How to use LaTeX for text rendering in Matplotlib

By default, Matplotlib does not use LaTeX to render the text in its plots. For certain documents, it may be necessary to use LaTeX for text rendering.

Matplotlib can be requested to use LaTeX using:

from matplotlib import rc
rc('text', usetex=True)

Tried with: Matplotlib 1.3.1 and Ubuntu 14.04

How to specify size of image in LaTeX

An image is inserted into a LaTeX document using the includegraphics command. The size of the image can be specified in a variety of techniques:

  • Specify height or width or both in terms of cm:
width=5cm

height=3cm

width=3cm, height=10cm
  • Specify width as fraction of width of text column:
width=0.9\linewidth

width=0.7\textwidth
  • Specify scale of image:
scale=0.5

Tried with: Ubuntu 14.04

How to convert LaTeX to HTML

The LaTeX2HTML tool can be used to convert any LaTeX document into HTML format. It generates HTML pages in the form of a book. All mathematical symbols and equations are converted into images.

Install the LaTeX2HTML package:

$ sudo apt install latex2html

Convert LaTeX to HTML:

$ latex2html foo.tex

Open the generated HTML file in browser:

$ xdg-open foo/index.html

Tried with: Ubuntu 14.04

How to add subfigures using subfigure package

Multiple figures are sometimes arranged together in a single figure in a paper or book written in LaTeX. This can be done using subfig and subfloat packages. I recently discovered the subfigure package which can be used to achieve the same with less code!

Below is LaTeX code to arrange three subfigures in two rows, one figure in top row and two figures in bottom row:


% Arrange three figures like this:
% Fig 1
% Fig 2 Fig 3
\begin{figure}
\centering
\subfigure[]
{
\includegraphics[scale=.2]{foo1.pdf}
}
\\
\subfigure[]
{
\includegraphics[scale=.5]{foo2.pdf}
}
\qquad
\subfigure[]
{
\includegraphics[scale=.26]{foo3.pdf}
}
\caption
{
(a) blah
(b) blah
(c) blah
}
\label{fig:foobar}
\end{figure}

Tried with: Ubuntu 14.04

How to create index in LaTeX

If you are writing a report or a book using LaTeX, it might be a good idea to generate an index or glossary of key terms at the end. The typical method to do this is using the makeidx package. Place its makeindex command in the preamble at the beginning of the document to indicate that an index should be generated. Use the index command and pass it the name of the index entry whenever a key term is used. Finally, place the printindex command at the end of the document to print the generated index at that location.


% In the preamble
\usepackage{makeidx}
\makeindex
% Whenever a key term is defined or used
\index{normal distribution}
\index{poisson distribution}
% At end of document
\printindex

view raw

index.tex

hosted with ❤ by GitHub

Tried with: Ubuntu 14.04

Document classes for book in LaTeX

Here are some of the document classes that can be used to create a book using LaTeX:

Book

The default class. Looks dated and ugly.

documentclass{book}

Memoir

Looks modern. Better than the default book.

documentclass{memoir}

AMSBook

Looks good, but can only be used for math books. This is because all headings are centered (not left-aligned) and all text is center-justified too.

documentclass{amsbook}

ScrBook

This is from the European designed KOMA package which looks modern and the fonts are nice. While their article class is nice, I did not like the book class that much.

documentclass{scrbook}

Tufte-LaTeX

Using this gave me compilation errors which I could not resolve. Thats a pity because this style looks almost like the books from Tufte.

Bookest

Beautiful book class and my favorite.

documentclass{bookest}

Octavo

Produces beautiful pocket books.

documentclass{octavo}

Caesar

Another nice looking book class.

documentclass{caesar_book}