## Drawing power crosses in LaTeX

Posted: 10th September 2015 by Tim in LaTeX, Optics
Tags: , , , , , , , ,

Power crosses are useful diagrams for doing lens power calculations in optics. Drawing the power crosses in LaTeX can be tedious, especially if you need to draw multiple power crosses in the same document. The code below creates a new command, \powercross{front@90}{front@180}{back@90}{back@180}, which will draw the power crosses for you and calculate the final lens […]

## Printing zero-padded numbers in Python

Posted: 28th December 2014 by Tim in Python
Tags: , , , , , ,

There are a number of ways to print a number with zero-padding (leading zeros), depending on the variable type you are wanting to print. One easy way to add zero padding to any type is to use the str(<number>).zfill(<length>). This will convert any number type to a string before adding the extra zeros. For example: […]

## Disabling auto indent in Vim

Posted: 12th October 2014 by Tim in Vim
Tags: , , , , , , ,

Auto indent is disabled by default in Vim, but some systems have this feature enabled in the system-wide vimrc file (found in /usr/share/vim/vimrc or a similar location). There are two ways to disable this: remove the system-wide setting, or remove the setting for your user only. To remove the setting system-wide, search for and remove […]

## Writing kanji with furigana (hiragana) above in LaTeX

Posted: 28th December 2012 by Tim in Japanese, LaTeX
Tags: , , , , , , , , , , , ,

When using kanji in a document which is non-standard or rare, it is common for hiragana or katakana characters to be printed above (or beside for vertical text) the kanji to aid pronunciation. This is also common in children’s books and other Japanese learning material. This post explains how to do that using LaTeX. This […]

## Small caps in LaTeX

Posted: 21st January 2012 by Tim in LaTeX
Tags: , , , , ,

Writing text in smallcaps in LaTeX is quite easy – just wrap your text in the \textsc{<text>} tag. For example: \textsc{This text is in small caps} Will create This text is in small caps

## Adding music notation to LaTeX with LilyPond

Posted: 27th December 2011 by Tim in LaTeX, LilyPond
Tags: , , , , , , , , , , ,

Ever wanted to add some music to a document? It’s not really a big feature for most word processors and most solutions involve creating an image using some third party software and copying that image into the document. The idea is the same in LaTeX, but it’s much easier to manage. LilyPond is a free […]

## Math case definitions in LaTeX

Posted: 12th December 2011 by Tim in LaTeX
Tags: , , , , , , , , , ,

When writing a math definition of a function, for example, the function may have different results depending on the value of the inputs. These are called cases and are grouped together with a large left curly brace. If you’re trying to typeset this in LaTeX, the cases environment makes this nice and easy. It’s easiest […]

## Adding text in math mode in LaTeX

Posted: 4th December 2011 by Tim in LaTeX
Tags: , , , , , ,

Occasionally you’ll want to add some text to a maths equation in LaTeX. By default, any text is written in italics, and white space is ignored. The solution is quite simple; put the text in a \text{…} block like so: $$x = \sqrt{x^2} \text{ : where x is positive}$$ As you can see, you can […]

## Using colors in LaTeX

Posted: 21st October 2011 by Tim in LaTeX
Tags: , , , , , , , , ,

If you want to add a bit of color to your LaTeX document, you can do this quite easily with the color package. This package works with both pdflatex and latex and gives you the following color options: blue cyan green magenta red yellow To use the colors, simply include the color package and wrap […]

## Using gnuplot with LaTeX

Posted: 28th July 2011 by Tim in Gnuplot, LaTeX
Tags: , , , , , , , , , , ,

Gnuplot is a great tool for creating plots. LaTeX is a great tool for creating documents. Both are (or at least can be) created using a text editor and compiling the source. Both work with Windows, linux/unix and Mac. Wouldn’t it be great if you could include a gnuplot plot in a LaTeX document without […]

## LaTeX table and figure numbering style

Posted: 18th July 2011 by Tim in LaTeX
Tags: , , , , , , , , , , ,

In LaTeX, by default, tables are numbered Table 1, Table 2, Table 3 an so on (or Table 1.1, Table 1.2, Table 2.1, etc if you’re using chapters). Sometimes you may want to change the way these are numbered. The solution is very similar to changing list numbering styles using different keywords. Like enumeration lists, […]

## Definition list in LaTeX

Posted: 14th June 2011 by Tim in LaTeX
Tags: , , , , , , , ,

