Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Is everything written unicode? or just the attachments? –  Johan Aug 20 '10 at 6:44
    
Just the stuff to be verbatimized. My latex code is plain old ascii. –  Adam Aug 20 '10 at 12:12
add comment

3 Answers

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.

share|improve this answer
1  
Unfortunately the arXiv won't accept anything other than latex or pdflatex. –  Adam Sep 18 '10 at 21:25
add comment

I usually do like this:

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

{\scriptsize \verbatiminput{fileToInput.txt}}

Maybe \verbatiminput does the work for you?

/Have fun

share|improve this answer
    
! Package inputenc Error: Unicode char \u8:⟨ not set up for use with LaTeX. –  Adam Sep 18 '10 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 '10 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 '10 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 '10 at 6:34
    
Johan, please look more carefully! Those aren't curly braces. –  Adam Sep 23 '10 at 16:51
show 4 more comments

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}}
share|improve this answer
    
Welcome to TeX.SX! –  Papiro Jun 12 '13 at 17:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.