# Blank lines after org-mode code block results in LaTeX export

Context I am embedding org-mode source code blocks and their results into my document and am exporting it to LaTeX. I usually wrap the output of my code into helper functions that generate formatted LaTeX code, for example equation environments or TikZ graphics.

Question Unfortunately I stumbled over blank lines after the results block leading to new paragraphs in the LaTeX document. Do you see a reasonin org-mode for this behauvior?

Related On StackOverflow there is a question regarding newline characters at the end of each python print invocation but this does not resolve the issue:

StackOverflow: Print to the same line and not a new line in python

Modifying the end paramter of print does only insert abc before the newline but is not replacing it.

print('\$$c+d\$$', end='abc'),


Minimum working example:

#+TITLE: Blank lines after source block results on export

* Example
In this example I would like to show that exporting a paragraph with
the embedded two source blocks
#+BEGIN_SRC python :exports results :results output latex
print('\$$a+b\$$')
#+END_SRC
and
#+BEGIN_SRC python :exports results :results output latex
print('\$$c+d\$$')
#+END_SRC
will result in blank lines after the result listing in the exported
LaTeX document.


LaTeX export:

\section{Example}
In this example I would like to show that exporting a paragraph with
the embedded two source blocks
$$a+b$$

and
$$c+d$$

will result in blank lines after the result listing in the exported
\LaTeX{} document.


Instead it should be exported as follows:

\section{Example}
In this example I would like to show that exporting a paragraph with
the embedded two source blocks
$$a+b$$
and
$$c+d$$
will result in blank lines after the result listing in the exported
\LaTeX{} document.


I really have no idea where to look for this issue. That's why I have the hope that you can help me with this. Thank you!

• Your MWE produced different results for me via org-latex-export-as-latex, do you have a variable set somewhere that asserts that equations must be exported? They are simply ignored at export time on my system. – Joe Corneli Jun 8 '15 at 22:18
• OK, I can reproduce the behavior you described if I evaluate: (org-babel-do-load-languages 'org-babel-load-languages '((python . t))) (setq org-confirm-babel-evaluate nil). – Joe Corneli Jun 8 '15 at 23:05
• It doesn't seem to be specific to python, I can reproduce the same behavior with an emacs-lisp :exports results :results value latex block containing (print "foo"). – Joe Corneli Jun 8 '15 at 23:46

After looking under the hood of org-mode, here's what I'd suggest.

Comment out Line 1987 in the current/latest version ob-core.el, evaluate, test, and if you like what you see, don't forget to byte compile.

If you are using a different version of Org, the line is part of the function org-babel-where-is-src-block-result, and it reads as follows:

(unless beg (insert "\n") (backward-char))


If you want a cleaner solution, there is probably another function you could advise. But I'll leave you to find that; now you know where the newline comes from.

### method

Maybe useful for you to know how I went about it. I dug into the export routines, starting with org-latex-export-as-latex, until I found the ob-core.el file. There are lots of newlines introduced there. To pinpoint which was responsible, I replaced each "\n" with some "N\n" (where N is a counting number) then reran the export.

• Oh my god, thank you very much! Replacing ´"\n"´ by ´""´ resolves the issue! :) :) – Christoph Jun 9 '15 at 9:16
• I will try to improve my debugging capabilities, such that I can find it myself next time. Thank you again :) – Christoph Jun 9 '15 at 9:17