Questions tagged [org-babel]
feature of Org mode that handles source code for multiple languages. It can execute source code from within Org mode documents, making it convenient for producing literate programming documents and managing reproducible research. Note that Org-babel is now incorporated into Org-mode as 'working with source code' and no longer a separate extension.
849
questions
0
votes
1
answer
58
views
Is there any org-babel source block that converts to a LaTeX pseudocode algorithm block?
Currently, when I want to add some algorithm's pseudocode to my LaTeX export, I have to manually write LaTeX:
** Pixel-Flipping: A Technique to Assess Faithfulness
- Pixel-flipping is a quantitative, ...
2
votes
2
answers
870
views
org-babel - Use specific python path and command line option
Since different python version installed on my system, how can I use specific python and option to run it?
For example,below test.py file will print hello output.
#!/opt/anaconda3/bin/python --...
0
votes
1
answer
20
views
Can I redefine org-babel-execute for specific org-babel blocks?
When I C-c C-c on an org-babel plantuml block, I get the message:
Debugger entered--Lisp error: (error "No org-babel-execute function for plantuml!")
I have to M-x plantuml-preview-current-...
3
votes
1
answer
151
views
org-babel python code block - not showing errors during execution
I have a python code block in an org-file that when executed results in some error. I was expecting to see that error in the #+RESULTS: block, but it doesn't show up. I have to navigate to the python ...
0
votes
1
answer
26
views
feed python output to sqlite as input sql stement
I would like to feed python output to sqlite input as below:
#+NAME: sqlcmd
#+begin_src python :results output
print("select * from tablename")
#+end_src
#+RESULTS: sqlcmd
: select * from ...
0
votes
1
answer
137
views
How to evaluate python code in org-mode when only python3 is provided by the package manager?
Recently I started to use guix as my operating system.
I installed python3 for my user via guix install python3.
python itself is not available in the package repository, which I verified by running ...
3
votes
1
answer
569
views
org-babel-tangle-file multiple files into a single output
Is there a way to tangle an org file with #+INCLUDE: statements? Or other ways to tangle multiple org files into a single output?
2
votes
2
answers
303
views
How do I stop org-babel from trying to edit a source block in a dedicated buffer?
I have org :jupyter in my Doom Emacs init.el, i.e., ob-jupyter, for using Jupyter with org-babel, and there's a really annoying behavior when I'm in an org file, editing a source block that begins ...
0
votes
2
answers
568
views
ledger in org-babel blocks uses incorrect path data in Windows 10
I am trying to include a ledger data file from an org-babel block. I am using Windows10 and the SciMax emacs distribution.
#+begin_src ledger :cmdline bal :results output :exports results
!include d:/...
1
vote
1
answer
182
views
No comment syntax defined when tangling lua or vimrc code blocks
Resolution
With help from commenters, I have things kind of working.
I removed :comments link from Properties.
I manually added comments to the top of every code block to replicate what :comments ...
0
votes
1
answer
16
views
Org-mode babel shell async evaluation not working with named sessions
I'm trying to use shell asynchronously with named sessions, but it doesn't work:
#+begin_src sh
echo "a"
#+end_src
#+RESULTS:
: a
#+begin_src sh :async
echo "a"
#+end_src
#+...
2
votes
1
answer
392
views
Org-babel python with session breaks output
If I run the following code block:
#+BEGIN_SRC python :results output
print(" /|")
print(" / |")
print(" / |")
print("/___|")
#+END_SRC
I get the result as expected:
#+RESULTS:
: /|...
0
votes
1
answer
233
views
code execution issue in org mode on windows
I issue
emacs -Q yes.org
where yes.org is
(org-babel-do-load-languages 'org-babel-load-languages '((python . t)))
#+begin_src python :results output
print(2)
#+end_src
I first evaluate the loading ...
0
votes
2
answers
320
views
org-mode batch export hangs when using a python session
I have developed a workflow for batch-export of org-mode files, and have come across an issue in which execution halts when using a python session. I'm using emacs 28.1 on MacOS 11.6.5 with Python 3.9....
0
votes
2
answers
538
views
Getting content of paragraph element using Org Element API
I've been trying to get the content of the paragraph element unsuccessfully using org-element-contents, is there something I am missing here?
I have a org document as follows:
* world
** China
*** ...
2
votes
1
answer
793
views
org-mode: How can noweb handle a multiple line output
I have a code chunk in my document that I want to use as a list of patterns to search for with grep.
If I were just writing a script without org-babel, I could write.
a="ar
er
ir
or
ur"
printf "...
0
votes
1
answer
265
views
Org and EIN (IPython): No output for print
I am using EIN in Org blocks, as explained on the GitHub page for EIN. So I use ein-python as the language for Org blocks (instead of python).
All seems to work well (for example displaying data from ...
0
votes
1
answer
188
views
(wrong-type-argument stringp nil) error when calling tangle
As the title says, I get this error whenever I, or the function I'll show below, call org-babel-tangle. I'm using a org file to configure emacs, which tangles every time it is saved to my init.el.
The ...
3
votes
1
answer
371
views
Literate agda programming in org-mode
How could I write literate (and exportable to latex) Agda code in org-mode?
Org-babel would be a great option, but there is no ob-agda2 (I think?). I have tried defining an org-babel-execute function ...
1
vote
1
answer
136
views
How to prevent org-mode loading babel's major mode stuffs unless entering `org-src-mode`?
I have some Java's scripts in a org file. And I use meghanada-mode in java-mode.
Each time I open this org file and do nothing, I get the following error since the mehanada server loaded by java-mode ...
1
vote
1
answer
375
views
How to execute org-mode source block asynchronously in session?
I have an org file with notes about how to setup my project. One of the notes has some shell scripts, like this:
#+begin_src sh :dir ~/Workspace/MyProject :session cmake-setup
cmake -B build-debug -S ....
2
votes
1
answer
347
views
Problem evaluating a `sage-shell-mode` function through `ob-sagemath`
I'm trying to use sage-math within an org-mode file. So far I've been able to configure the sage-shell-mode package (I'm impressed that sagemath can be installed in Debian using the package manager), ...
0
votes
1
answer
30
views
In org-mode, undo the effects of :results pp
In my org-files I usually always enable pretty-printing at the top because I find it preferrable to Org's default of trying to fit output into tables and whatnot. But I have now hit a snag.
In a clean ...
2
votes
2
answers
54
views
Org babel add extra "," after indent for no reason
Insert the following text in an org buffer with electric-indent-mode on.
#+begin_src python
s='''
#+1
#+1'''
#+end_src
add a newline to s, and the buffer will become:
#+begin_src python
s='''
,#+...
0
votes
1
answer
1k
views
Tangle only selected src blocks using org-babel on export
I have a document with only several source code blocks that should be tangled. So the structure is:
# Some main.org
...
#+BEGIN_SRC awk :tangle file1.awk
...
#+END_SRC awk
...
...
1
vote
3
answers
458
views
Babel + Python function definition with for loop causes IndentationError
I am using orgmode and Babel to run Python source code blocks.
I noticed that if I define a function that returns a value, and if this function has a for loop inside it, then evaluating it with Babel ...
0
votes
1
answer
67
views
Org mode LaTeX block fails to invoke gnuplot for pgfplots?
I've copied a configuration from the internet that allows me to generate images from LaTeX code blocks in Org mode. Here's the setup:
#+PROPERTY: header-args:latex :results file raw drawer :headers '(&...
0
votes
1
answer
217
views
conf "language" in org-babel
#+NAME: certfile
#+begin_src emacs-lisp
(cond
((eq system-type 'gnu/linux) "/etc/ssl/cert.pem")
((eq system-type 'darwin) "~/Mail/certificates/root-certificates.pem"))
#+end_src
...
0
votes
1
answer
33
views
how can I update the org-mode header-args from the output of an org-babel code block?
I have a code block with a shell scripts that asks for a token. I want to insert this token into the header-args, so that I can reference this from other code blocks.
I usually copy it, but can this ...
0
votes
1
answer
256
views
Org mode exam template with question and results in combination with latex
I would like to use Org mode for creating exam questions and including the templates for the corresponding results for each question.
A general template is shown here
#+TITLE: Lecture
#+AUTHOR: ...
2
votes
1
answer
196
views
How do I associate org-mode source buffer to appropriate session?
I want to execute org-babel code blocks associated with a session without locking up Emacs. I found the ob-async package, but it doesn't have support for sessions yet. I've found that opening the code ...
1
vote
1
answer
44
views
Python Org Babel producing garbled result
I have the following settings on for org-babel
#+PROPERTY: header-args:python :python ~/env/pt/bin/python :session a :results drawer output replace
When I evaluate a code block, the results are some ...
0
votes
1
answer
271
views
Org Babel Redirect stderr (-c option requires an argument)
Reading about how to redirect stderr, but it does not work for me.
$ cat bash-redir-stderr.sh
#!/usr/bin/env bash
{
bash $1
} 2>&1
I get:
bash: -c: option requires an argument
..no matter ...
2
votes
1
answer
105
views
How can I make SQL output readable?
I'm trying to find an Emacs replacement for SQL Server Management Studio (SSMS). I have managed to query my Microsoft SQL Server from Emacs – and what a task that was! – through SQL Mode. However, the ...
2
votes
1
answer
631
views
How to replace raw code block output
I would like to execute a python code block to produce new headlines (i.e. modify the current org file programmatically). If I produce raw results with a replace argument, the replace argument seems ...
2
votes
1
answer
594
views
How to use PlantUML Server with Org mode?
plantuml-mode supports execution using a PlantUML server, with (setq plantuml-default-exec-mode 'server). I can set the server location with (setq plantuml-server-url "https://myserver.plantuml....
0
votes
1
answer
107
views
Babel C++ blocks have incorrect indentation
When using a C++ source block in org-mode, the indentation doesn't match that of the C++ major mode.
Viewing the source block in the org file:
Viewing the same code in a C++ mode buffer or using org-...
0
votes
1
answer
82
views
Can I find snippets using yasnippet for the mode of an org-babel block (e.g. python / bash)?
I like snippets. I use yassnippet a lot. I also use babel in org mode. I would quite like to be able to use my snippets in org babel blocks, but they don't work because I am in the wrong mode. Is ...
0
votes
1
answer
24
views
How can I make this section-level Org-Mode header work at the top-level?
I find that the following org-mode header works just fine if I put it in a section
* SQL world
:PROPERTIES:
:header-args:sql: :exports both
:header-args:sql+: :cmdline -S 123.45.0.6,1999 -U sa -P &...
1
vote
2
answers
113
views
When tangling, how to reference code-blocks from different file?
When tangling, I want to use/refer to code-blocks from different file.
Suppose /tmp/1.org file below that contains code block named code_block_in_1_org (that I want to use later).
* This is ~1.org~ ...
6
votes
3
answers
468
views
Can I insert a prefix to Org Babel source code lines on export?
Like, say I have a shell script source code block.
#+BEGIN_SRC shell
echo 'Hello World!'
#+END_SRC
On export, I want the code text to pick up a dollar sign, so $ echo 'Hello World!'. But I only ...
0
votes
1
answer
41
views
org-insert-structure-template on non empty line
When I insert a code block, I usually first mark the current line, before I issue org-insert-structure-template, but can I encapsulate the current line, without selecting it?
Something like this, but ...
0
votes
1
answer
28
views
Org-babel ignores RESULTS when generating beamer?
I'm using Org-babel to generate a bunch of pdfs from a single Org-mode file, compiling using Beamer.
Each subtree starts something like this:
* Introduction
:PROPERTIES:
:EXPORT_FILE_NAME: pdf/...
0
votes
1
answer
78
views
org-mode: How to define then call a Java method using source blocks
I have a super simple example where I have a list, a Java method and a call to this method. It looks like this:
#+name: animals
- dog
- cat
- guinea pig
- horse
#+name: does-contains-cat
#+begin_src ...
0
votes
1
answer
111
views
Fish and org-babel
I am having troubles with the output of a fish session in org-babel. It seems to be related to the bracketed paste, but only happens when :session is used. I was wondering if there is any way to clean ...
1
vote
1
answer
178
views
Tangle babel code to specific location in source file?
Let's say I'm creating many babel code blocks in a growing org-mode buffer and I'm tangling them all to a single file. However, I want certain blocks to appear above others. For example,
#+begin_src ...
2
votes
2
answers
91
views
replace expressions with output in code-blocks before org-babel-tangle
How to evaluate the expressions or functions in a code-block before tangling a source code block?
I generate my init.el file using org-babel-tangle
AND
I'm using chemacs2 - which allows using ...
0
votes
0
answers
22
views
Display custom message after completing org-babel-tangle
I'm using org-babel-tangle to tangle one of my org file into an the emacs config file. After completion, I get a message showing how many blocks have been tangled like Tangled 48 code blocks from My-...
0
votes
1
answer
49
views
Org-mode code blocks and results side-by-side in beamer export?
I'm using org-mode to generate slides for a class I'm teaching, and one of the things I do is use org-babel to show code snippets, run them and display the results.
However, in the generated Beamer ...
0
votes
1
answer
56
views
lexical binding in a tangled init.el file
How can I enable lexical binding in an init.el file that is tangled from an org mode file? I have an org mode file called Emacs.org which is used to tangle the init.el file using the command M-x org-...