3

I am testing out the Babel feature in org-mode, with this small block.

#+BEGIN_SRC sh :results verbatim :exports both                                                     
banner -w 35 e                                                                                                                  
#+END_SRC                                                                                                                          

#+RESULTS:                                                                                                                         
:              #####                                                                                                               
:            #########                                                                                                             
:          ####  #   ###                                                                                                           
:          #     #     ##                                                                                                          
:         ##     #      #                                                                                                          
:          #     #     ##                                                                                                          
:          #     #   ###                                                                                                           
:            #   #####                                                                                                             

(The banner command writes an ASCII art heading. So in this example I'm just printing out an e, sideways. The leading whitespace characters are all spaces.)

I try to export this to TeX, and in the TeX file I see that some of the leading spaces have been replaced with tabs; namely any group of 8 spaces gets replaced with a tab. Therefore the lines don't show up properly when the TeX is exported to PDF. I had a look at the source code of org and I found that it might be org-trim causing this. There's also the option org-src-preserve-indentation, but that doesn't seem to act on the output of the source code, only the source itself. Can I stop org from converting the whitespaces to tabs?

EDIT: Just tried sed 's/<tab-character>/ /g' on the TeX file to replace each tab with 8 spaces, and the problem is fixed immediately. So org must be changing them somewhere, I just need to know where...

EDIT #2: Apparently there is some normalizing going on that might be the issue. Listing here for reference.

3

This usually fixes for me so LaTeX comes out fine:

(setq org-src-preserve-indentation nil 
      org-edit-src-content-indentation 0)

Also, you could use this instead of sed:

M-x untabify
  • Thanks for the tip on untabify. I set the variables at the top of the .org file with # -*- org-src-preserve-indentation: nil; org-edit-src-content: 0; -*- and reloaded the buffer, but this doesn't seem to change the exported TeX. – Charles Jun 30 '16 at 6:16
  • @Charles, I usually set those types of variables in my init file and load them before org is loaded. I do not know if that makes any difference in your case. – Emacs User Jun 30 '16 at 16:55
  • Hold on, shouldn't org-src-preserve-indentation in your answer be set to t? The manual says, By default, the value is nil, which means that when code blocks are evaluated during export or tangled, they are re-inserted into the code block, which may replace sequences of spaces with tab characters. ***When non-nil, whitespace in code blocks will be preserved during export or tangling, exactly as it appears.*** – Charles Jun 30 '16 at 17:05
  • 0 is non-nil. – Emacs User Jun 30 '16 at 17:36
  • I'm talking about org-src-preserve-indentation, which, in your answer, you recommended to set as nil. It turns out that setting it to t fixes the TeX output! Now it's just that TeX "normalizes" the whitespace by deleting it in rectangular vertical chunks. But I think I have almost solved it. – Charles Jun 30 '16 at 23:10
0

Doing the simple

(setq indent-tabs-mode nil)

fixed it for me...

Org mode doesn't really like tabs anyway, it seems, so this works just fine.

EDIT: Nope nope nope I'm an idiot. But this worked for me, at least (I use two space tabs, change that as necessary):

org-latex-pdf-process '("sed -ie 's/    /  /g' %f"
                        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
                        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
                        "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f")
  • What are you doing with this code? Are you setqing a variable, or calling the function? You can just delete your currently-commented-out text if it's not an answer. – zck Feb 20 '17 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.