scimax icon indicating copy to clipboard operation
scimax copied to clipboard

formatting of results block and linebreaks in subsequent latex export

Open uliw opened this issue 5 years ago • 4 comments

Hi John,

if i evaluate the following inside a buffer

#+BEGIN_SRC python
print("text 1")
print("text 2")
#+END_SRC

I obtain

#+RESULTS:
: text 1
: text 2

which exports to latex preserving the line break between text1 and text2, i.e.,

text1
text2

If I do the same with

#+BEGIN_SRC ipython
print("text 1")
print("text 2")
#+END_SRC

I get

#+RESULTS:
:results:
# Out [2]: 
# output
text 1
text 2

:end:

which when exported to latex yields

text1 text2

is there a way or a switch to preserve the line breaks?

Cheers

Uli

uliw avatar Jan 13 '20 21:01 uliw

I think you are seeing this because the default for ipython is set to be drawer, which is not what you want. You can remove that with this:

#+BEGIN_SRC emacs-lisp (setf (cdr (assoc :results org-babel-default-header-args:ipython)) "output replace") #+END_SRC Then, you should get the output you want.

#+BEGIN_SRC ipython print("text 1") print("text 2") #+END_SRC

#+RESULTS: : # Out [2]: : # output : text 1 : text 2 :

jkitchin avatar Jan 14 '20 00:01 jkitchin

Awesome!

Out of curiosity, why does

#+BEGIN_SRC ipython :results output replace

fail to achieve the same result?

Cheers & Thanks!

Uli

On Mon, Jan 13, 2020 at 8:00 PM John Kitchin [email protected] wrote:

I think you are seeing this because the default for ipython is set to be drawer, which is not what you want. You can remove that with this:

#+BEGIN_SRC emacs-lisp (setf (cdr (assoc :results org-babel-default-header-args:ipython)) "output replace") #+END_SRC Then, you should get the output you want.

#+BEGIN_SRC ipython print("text 1") print("text 2") #+END_SRC

#+RESULTS: : # Out [2]: : # output : text 1 : text 2 :

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jkitchin/scimax/issues/331?email_source=notifications&email_token=ABWSVAWPJFRSZ6FXES2VC7LQ5UFA3A5CNFSM4KGJOPU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEI237GQ#issuecomment-573947802, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWSVAQVPI2DCVJ44OAIX5TQ5UFA3ANCNFSM4KGJOPUQ .

-- Ulrich G. Wortmann http://www.es.utoronto.ca/people/faculty/wortmann-ulrich/ http://webcan.es.utoronto.ca/people/faculty/wortmann-ulrich/ Dept. of Earth Sciences Fax : 416 978 3938 University of Toronto Phone: 416 978 7084 22 Russell Street, Toronto, ON, Canada M5S 3B1

uliw avatar Jan 14 '20 14:01 uliw

never mind, I realize that #+BEGIN_SRC ipython :results output pp replace

will do what I need to do.

Cheers

Uli

On Tue, Jan 14, 2020 at 9:21 AM Ulrich G. Wortmann [email protected] wrote:

Awesome!

Out of curiosity, why does

#+BEGIN_SRC ipython :results output replace

fail to achieve the same result?

Cheers & Thanks!

Uli

On Mon, Jan 13, 2020 at 8:00 PM John Kitchin [email protected] wrote:

I think you are seeing this because the default for ipython is set to be drawer, which is not what you want. You can remove that with this:

#+BEGIN_SRC emacs-lisp (setf (cdr (assoc :results org-babel-default-header-args:ipython)) "output replace") #+END_SRC Then, you should get the output you want.

#+BEGIN_SRC ipython print("text 1") print("text 2") #+END_SRC

#+RESULTS: : # Out [2]: : # output : text 1 : text 2 :

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jkitchin/scimax/issues/331?email_source=notifications&email_token=ABWSVAWPJFRSZ6FXES2VC7LQ5UFA3A5CNFSM4KGJOPU2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEI237GQ#issuecomment-573947802, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWSVAQVPI2DCVJ44OAIX5TQ5UFA3ANCNFSM4KGJOPUQ .

-- Ulrich G. Wortmann http://www.es.utoronto.ca/people/faculty/wortmann-ulrich/ http://webcan.es.utoronto.ca/people/faculty/wortmann-ulrich/ Dept. of Earth Sciences Fax : 416 978 3938 University of Toronto Phone: 416 978 7084 22 Russell Street, Toronto, ON, Canada M5S 3B1

-- Ulrich G. Wortmann http://www.es.utoronto.ca/people/faculty/wortmann-ulrich/ http://webcan.es.utoronto.ca/people/faculty/wortmann-ulrich/ Dept. of Earth Sciences Fax : 416 978 3938 University of Toronto Phone: 416 978 7084 22 Russell Street, Toronto, ON, Canada M5S 3B1

uliw avatar Jan 14 '20 15:01 uliw

For some reason, #+BEGIN_SRC ipython :results output replace does not overwrite all the elements, where as your example does.

This is the default

#+BEGIN_SRC ipython
(assoc :result-params (nth 2 (org-babel-get-src-block-info)))
#+END_SRC

(:result-params "drawer" "replace" "output")

this doesn't change the drawer
#+BEGIN_SRC ipython :results output replace
(assoc :result-params (nth 2 (org-babel-get-src-block-info)))
#+END_SRC

(:result-params "replace" "output" "drawer")

This does replace the drawer
#+BEGIN_SRC ipython :results output replace pp
(assoc :result-params (nth 2 (org-babel-get-src-block-info)))
#+END_SRC

(:result-params "pp" "replace" "output")

In the last case, pp is a different format (https://orgmode.org/manual/results.html) so it overwrites drawer.

I am not sure if I consider this a bug or not, I sort of do.

jkitchin avatar Jan 14 '20 22:01 jkitchin