[Tex/LaTex] xelatex: Minted code block represents tabs as ^^I

mintedxetex

I am producing LaTeX output with org mode. My code snippets wind up being indented with tabs, because of my c-mode settings. Changing these would be inconvenient. Although the snippet I am posting could be compiled with latex, I need to be able to compile Unicode documents, so I am using xelatex -shell-escape to compile the automatically generated latex source.

The generated source looks like this:

Which produces LaTeX like the following (some irrelevant stuff removed, this reproduces the problem):

 \documentclass[11pt]{article}
 \tolerance=1000
 \usepackage{fontspec}
 \usepackage{minted}
 \author{Glen Stark}
 \date{\today}
 \title{sample}
 \begin{document}

 \section{Foo}

 \begin{minted}[]{c++}
 void foo()
 {
     void bar = fb();
     std::cout << "fbar" << "\n"
 }
 \end{minted}
 \end{document}

Compiling this with xelatex -shell-escape results in output like:

void foo()

^^Ivoid bar = fb();

^^Istd::cout //etc.

The whitespace in the minted block is a tab. Obviously xelatex is inserting something funny in place of the tabs. I have a workaround where I force generation of spaces instead of tabs, but this is inconvenient.

Anyone know what the fix/problem is?

Best Answer

The problem is pretty similar to the one described in Tabs in output file written by xelatex and pdflatex are different

The solution should be to call xelatex with the -8bit option:

xelatex -8bit -shell-escape test

Here's the test.tex example I used, to show that two byte characters are honored in comments nonetheless.

\documentclass[11pt]{article}
\usepackage{fontspec}
\usepackage{minted}

\begin{document}

\section{Foo}

\begin{minted}[]{c++}
// comment éßàł
void foo()
        {
                void bar = fb();
                std::cout << "fbar" << "\n"
        }
\end{minted}

\end{document}

(Note: the interface of StackExchange changes tabs to spaces, so change them back for testing.)

enter image description here