LaTeX Symbols in Verbatim Mode (using UTF8)

Author: When: 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:




[S]: (∅ ∅ ∅ ∅)


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.


Leave a comment

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