Demonstrate inline-src block-behavior and the {{{results( )}}} macro. The `demo' src block sets up an inline-src-block, calls it, then exports the result. The output is as follows: - inline-src-block :: inline-src-block with headers and content. - export backend :: Which backend was used to render the result. - result :: What the ~*.org~ buffer looks looks like after babel executes the inline-src-block. If an error stops execution, the phrase 'Stopped for Error' is shown after the inline src block. - exported as :: Show the exported version (starting on the next line). If an error stops execution, the phrase 'Stopped for Error' is shown. * :results replace (default) #+name: demo #+BEGIN_SRC emacs-lisp :var str="replace" bkend="ascii" contents="42" (let ((cmd (format "src_emacs-lisp[:results %s]{%s}" str contents))) (concat "inline-src-block: " cmd "\nexport backend: " bkend "\nresult: " (with-temp-buffer (insert cmd) (or (ignore-errors (org-babel-execute-buffer)) (progn (goto-char (point-max)) (insert "Stopped for Error"))) (buffer-string)) "\nexported as:\n" (or (ignore-errors (org-export-string-as cmd (intern bkend) t)) "Stopped for Error"))) #+END_SRC #+RESULTS: demo : inline-src-block: src_emacs-lisp[:results replace]{42} : export backend: ascii : result: src_emacs-lisp[:results replace]{42} {{{results(=42=)}}} : exported as: : `42' #+CALL: demo("replace") #+RESULTS: : inline-src-block: src_emacs-lisp[:results replace]{42} : export backend: ascii : result: src_emacs-lisp[:results replace]{42} {{{results(=42=)}}} : exported as: : `42' * :results html under html backend #+CALL: demo("html","html") #+RESULTS: : inline-src-block: src_emacs-lisp[:results html]{42} : export backend: html : result: src_emacs-lisp[:results html]{42} {{{results(@@html:42@@)}}} : exported as: :

: 42

* :results html under latex backend #+CALL: demo("html","latex") #+RESULTS: : inline-src-block: src_emacs-lisp[:results html]{42} : export backend: latex : result: src_emacs-lisp[:results html]{42} {{{results(@@html:42@@)}}} : exported as: * :results latex under latex backend #+CALL: demo("latex","latex") #+RESULTS: : inline-src-block: src_emacs-lisp[:results latex]{42} : export backend: latex : result: src_emacs-lisp[:results latex]{42} {{{results(@@latex:42@@)}}} : exported as: : 42 * :results replace :wrap ascii #+CALL: demo("replace :wrap ascii","ascii") #+RESULTS: : inline-src-block: src_emacs-lisp[:results replace :wrap ascii]{42} : export backend: ascii : result: src_emacs-lisp[:results replace :wrap ascii]{42} {{{results(@@ascii:42@@)}}} : exported as: : 42 * :results raw #+CALL: demo("raw") #+RESULTS: : inline-src-block: src_emacs-lisp[:results raw]{42} : export backend: ascii : result: src_emacs-lisp[:results raw]{42} 42 : exported as: : 42 * :results drawer Same as default. #+CALL: demo("drawer") #+RESULTS: : inline-src-block: src_emacs-lisp[:results drawer]{42} : export backend: ascii : result: src_emacs-lisp[:results drawer]{42} {{{results(42)}}} : exported as: : 42 * :results org Code is quoted like this: `42' under ascii backend. #+CALL: demo("org") #+RESULTS: : inline-src-block: src_emacs-lisp[:results org]{42} : export backend: ascii : result: src_emacs-lisp[:results org]{42} {{{results(src_org{42})}}} : exported as: : `42' * :results code Code is quoted like this: `42' under ascii backend. #+CALL: demo("code") #+RESULTS: : inline-src-block: src_emacs-lisp[:results code]{42} : export backend: ascii : result: src_emacs-lisp[:results code]{42} {{{results(src_emacs-lisp[]{42})}}} : exported as: : `42' * :results list Lists and tables should be avoided for inline-src-blocks, but for completeness some are listed here. #+CALL: demo("list") #+RESULTS: : inline-src-block: src_emacs-lisp[:results list]{42} : export backend: ascii : result: src_emacs-lisp[:results list]{42} Stopped for Error : exported as: : Stopped for Error * :results table #+CALL: demo("table") #+RESULTS: : inline-src-block: src_emacs-lisp[:results table]{42} : export backend: ascii : result: src_emacs-lisp[:results table]{42} Stopped for Error : exported as: : Stopped for Error * :results replace, proper list as content Proper lists become tables. #+CALL: demo(contents="\'(42)") #+RESULTS: : inline-src-block: src_emacs-lisp[:results replace]{'(42) } : export backend: ascii : result: src_emacs-lisp[:results replace]{'(42) } Stopped for Error : exported as: : Stopped for Error * :results code, contents as elisp #+CALL: demo("code",contents="(quote (+ 1 2))") #+RESULTS: : inline-src-block: src_emacs-lisp[:results code]{(quote (+ 1 2) )} : export backend: ascii : result: src_emacs-lisp[:results code]{(quote (+ 1 2) )} {{{results(src_emacs-lisp[]{(+ 1 2)})}}} : exported as: : `(+ 1 2)' * inline calls The `demo' src block sets up an inline-babel-call, calls it, then exports the result. The output is as described above. #+name: square-code #+begin_src org :export code :eval no ,#+name: square ,#+BEGIN_SRC emacs-lisp :var x=1 :exports none (* x x) ,#+end_src #+end_src #+name: demo_calls #+BEGIN_SRC emacs-lisp :var str="replace" bkend="ascii" contents=3 :noweb yes (let ((cmd (format "call_square(%s)[:results %s] " contents str))) (concat "inline-babel-call: " cmd "\nexport backend: " bkend "\nresult: " (with-temp-buffer (insert cmd " <>" ) (or (ignore-errors (org-babel-execute-buffer)) (progn (goto-char (point-min)) (goto-char (point-at-eol)) (insert "Stopped for Error"))) (let (( bstr (buffer-string))) (replace-regexp-in-string "\n[#]\\(.\\|\n\\)*" "" bstr))) "\nexported as:\n" (or (ignore-errors (org-export-string-as (concat " <>" "\n" cmd) (intern bkend) t)) "Stopped for Error"))) #+END_SRC #+RESULTS: demo_calls : inline-babel-call: call_square(3)[:results replace] : export backend: ascii : result: call_square(3)[:results replace] {{{results(=9=)}}} : exported as: : `9' #+CALL: demo_calls("replace") #+RESULTS: : inline-babel-call: call_square(3)[:results replace] : export backend: ascii : result: call_square(3)[:results replace] {{{results(=9=)}}} : exported as: : `9' #+CALL: demo_calls("html","html") #+RESULTS: : inline-babel-call: call_square(3)[:results html] : export backend: html : result: call_square(3)[:results html] {{{results(@@html:9@@)}}} : exported as: :

