14

A lot of leading-edge programming languages (like Coq and Agda) allow nearly unrestricted use of unicode symbols in program text, so you can have math characters like $\otimes$ (Unicode U+2A02) as operators in your program.

I'd like to be able to cut and paste these programs directly into my LaTeX documents inside a verbatim-like environment and get a reasonable result. For various reasons I can't use the listings environment -- I need the typeset output to look the same as the program looks on the computer screen, even if the listings package would make it "prettier".

Unfortunately the computer modern typewriter (cmtt) font, which I really like a lot, doesn't have math symbols, but there ought to be some package that acts like verbatim using cmtt wherever possible and falls back to the math fonts when it encounters a unicode symbol that isn't in cmtt.

A package like this would probably require a major effort to "line up" the unicode math symbols with the Latex Symbols List, but once a table like that were to be compiled it would be really, really useful!

So, I guess my question is in two parts: has anybody compiled such a table, and (more importantly) has anybody used it to produce a verbatim that makes a "reasonable effort" at handling unicode math characters?

2
  • Is everything written unicode? or just the attachments?
    – Johan
    Aug 20, 2010 at 6:44
  • Just the stuff to be verbatimized. My latex code is plain old ascii.
    – Adam
    Aug 20, 2010 at 12:12

3 Answers 3

11

I recommend using either XeLaTeX or LuaLaTeX and loading an appropriate Unicode font for the verbatim that requires those symbols. pdfLaTeX won't cut it in this case, I'm afraid.

1
  • 3
    Unfortunately the arXiv won't accept anything other than latex or pdflatex.
    – Adam
    Sep 18, 2010 at 21:25
1

The question is now answered. If there aren't many symbols, you can use newunicodechar package to manually map unicode characters to LaTeX code.

\usepackage{newunicodechar}
\newunicodechar{⟨}{\ensuremath{\langle}}
0
0

I usually do like this:

\usepackage[utf8]{inputenc}
\usepackage{verbatim}

{\scriptsize \verbatiminput{fileToInput.txt}}

Maybe \verbatiminput does the work for you?

/Have fun

9
  • ! Package inputenc Error: Unicode char \u8:⟨ not set up for use with LaTeX.
    – Adam
    Sep 18, 2010 at 21:27
  • en.wikipedia.org/wiki/List_of_Unicode_characters tells us that U+0008 = Backspace. What are you trying to include?
    – Johan
    Sep 20, 2010 at 8:29
  • 1
    The "8" isn't the character code; it's just part of how latex prints error messages. The actual character is "⟨" which is 2329 "left pointing angle bracket" (look just after the colon).
    – Adam
    Sep 22, 2010 at 18:40
  • But then something is really fishy, since I have include a lot of code that had { and } in them...
    – Johan
    Sep 23, 2010 at 6:34
  • Johan, please look more carefully! Those aren't curly braces.
    – Adam
    Sep 23, 2010 at 16:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .