Posts Tagged ‘code’

There are a few ways to do this, but one of the simplest ways to pretty-print code in LaTeX documents is to use the listings package. The package can be configured to use specific colors for different parts of the code, with many programming languages supported. The following document will display code for both C++ […]

Namespace Alias in C++

Posted: 26th November 2013 by Tim in C++
Tags: , , , , , ,

Sometimes you may find yourself working with namespaces which are really long to type. Writing out the whole namespace can be tedious and make the code harder to read, and using use namespace can sometimes make the code ambiguous (and is discouraged by some coding guidelines). The solution to this is to create a namespace […]

C++ can be a strange language. Most of the time it’s easy to work with, but occasionally you’ll get errors which take forever to debug. Take a look at the following code and write down what you think the output will be. #include <iostream> class Base { public:     virtual void test(int x = 0)     { […]

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 […]

Verbatim in LaTeX

Posted: 5th November 2009 by Tim in LaTeX
Tags: , , , , , ,

If you’re adding a section to a LaTeX document which has a lot of special characters (such as code, HTML, etc), you can add it verbatim. This means that special characters (<, >, {, }, $, etc) will not be processed and will be displayed as they are. There are two ways of printing verbatim. […]

Millisecond timer in C / C++

Posted: 18th October 2009 by Tim in C, C++
Tags: , , , , , , , ,

If you’re looking for a timer with fairly good accuracy in C or C++, you can use the functions in time.h and sys/time.h to build a millisecond timer. This is useful for things like evaluating the execution time of a program, roughly accurate to the nearest microsecond. double get_time_ms() { struct timeval t; gettimeofday(&t, NULL); […]

LaTeX Footnotes

Posted: 1st September 2009 by Tim in LaTeX
Tags: , , , , ,

Adding footnotes to LaTeX is very easy. LaTeX will figure out which page to place the footnote on, correctly number the footnote and so on – all you have to do is provide the text using the \footnote{footnote text} command. For example: Michelangelo’s statue of David is one of the best known sculptures of the […]