: 9

#+CALL: demo_calls("html","latex") #+RESULTS: : inline-babel-call: call_square(3)[:results html] : export backend: latex : result: call_square(3)[:results html] {{{results(@@html:9@@)}}} : exported as: : #+CALL: demo_calls("latex","latex") #+RESULTS: : inline-babel-call: call_square(3)[:results latex] : export backend: latex : result: call_square(3)[:results latex] {{{results(@@latex:9@@)}}} : exported as: : 9 #+CALL: demo_calls("raw") #+RESULTS: : inline-babel-call: call_square(3)[:results raw] : export backend: ascii : result: call_square(3)[:results raw] 9 : exported as: : 9 #+CALL: demo_calls("drawer") #+RESULTS: : inline-babel-call: call_square(3)[:results drawer] : export backend: ascii : result: call_square(3)[:results drawer] {{{results(9)}}} : exported as: : 9 #+CALL: demo_calls("org") #+RESULTS: : inline-babel-call: call_square(3)[:results org] : export backend: ascii : result: call_square(3)[:results org] {{{results(src_org{9})}}} : exported as: : `9' #+CALL: demo_calls("list") #+RESULTS: : inline-babel-call: call_square(3)[:results list] : export backend: ascii : result: call_square(3)[:results list] Stopped for Error : exported as: : Stopped for Error #+CALL: demo_calls("code") #+RESULTS: : inline-babel-call: call_square(3)[:results code] : export backend: ascii : result: call_square(3)[:results code] {{{results(src_emacs-lisp[]{9})}}} : exported as: : `9' #+CALL: demo_calls("table") #+RESULTS: : inline-babel-call: call_square(3)[:results table] : export backend: ascii : result: call_square(3)[:results table] Stopped for Error : exported as: : Stopped for Error #+CALL: demo_calls("code",contents="(quote (+ 1 2))") #+RESULTS: : inline-babel-call: call_square((quote (+ 1 2) ))[:results code] : export backend: ascii : result: call_square((quote (+ 1 2) ))[:results code] Stopped for Error : exported as: : Stopped for Error #+CALL: demo_calls("replace :wrap ascii","ascii") #+RESULTS: : inline-babel-call: call_square(3)[:results replace :wrap ascii] : export backend: ascii : result: call_square(3)[:results replace :wrap ascii] {{{results(@@ascii:9@@)}}} : exported as: : 9