11

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?

0

2 Answers 2

9

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

5
  • @ComFreek I get unrecognized option `-enable-8bit-chars' on TeX Live.
    – egreg
    Commented Jun 12, 2019 at 18:03
  • It seems you only typed one dash. Does it work with two?
    – ComFreek
    Commented Jun 13, 2019 at 6:03
  • @ComFreek No, it doesn’t. TeX Live programs accept one or two hyphens. I think it’s only a MiKTeX option.
    – egreg
    Commented Jun 13, 2019 at 8:08
  • xelatex -8bit -shell-escape worked for me.
    – Jason
    Commented Aug 24, 2020 at 2:04
2

The -8bit option doesn't work for me, it just causes xelatex to throw up a compilation error when processing the .pygtex auxiliary file that I can't resolve. What does work for me is saving my function into its own source code file and using the \inputminted command to import into latex:

\inputminted{c++}{foo.cpp}

Whitespace characters are then represented correctly.

You must log in to answer this question.

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