LaTeX Symbols in Verbatim Mode (using UTF8)
Author: When: Wednesday, 17 March 2010April 2009
May 2009
August 2009
September 2009
October 2009
- Building a Concrete Bath
- LED Lighting Comparison
- Thinking about Programming Languages
- How To Be A Consultant
- Lucid Programming Dojo
- Exim4 + ClamAV + SpamAssassin
- Secure login using AJAX
- Ramaze And Rack
- ActiveMerchant
- Concurrency And Immutability
- Floating Point Numbers
- Programming And Debugging
- Useful jQuery Plugins
- Loading Anonymous Ruby Classes
- 尺八 (Shakuhachi)
- Card Trick
- Object Oriented C
- Gemcutter
- Writing Clearly
- Richard Stallman In Christchurch
- Magnatune
- Client Side Graphing
- Zena CMS
November 2009
February 2010
March 2010
April 2010
May 2010
June 2010
July 2010
August 2010
September 2010
December 2010
January 2011
March 2011
May 2011
August 2011
September 2011
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
Please note, you can leave a comment that uses (limited) XHTML and Textile syntax.