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.

I'm writing a report about a website I'm working on to play cards online. I use lstlisting to display my PHP, JavaScript and HTML code. The problem is that I'm using a lot of µ's in my JavaScript codes. For example:

\begin{lstlisting}[caption=some code]
  µ.a('error', µ.m('Server responded: ' + r));
\end{lstlisting}

I use the micro symbol because i wanted to have a shortcut for certain functions.

Now, the problem is that LaTeX won't compile these µ's. As output I get to see .a('error', .m('Server responded: ' + r)); LaTeX simply seems to ignore those µ's. I tried to fix this by using:

\usepackage[utf8x]{inputenc}

but this leads to an error: Package utf8x Error: Character181appearedalone.

Any toughts on how to fix this? Thanks!

share|improve this question
    
Is xelatex/lualatex + fontspec an option? If so, all problems should just go away (no inputenc required) –  Mikael Öhman Apr 24 '12 at 15:38
    
I'm sorry, I'm relatively new to LaTeX. Are these things just packages or ... ? EDIT: I'm using MikTeX, and doesn't that have XeTeX included? –  Sebastian Apr 24 '12 at 15:48
    
It is possible, I had the same problem displaying \alpha and \beta. I hope I still have the source of this old report, just a sec... Edit: found it, you can use \begin{lstlisting}[escapechar=\#] and then #$\alpha$# or #$\mu$# in your case. –  Ailurus Apr 24 '12 at 16:09
    
But then I'd have to change all my appearances of µ in my code, wouldn't I? –  Sebastian Apr 24 '12 at 16:18
add comment

1 Answer

up vote 7 down vote accepted

(pdf)latex solution:

If you use the symbol µ only inside lstlisting you can use the option literate.

Here an example

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage{upgreek}

\begin{document}
\begin{lstlisting}[caption=some code,literate={µ}{$\upmu$}1]
  µ.a('error', µ.m('Server responded: ' + r));
\end{lstlisting}
\end{document}

enter image description here

share|improve this answer
    
Thanks, this actually does the trick! I already tried something with literate, but that didn't work, but your code does. :) Of course it would be handier to just use µ everywhere in my document, and not only inside lstlisting, but that can be easily fixed with \textmu I assume. –  Sebastian Apr 24 '12 at 16:17
2  
@Sebastian: You can also use it inside the document body. Therefor you should have a look at this question: tex.stackexchange.com/questions/28031/… –  Marco Daniel Apr 24 '12 at 16:20
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.