If you want to include a glossary, definitions or some other descriptive list in your LaTeX document, you can make use of the description list type. This is a lot like the other list types except that \item can take an argument, the item `name’, in square brackets (ie: \item[Tim Murphy] Author of http://timmurphy.org). In […]

## LaTeX align right or left

Posted: 24th April 2011 by Tim in LaTeX
Tags: , , , , , ,

Occasionally you may want to have text right-aligned in a LaTeX document. Other times you may want a block of left-aligned text next to a block of right-aligned text. LaTeX provides this functionality with the \hfill keyword. \hfill is a horizontal fill keyword. It tells LaTeX that you want to expand the space between the […]

## Using an organisation name as an author in BibTeX

Posted: 15th February 2011 by Tim in LaTeX
Tags: , , , , , , ,

BibTeX is great in that it ensures all of the entries are output in the same style. The most noticeable formatting change is the Author field; John Smith becomes Smith, J for example. Useful, unless your author is not a normal name. Let’s say that you’ve got an article written by the Reserve Bank of […]

## Splitting up LaTeX documents

Posted: 14th November 2010 by Tim in LaTeX
Tags: , , , , , , ,

If you’re writing a large LaTeX document like a book or a thesis, you probably don’t want to have the whole thing in one massive file. It’s the same principle as general programming; splitting the program into smaller components makes it easier to work with, maintain and test. In Microsoft Word you can do this […]

## My third LaTeX document

Posted: 30th August 2010 by Tim in LaTeX
Tags: , , , , , , , , , , , , , , , , ,

This tutorial is for those who have gone through the first and second LaTeX tutorials, and should give you the knowledge required to understand more specific LaTeX tips both on this site and on other websites. This tutorial will cover Packages and the basics of math mode. Packages Much like in programming, additional functionality can […]

## Drawing pictures in LaTeX

Posted: 20th August 2010 by Tim in LaTeX
Tags: , , , , , , , , , , , , , , , , , ,

LaTeX has the ability to draw images out of the box. The drawing functionality is pretty basic — lines, circles, boxes and the like — but perfect for most simple diagrams. This tutorial will be split into three sections: configuring the environment, different ways of drawing shapes, and a description of the shapes themselves. Configuring […]

## Headers and Footers in LaTeX using fancyhdr

Posted: 7th August 2010 by Tim in LaTeX
Tags: , , , , , , , , , ,

There are a number of ways to change the document header and footer styles in LaTeX. One of the easiest and most flexible options is to use the fancyhdr package. fancyhdr is a massive package with a crazy number of tweaks and modifications available for your document’s header and footer styles. This tutorial will only […]

## Changing itemize bullet styles in LaTeX

Posted: 5th July 2010 by Tim in LaTeX
Tags: , , , , , , , , , , , ,

Latex allows the creation of itemized (unordered) lists up to four deep. The numbering styles for each depth can be styled to suit your needs using the \renewcommand{label}{style} command, where label is the list depth being styled and style is how you want that number to be shown. label may be any of the following: […]

## Adding a two-column section to a LaTeX document

Posted: 23rd June 2010 by Tim in LaTeX
Tags: , , , , ,

There are times when you want to have multiple columns on part of a page. You could use tables to get such a layout, but that’s a bit dirty. A nice, clean method is to use the minipage environment. Minipages are defined with a width parameter. If you have multiple minipages defined immediately after each […]

## LaTeX length units

Posted: 26th May 2010 by Tim in LaTeX
Tags: , , , , , , , , , , ,

There are many configurations and commands in LaTeX which require lengths to be set. The following length units can be used: in – imperial inch pt – point (1/72 of an inch) cm – metric centimeter mm – metric millimeter em – width of a capital “M” in the current font settings ex – width […]

## Union and Intersection symbols in LaTeX

Posted: 22nd May 2010 by Tim in LaTeX
Tags: , , , , , , , , , ,

Union (∪) and Intersection (∩) symbols in LaTeX can be produced via the \cup and \cap definitions while in math mode. No extra packages are required to use these symbols. For example: Let $L_C = L_A \cap (L_B \cup L_C)$ will produce:

## My second LaTeX document

Posted: 16th May 2010 by Tim in LaTeX
Tags: , , , , , , , , , , , , , , ,

This tutorial is for those who have gone through the first tutorial. Here we will cover new lines and paragraphs, comments, font decoration (bold, italic and underline) and sections. Fun. New lines and paragraphs First we will look at paragraphs. In LaTeX, having a new line in your .tex file (which we will refer to […]

## Math blackboard (double-barred) font in LaTeX

Posted: 28th April 2010 by Tim in LaTeX
Tags: , , , , , , , , , , ,

In math, certain blackboard (double-barred) letters Z, N, R, etc. represent sets of numbers (integers, natural numbers, rational numbers, etc). These can be included in a LaTeX document using the \mathbb{[letter]} tag from within the math environment. Note that this requires the amssymb package to be included (ie: add \usepackage{amssymb} to the top of the […]

## Underline text in LaTeX

Posted: 13th April 2010 by Tim in LaTeX
Tags: , , , , ,

Underlining text in LaTeX is very easy – simply wrap the text with \underline{text}. For example, The cake was \underline{huge}. will produce: The cake was huge.