[Tex/LaTex] Using minted and tabs

mintedxetex

I just started using the minted package. When I insert tabs as indentation, it gives me a bunch of characters instead:

enter image description here

However, when I copy the example from the documentation it seems to work fine. I tried experimenting with the obeytabs and showtabs options but I can't get rid of the characters. I'm using xelatex with TexLive 2011 in TexShop. All files are up to date.

Here's a MWE (please note as pointed out in the comments that the indentation in the code is supposed to be tabs and not spaces):

\documentclass{article}

\usepackage{minted}
\newminted{python}{linenos}

\begin{document}

\begin{minted}[linenos]{python}
def all(iterable):
    for i in iterable:
        if not i:
            return False
    return True
\end{minted}

\end{document}

Edit: I noticed something strange: When I change the typesetting engine back to pdflatex, it seems to be working, but then I can't load the fontspec package. So I guess this is related to xelatex?

I'm using xelatex --file-line-error --shell-escape --synctex=1

Best Answer

This looks like a manifestation of the problem discussed in this question – xe(la)tex has a bug that makes it write tabs incorrectly. The fix discussed there is to pass the -8bit command-line option to xelatex. It is said (by someone who seems pretty knowledgeable) here that "this may have adverse effects on the writing of aux files," but I am not sure what those may be.