Next:Using Header Arguments, Previous:Features Overview, Up:Working with Source Code [Contents][Index]
Org offers two ways to structure source code in Org documents: ina source code block, and directly inline. Both specifications areshown below.
A source code block conforms to this structure:
#+NAME: <name>#+BEGIN_SRC <language> <switches> <header arguments> <body>#+END_SRC
Do not be put-off by having to remember the source block syntax. Orgmode offers a command for wrapping existing text in a block (seeStructure Templates). Org also works with other completion systemsin Emacs, some of which predate Org and have custom domain-specificlanguages for defining templates. Regular use of templates reduceserrors, increases accuracy, and maintains consistency.
An inline code block conforms to this structure:
src_<language>{<body>}or
src_<language>[<header arguments>]{<body>}Optional. Names the source block so it can be called, likea function, from other source blocks or inline code to evaluate orto capture the results. Code from other blocks, other files, andfrom table formulas (seeThe Spreadsheet) can use the name toreference a source block. This naming serves the same purpose asnaming Org tables. Org mode requires unique names. For duplicatenames, Org mode’s behavior is undefined. Inline code blocks cannothave a name.
Mandatory. They mark the start and end of a block that Orgrequires. The ‘#+BEGIN_SRC’ line takes additional arguments, asdescribed next.
Optional. It is the identifier of the source code language in theblock. SeeLanguages, for identifiers of supported languages.
When ‘<language>’ identifier is omitted, the block also cannothave ‘<switches>’ and ‘<header arguments>’.
Language identifier is also used to fontify code blocks in Orgbuffers, whenorg-src-fontify-natively is set to non-nil. SeeEditing Source Code.
Optional. Switches provide finer control of the code execution,export, and format (see the discussion of switches inLiteral Examples).
Optional. Heading arguments control many aspects of evaluation,export and tangling of code blocks (seeUsing Header Arguments).Using Org’s properties feature, header arguments can be selectivelyapplied to the entire buffer or specific subtrees of the Orgdocument.
Source code in the dialect of the specified language identifier.
Next:Using Header Arguments, Previous:Features Overview, Up:Working with Source Code [Contents][Index]