Wrap verbatim examples in @example ... @end example

Note that there are some cases where the #+begin_src itself is part of
the example, and others where only the body of the source block is the
example.
This commit is contained in:
Dan Davison 2010-04-11 12:21:57 -04:00 committed by Eric Schulte
parent 12e9b0a567
commit a465cff872
1 changed files with 112 additions and 104 deletions

View File

@ -8,10 +8,11 @@
@subsection Source Code Block @subsection Source Code Block
The basic syntax of source code blocks in Org-babel is as follows: The basic syntax of source code blocks in Org-babel is as follows:
: #+begin_src language header-arguments @example
: body #+begin_src language header-arguments
: #+end_src body
#+end_src
@end example
- language :: The language of the code in the source code block. Valid - language :: The language of the code in the source code block. Valid
values must be members of =org-babel-interpreters=. values must be members of =org-babel-interpreters=.
- header-arguments :: Header arguments control many facets of the - header-arguments :: Header arguments control many facets of the
@ -26,10 +27,12 @@ The basic syntax of source code blocks in Org-babel is as follows:
This syntax can be expanded by naming the source code block. This syntax can be expanded by naming the source code block.
: #+source: name @example
: #+begin_src language header-arguments #+sourcename
: #+begin_src language header-arguments
: #+end_src body
#+end_src
@end example
- name :: This name is associated with the source code block. This is - name :: This name is associated with the source code block. This is
similar to the =#+tblname= lines that can be used to name tables similar to the =#+tblname= lines that can be used to name tables
@ -42,33 +45,35 @@ This syntax can be expanded by naming the source code block.
@subsection Library of Babel @subsection Library of Babel
[[file:library-of-babel.org][Library of Babel]] functions can be called using the following syntax. [[file:library-of-babel.org][Library of Babel]] functions can be called using the following syntax.
: #+lob: R-plot(data=R-plot-example-data) @example
#+lob: R-plot(data=R-plot-example-data)
@end example
@subsection Aliases @subsection Aliases
Keyword aliases are intended to make Org-babel feel natural to Keyword aliases are intended to make Org-babel feel natural to
programmers fluent in a variety of languages. For example, programmers fluent in a variety of languages. For example,
#+begin_example @example
,#+srcname: alias-example #+srcname: alias-example
,#+begin_src emacs-lisp #+begin_src emacs-lisp
'((call lob) '((call lob)
(source function srcname) (source function srcname)
(results resname)) (results resname))
,#+end_src #+end_src
,#+results: alias-example #+results: alias-example
| call | lob | | | call | lob | |
| source | function | srcname | | source | function | srcname |
| results | resname | | | results | resname | |
#+end_example @end example
- =#+srcname:= can be replaced with either of two aliases, =#+source:= or =#+function:=. - =#+srcname:= can be replaced with either of two aliases, =#+source:= or =#+function:=.
- =#+results:= can be replaced with its alias, =#+resname:=. - =#+results:= can be replaced with its alias, =#+resname:=.
When calling Library of Babel functions, as in the following When calling Library of Babel functions, as in the following
example, there are two acceptable keywords. The =#+lob= call in example, there are two acceptable keywords. The =#+lob= call in
the example could be replaced with its alias, =#+call=. the example could be replaced with its alias, =#+call=.
#+begin_example @example
,#+lob: R-plot(data=R-plot-example-data) #+lob: R-plot(data=R-plot-example-data)
#+end_example @end example
@section Languages @section Languages
:PROPERTIES: :PROPERTIES:
@ -107,9 +112,9 @@ This syntax can be expanded by naming the source code block.
are met, then add a line like the following to your Emacs are met, then add a line like the following to your Emacs
configuration, (replace "identifier" with one of the configuration, (replace "identifier" with one of the
entries in the Identifier column of the table). entries in the Identifier column of the table).
#+begin_src emacs-lisp @example
(require 'org-babel-identifier) (require 'org-babel-identifier)
#+end_src @end example
@section Header Arguments @section Header Arguments
:PROPERTIES: :PROPERTIES:
@ -133,7 +138,7 @@ each more specific than the last.
System-wide values of header arguments can be specified by System-wide values of header arguments can be specified by
customizing the =org-babel-default-header-args= variable: customizing the =org-babel-default-header-args= variable:
#+begin_example @example
org-babel-default-header-args is a variable defined in `org-babel.el'. org-babel-default-header-args is a variable defined in `org-babel.el'.
Its value is Its value is
((:session . "none") ((:session . "none")
@ -145,16 +150,16 @@ each more specific than the last.
Documentation: Documentation:
Default arguments to use when evaluating a source block. Default arguments to use when evaluating a source block.
#+end_example @end example
[[#default-noweb]] [[#default-noweb]]
For example, the following example could be used to set the default value For example, the following example could be used to set the default value
of =:noweb= header arguments to =yes=. This would have the effect of of =:noweb= header arguments to =yes=. This would have the effect of
expanding =:noweb= references by default when evaluating source code blocks. expanding =:noweb= references by default when evaluating source code blocks.
#+begin_src emacs-lisp :results silent :exports code @example
(setq org-babel-default-header-args (setq org-babel-default-header-args
(cons '(:noweb . "yes") (cons '(:noweb . "yes")
(assq-delete-all :noweb org-babel-default-header-args))) (assq-delete-all :noweb org-babel-default-header-args)))
#+end_src @end example
*** Org-mode Properties *** Org-mode Properties
@ -162,13 +167,13 @@ each more specific than the last.
means they can be set on the outline header level. For example, the means they can be set on the outline header level. For example, the
value of the =:cache= header argument will default to true in all value of the =:cache= header argument will default to true in all
source code blocks under the following example of an Org-mode outline header: source code blocks under the following example of an Org-mode outline header:
#+begin_example @example
,* outline header * outline header
:PROPERTIES: :PROPERTIES:
:cache: yes :cache: yes
:CUSTOM_ID: property-set-header-arguments :CUSTOM_ID: property-set-header-arguments
:END: :END:
#+end_example @end example
Properties defined in this way override the properties set in Properties defined in this way override the properties set in
=org-babel-default-header-args=. It is convenient to use the =org-babel-default-header-args=. It is convenient to use the
=org-set-property= function bound to =C-c C-x p= to set properties =org-set-property= function bound to =C-c C-x p= to set properties
@ -189,13 +194,13 @@ each more specific than the last.
header argument is set to =code=, meaning only the body of the header argument is set to =code=, meaning only the body of the
source code block source code block
will be preserved on export to HTML or LaTeX. will be preserved on export to HTML or LaTeX.
#+begin_example @example
,#+source: factorial #+source: factorial
,#+begin_src haskell :results silent :exports code #+begin_src haskell :results silent :exports code
fac 0 = 1 fac 0 = 1
fac n = n * fac (n-1) fac n = n * fac (n-1)
,#+end_src #+end_src
#+end_example @end example
@subsection Specific Header Arguments @subsection Specific Header Arguments
:PROPERTIES: :PROPERTIES:
@ -223,64 +228,64 @@ each more specific than the last.
The following syntax is used to pass arguments to source code The following syntax is used to pass arguments to source code
blocks using the =:var= header argument. blocks using the =:var= header argument.
#+begin_example @example
:var name=assign :var name=assign
#+end_example @end example
where =assign= can take one of the following forms where =assign= can take one of the following forms
- literal value :: either a string ="string"= or a number =9=. - literal value :: either a string ="string"= or a number =9=.
- reference :: a table name: - reference :: a table name:
#+begin_example @example
,#+tblname: example-table #+tblname: example-table
| 1 | | 1 |
| 2 | | 2 |
| 3 | | 3 |
| 4 | | 4 |
,#+source: table-length #+source: table-length
,#+begin_src emacs-lisp :var table=example-table #+begin_src emacs-lisp :var table=example-table
(length table) (length table)
,#+end_src #+end_src
,#+results: table-length #+results: table-length
: 4 : 4
#+end_example @end example
a source code block name, as assigned by =#+srcname:=, a source code block name, as assigned by =#+srcname:=,
followed by parentheses: followed by parentheses:
#+begin_example @example
,#+begin_src emacs-lisp :var length=table-length() #+begin_src emacs-lisp :var length=table-length()
(* 2 length) (* 2 length)
,#+end_src #+end_src
,#+results: #+results:
: 8 : 8
#+end_example @end example
In addition, an argument can be passed to the source code In addition, an argument can be passed to the source code
block referenced by =:var=. The argument is passed within block referenced by =:var=. The argument is passed within
the parentheses following the source code block name: the parentheses following the source code block name:
#+begin_example @example
,#+source: double #+source: double
,#+begin_src emacs-lisp :var input=8 #+begin_src emacs-lisp :var input=8
(* 2 input) (* 2 input)
,#+end_src #+end_src
,#+results: double #+results: double
: 16 : 16
,#+source: squared #+source: squared
,#+begin_src emacs-lisp :var input=double(input=1) #+begin_src emacs-lisp :var input=double(input=1)
(* input input) (* input input)
,#+end_src #+end_src
,#+results: squared #+results: squared
: 4 : 4
#+end_example @end example
**** alternate argument syntax **** alternate argument syntax
:PROPERTIES: :PROPERTIES:
@ -291,12 +296,12 @@ each more specific than the last.
natural way using the =#+source:= line of a source code block. natural way using the =#+source:= line of a source code block.
As in the following example arguments can be packed inside of As in the following example arguments can be packed inside of
parenthesis following the source name. parenthesis following the source name.
#+begin_example @example
,#+source: double(input=0) #+source: double(input=0)
,#+begin_src emacs-lisp #+begin_src emacs-lisp
(* 2 input) (* 2 input)
,#+end_src #+end_src
#+end_example @end example
**** indexable variable values **** indexable variable values
:PROPERTIES: :PROPERTIES:
@ -308,9 +313,9 @@ each more specific than the last.
assigns the second and third rows of the table assigns the second and third rows of the table
=example-table= to the variable =data=: =example-table= to the variable =data=:
#+begin_example @example
:var data=example-table[1:2] :var data=example-table[1:2]
#+end_example @end example
*Note:* ranges are indexed using the =:= operator. *Note:* ranges are indexed using the =:= operator.
@ -319,9 +324,9 @@ each more specific than the last.
The following example assigns the second column of the The following example assigns the second column of the
first row of =example-table= to =data=: first row of =example-table= to =data=:
#+begin_example @example
:var data=example-table[0,1] :var data=example-table[0,1]
#+end_example @end example
It is possible to index into the results of source code blocks It is possible to index into the results of source code blocks
as well as tables. Any number of dimensions can be indexed. as well as tables. Any number of dimensions can be indexed.
@ -330,7 +335,7 @@ each more specific than the last.
For more information on indexing behavior see the documentation For more information on indexing behavior see the documentation
for the =org-babel-ref-index-list= function -- provided below. for the =org-babel-ref-index-list= function -- provided below.
#+begin_example @example
org-babel-ref-index-list is a Lisp function in `org-babel-ref.el'. org-babel-ref-index-list is a Lisp function in `org-babel-ref.el'.
(org-babel-ref-index-list INDEX LIS) (org-babel-ref-index-list INDEX LIS)
@ -340,7 +345,7 @@ each more specific than the last.
next deepest nesting or dimension. A valid PORTION can consist next deepest nesting or dimension. A valid PORTION can consist
of either an integer index, or two integers separated by a : in of either an integer index, or two integers separated by a : in
which case the entire range is returned. which case the entire range is returned.
#+end_example @end example
*Note:* In Emacs, the documentation for any function or variable *Note:* In Emacs, the documentation for any function or variable
can be read using the =describe-function= (M-x describe can be read using the =describe-function= (M-x describe
@ -468,22 +473,22 @@ each more specific than the last.
In other words, if you want your plot to go into a folder called In other words, if you want your plot to go into a folder called
Work in your home directory, you could use Work in your home directory, you could use
#+begin_example @example
,#+begin_src R :file myplot.png :dir ~/Work #+begin_src R :file myplot.png :dir ~/Work
matplot(matrix(rnorm(100), 10), type="l") matplot(matrix(rnorm(100), 10), type="l")
,#+end_src #+end_src
#+end_example @end example
**** Remote execution **** Remote execution
A directory on a remote machine can be specified using [[http://www.gnu.org/software/tramp/#Filename-Syntax][tramp A directory on a remote machine can be specified using [[http://www.gnu.org/software/tramp/#Filename-Syntax][tramp
filename syntax]], in which case the code will be executed on the filename syntax]], in which case the code will be executed on the
remote machine[fn:2]. An example is remote machine[fn:2]. An example is
#+begin_example @example
,#+begin_src R :file plot.png :dir /dand@@yakuba.princeton.edu: #+begin_src R :file plot.png :dir /dand@@yakuba.princeton.edu:
plot(1:10, main=system("hostname", intern=TRUE)) plot(1:10, main=system("hostname", intern=TRUE))
,#+end_src #+end_src
#+end_example @end example
Text results will be returned to the local org buffer as normal, and Text results will be returned to the local org buffer as normal, and
file output will be created on the remote machine with relative paths file output will be created on the remote machine with relative paths
@ -493,9 +498,9 @@ remote file will be created.
So in the above example a plot will be created on the remote machine, So in the above example a plot will be created on the remote machine,
and a link of the following form will be inserted in the org buffer: and a link of the following form will be inserted in the org buffer:
#+begin_example @example
[[file:/scp:dand@@yakuba.princeton.edu:/home/dand/plot.png][plot.png]] [[file:/scp:dand@@yakuba.princeton.edu:/home/dand/plot.png][plot.png]]
#+end_example @end example
Most of this functionality follows immediately from the fact that Most of this functionality follows immediately from the fact that
=:dir= sets the value of the emacs variable =default-directory=, =:dir= sets the value of the emacs variable =default-directory=,
@ -591,17 +596,17 @@ above features to work correctly.
This source code block: This source code block:
#+begin_example @example
-- <<example>> -- <<example>>
#+end_example @end example
expands to: expands to:
#+begin_example @example
-- this is the -- this is the
-- multi-line body of example -- multi-line body of example
#+end_example @end example
Note that noweb replacement text that does *not* contain any Note that noweb replacement text that does *not* contain any
newlines will not be affected by this change, so it is still newlines will not be affected by this change, so it is still
@ -683,6 +688,7 @@ above features to work correctly.
non-interactive interpreter running as an external process. For non-interactive interpreter running as an external process. For
example, compare the following two blocks: example, compare the following two blocks:
@example
#+begin_src python :results output #+begin_src python :results output
print "hello" print "hello"
2 2
@ -692,9 +698,10 @@ above features to work correctly.
#+resname: #+resname:
: hello : hello
: bye : bye
@end example
In non-session mode, the '2' is not printed and does not appear. In non-session mode, the '2' is not printed and does not appear.
@example
#+begin_src python :results output :session #+begin_src python :results output :session
print "hello" print "hello"
2 2
@ -705,6 +712,7 @@ above features to work correctly.
: hello : hello
: 2 : 2
: bye : bye
@end example
But in =:session= mode, the interactive interpreter receives input '2' But in =:session= mode, the interactive interpreter receives input '2'
and prints out its value, '2'. (Indeed, the other print statements are and prints out its value, '2'. (Indeed, the other print statements are
@ -776,7 +784,7 @@ above features to work correctly.
:CUSTOM_ID: function-org-babel-execute-src-block :CUSTOM_ID: function-org-babel-execute-src-block
:END: :END:
#+begin_example @example
org-babel-execute-src-block is an interactive Lisp function in org-babel-execute-src-block is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -793,14 +801,14 @@ above features to work correctly.
Optionally supply a value for PARAMS which will be merged with Optionally supply a value for PARAMS which will be merged with
the header arguments specified at the front of the source code the header arguments specified at the front of the source code
block. block.
#+end_example @end example
*** org-babel-open-src-block-result *** org-babel-open-src-block-result
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-open-src-block-result :CUSTOM_ID: function-org-babel-open-src-block-result
:END: :END:
#+begin_example @example
org-babel-open-src-block-result is an interactive Lisp function in org-babel-open-src-block-result is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -810,14 +818,14 @@ above features to work correctly.
source code block, otherwise return nil. With optional prefix source code block, otherwise return nil. With optional prefix
argument RE-RUN the source-code block is evaluated even if argument RE-RUN the source-code block is evaluated even if
results already exist. results already exist.
#+end_example @end example
*** org-babel-load-in-session *** org-babel-load-in-session
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-load-in-session :CUSTOM_ID: function-org-babel-load-in-session
:END: :END:
#+begin_example @example
org-babel-load-in-session is an interactive Lisp function in org-babel-load-in-session is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -828,14 +836,14 @@ above features to work correctly.
session. After loading the body this pops open the session. session. After loading the body this pops open the session.
[back] [back]
#+end_example @end example
*** org-babel-pop-to-session *** org-babel-pop-to-session
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-pop-to-session :CUSTOM_ID: function-org-babel-pop-to-session
:END: :END:
#+begin_example @example
org-babel-pop-to-session is an interactive Lisp function in org-babel-pop-to-session is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -847,14 +855,14 @@ above features to work correctly.
of the source block to the kill ring. of the source block to the kill ring.
[back] [back]
#+end_example @end example
*** org-babel-tangle *** org-babel-tangle
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-tangle :CUSTOM_ID: function-org-babel-tangle
:END: :END:
#+begin_example @example
org-babel-tangle is an interactive Lisp function in org-babel-tangle is an interactive Lisp function in
`org-babel-tangle.el'. `org-babel-tangle.el'.
@ -867,14 +875,14 @@ above features to work correctly.
TARGET-FILE can be used to specify a default export file for all TARGET-FILE can be used to specify a default export file for all
source blocks. Optional argument LANG can be used to limit the source blocks. Optional argument LANG can be used to limit the
exported source code blocks by language. exported source code blocks by language.
#+end_example @end example
*** org-babel-execute-subtree *** org-babel-execute-subtree
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-execute-subtree :CUSTOM_ID: function-org-babel-execute-subtree
:END: :END:
#+begin_example @example
org-babel-execute-subtree is an interactive Lisp function in org-babel-execute-subtree is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -883,14 +891,14 @@ above features to work correctly.
(org-babel-execute-subtree &optional ARG) (org-babel-execute-subtree &optional ARG)
Replace EVAL snippets in the entire subtree. Replace EVAL snippets in the entire subtree.
#+end_example @end example
*** org-babel-execute-buffer *** org-babel-execute-buffer
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-execute-buffer :CUSTOM_ID: function-org-babel-execute-buffer
:END: :END:
#+begin_example @example
org-babel-execute-buffer is an interactive Lisp function in org-babel-execute-buffer is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -899,14 +907,14 @@ above features to work correctly.
(org-babel-execute-buffer &optional ARG) (org-babel-execute-buffer &optional ARG)
Replace EVAL snippets in the entire buffer. Replace EVAL snippets in the entire buffer.
#+end_example @end example
*** org-babel-sha1-hash *** org-babel-sha1-hash
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-sha1-hash :CUSTOM_ID: function-org-babel-sha1-hash
:END: :END:
#+begin_example @example
org-babel-sha1-hash is an interactive Lisp function in `org-babel.el'. org-babel-sha1-hash is an interactive Lisp function in `org-babel.el'.
It is bound to C-c M-b h. It is bound to C-c M-b h.
@ -914,14 +922,14 @@ above features to work correctly.
(org-babel-sha1-hash &optional INFO) (org-babel-sha1-hash &optional INFO)
Not documented. Not documented.
#+end_example @end example
*** org-babel-goto-named-source-block *** org-babel-goto-named-source-block
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-goto-named-source-block :CUSTOM_ID: function-org-babel-goto-named-source-block
:END: :END:
#+begin_example @example
org-babel-goto-named-source-block is an interactive Lisp function in org-babel-goto-named-source-block is an interactive Lisp function in
`org-babel.el'. `org-babel.el'.
@ -930,14 +938,14 @@ above features to work correctly.
(org-babel-goto-named-source-block &optional NAME) (org-babel-goto-named-source-block &optional NAME)
Go to a named source-code block. Go to a named source-code block.
#+end_example @end example
*** org-babel-lob-ingest *** org-babel-lob-ingest
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: function-org-babel-lob-ingest :CUSTOM_ID: function-org-babel-lob-ingest
:END: :END:
#+begin_example @example
org-babel-lob-ingest is an interactive Lisp function in org-babel-lob-ingest is an interactive Lisp function in
`org-babel-lob.el'. `org-babel-lob.el'.
@ -946,7 +954,7 @@ above features to work correctly.
(org-babel-lob-ingest &optional FILE) (org-babel-lob-ingest &optional FILE)
Add all source-blocks defined in FILE to `org-babel-library-of-babel'. Add all source-blocks defined in FILE to `org-babel-library-of-babel'.
#+end_example @end example
@section Batch Execution @section Batch Execution
It is possible to call Org-babel functions from the command line. It is possible to call Org-babel functions from the command line.
@ -954,7 +962,7 @@ This shell script calls [[function-org-babel-tangle][org-babel-tangle]] on every
arguments. arguments.
Be sure to adjust the paths to fit your system. Be sure to adjust the paths to fit your system.
#+begin_src sh @example
#!/bin/sh #!/bin/sh
# -*- mode: shell-script -*- # -*- mode: shell-script -*-
# #
@ -977,7 +985,7 @@ Be sure to adjust the paths to fit your system.
(find-file (expand-file-name file \"$DIR\")) (find-file (expand-file-name file \"$DIR\"))
(org-babel-tangle) (org-babel-tangle)
(kill-buffer)) '($FILES)))" (kill-buffer)) '($FILES)))"
#+end_src @end example
@section Footnotes @section Footnotes