1

Suppose that I type the following code in to a REPL.

(+ 1 2)
(+ 1 3)

At the end, my REPL looks like

* (+ 1 2)
3
* (+ 1 3)
4

I want the same when exporting org-mode to PDF, but I don't get it. This org

#+PROPERTY: header-args :exports both :eval yes :session global

#+begin_src lisp
(+ 1 2)
(+ 1 3)
#+end_src

gives me this lame PDF.

enter image description here

How can I get more REPL-like output in a PDF? I want every result and I want each result directly under the line that produced it.

0

1 Answer 1

2

Babel is not a REPL: it's more like a batch evaluation environment. If you want your PDF to look like the REPL, then cut and paste from the REPL into an EXAMPLE block. You can also try with :results output and changing the forms to print out results: (print (+1 2)) but it still won't look like the REPL. It will look like what you get when you evaluate the block with C-c C-c.

I guess the closest you can get with Babel is by using a different source block for each form:

#+PROPERTY: header-args :exports both :eval yes

* foo

#+begin_src elisp
    (+ 1 2)
#+end_src
#+begin_src elisp
    (+ 1 3)
#+end_src

There's not much to an example block: you just cut-and-paste from the REPL. There is no automatic evaluation during export: you have to do it beforehand. But you can do arbitrary text this way.

For example, if you run a Guile session in a shell in Emacs, you see the following:

GNU Guile 2.0.14
Copyright (C) 1995-2016 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (+ 1 2)
$1 = 3
scheme@(guile-user)> (+ 2 3)
$2 = 5
scheme@(guile-user)> 

So you can cut-and-paste that whole thing into your Org mode file as an example block:

#+BEGIN_EXAMPLE
GNU Guile 2.0.14
Copyright (C) 1995-2016 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (+ 1 2)
$1 = 3
scheme@(guile-user)> (+ 2 3)
$2 = 5
scheme@(guile-user)> 
#+END_EXAMPLE

and then export to PDF: the example block will be exported literally. The only thing that you have to watch out for is to quote any lines that Org mode might interpret as headlines (because they start with one or more * characters) or keyword lines (because they start with #+) - you quote them by prefixing a , to them. See Literal Examples in the manual. For example, if you run an IELM session, you would get:

*** Welcome to IELM ***  Type (describe-mode) or press C-h m for help.
ELISP> (+ 1 2)
3
 (#o3, #x3, ?\C-c)
ELISP> (+ 2 3)
5
 (#o5, #x5, ?\C-e)
ELISP> 


in which case the first line would have to be so quoted in the EXAMPLE block:

#+begin_example
,*** Welcome to IELM ***  Type (describe-mode) or press C-h m for help.
ELISP> (+ 1 2)
3
 (#o3, #x3, ?\C-c)
ELISP> (+ 2 3)
5
 (#o5, #x5, ?\C-e)
ELISP> 
#+end_example

2
  • May I also see your EXAMPLE block solution?
    – J. Mini
    Commented May 13 at 20:17
  • See edited answer.
    – NickD
    Commented May 14 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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