Samuel Williams Wednesday, 17 March 2010

LaTeX is a great tool for putting together documents. However, sometimes it can be a little bit tricky to get exactly what you want.

Recently, I wanted to use the verbatim mode for the output of a program run on the command line. However, this included UTF8 symbols. These symbols didn't show up in the verbatim mode, and using the equivalent symbol \O didn't work either. I found a way around this, by using the utf8 package:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\DeclareUnicodeCharacter{2205}{\O}

\begin{document}

\begin{verbatim}
[S]: (∅ ∅ ∅ ∅)
\end{verbatim}

\end{document}

The resulting document is exactly what we expect — the correct symbols are substituted in verbatim mode.

The main trick is \DeclareUnicodeCharacter which takes a Unicode character code-point, in this case the code point for ∅ is 2205, and defines it to be one of the standard LaTeX symbols. You can do this for whatever symbols you require.

Comments

Leave a comment

Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g. <www.codeotaku.com>.