I have worked around the problem by customizing org-src-preserve-indentation to true, but by default when I export my code snippets to pdf, My code winds up looking like this:
void foo() { ^I//bla bla bla; } Which is kind of irritating. Anyone know whats going on? I am using xelatex for pdf generation (because of unicode in the sources), and minted for syntax highlighting.
Is there a best way to get beatiful code formatting in my pdf? Can I tell it to use clang-format from within xelatex?
Minumum Sample
It took me a while to make a minimum sample, since the issue is configuration file, not the code snippet. With the following as your .emacs, you should be able to reproduce the failure (you will need xelatex and the fontspec package of course). I apologize that there's some unecessary noise form copy-pasting my custom-set-variables block, but it would have taken some effort for me to extract just the salient
(setq-default c-basic-offset 4 tab-width 4 indent-tabs-mode t) ;; ;; fontify code in code blocks (setq org-src-fontify-natively t) (setq org-latex-listings 'minted) ;; ;; Let the exporter use the -shell-escape option to let latex ;; ;; execute external programs. ;; ;; This obviously and can be dangerous to activate! (setq org-latex-pdf-process '("xelatex -shell-escape -interaction nonstopmode -output-directory %o %f")) (provide 'dotemacs) ;;; dotemacs.el ends here (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(org-latex-default-packages-alist (quote (("T1" "fontenc" t) ("" "fixltx2e" nil) ("" "graphicx" t) ("" "longtable" nil) ("" "float" nil) ("" "wrapfig" nil) ("" "rotating" nil) ("normalem" "ulem" t) ("" "amsmath" t) ("" "textcomp" t) ("" "marvosym" t) ("" "wasysym" t) ("" "amssymb" t) ("" "hyperref" nil) "\\tolerance=1000"))) '(org-latex-packages-alist (quote (("" "fontspec" t) ("" "minted" nil))))) With that, even a trivial (indented) code sample will produce the erroneous results:
* Foo #+BEGIN_SRC C++ void foo() { void bar = fb(); std::cout << "fbar" << "\n" } #+END_SRC (sorry, I don't know how to get an org src block to show up right on this sight). Create an indented source code block to reproduce the error.
Which produces the following LaTeX:
% Created 2015-09-02 Wed 23:17 \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{fixltx2e} \usepackage{graphicx} \usepackage{longtable} \usepackage{float} \usepackage{wrapfig} \usepackage{rotating} \usepackage[normalem]{ulem} \usepackage{amsmath} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} \usepackage{amssymb} \usepackage{hyperref} \tolerance=1000 \usepackage{fontspec} \usepackage{minted} \author{Glen Stark} \date{\today} \title{sample} \hypersetup{ pdfkeywords={}, pdfsubject={}, pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}} \begin{document} \maketitle \tableofcontents \section{Foo} \label{sec-1} \begin{minted}[]{c++} void foo() { void bar = fb(); std::cout << "fbar" << "\n" } \end{minted} % Emacs 24.5.1 (Org mode 8.2.10) \end{document} The whitespace in the minted block is a tab. Obviously xelatex is inserting something funny in place of the tabs. Unfortunately my companies coding standards are tabs not spaces, so it would be inconvenient to change this (more inconvenient than my current workaround).
Anyone know what the fix is?
org-src-preserve-indentationtotif you want to preserve the code indentations; they are anyways preserved. Setting the above var preserves the overall redundant indentation too.M-x org-version).^Iis literallytabsymbol, maybe that particular font cannot render it? In any case, I suspect that you use tabs to indent your code, what if youuntabifyit?