On Debian Stretch, I'm trying to export this file called test.org
# -*- org-confirm-babel-evaluate: nil -*-
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:nil d:(not "LOGBOOK") date:t e:t
#+OPTIONS: email:nil f:t inline:t num:t p:nil pri:nil prop:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t title:t toc:t todo:t |:t
#+TITLE: Emacs Batch Test
#+DATE:
#+EMAIL:
#+LANGUAGE: en
#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport
#+CREATOR: Emacs 25.2.1 (Org mode 8.3.4)
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS:
#+LATEX_HEADER:
#+LATEX_HEADER_EXTRA:
#+DESCRIPTION:
#+KEYWORDS:
#+SUBTITLE:
* Section 1
This is some text.
* Section 2
#+NAME: testcode
#+HEADER: :session R:emacsbatchtest
#+BEGIN_SRC R :exports both :results output
library(arm)
example(display)
#+END_SRC
using this elisp script called test.el
(progn
(require 'cl-lib)
(require 'org)
(require 'ox)
(require 'ox-latex)
(require 'ox-publish)
(defun bh-export-batch-dot-org ()
(find-file "test.org")
(org-latex-export-to-pdf nil nil nil nil nil)
)
(bh-export-batch-dot-org)
)
using this command line:
$ emacs -batch -l test.el
Emacs produces the PDF just fine, but it fails to execute the R source code. I can try to set org-confirm-babel-evaluate
in my .emacs or in the file; it makes no difference in the results (and I'm not sure that in-file setting is syntactically correct; it doesn't seem to do anything). I've looked, but I haven't found a solution on stackexchange or elsewhere that seems to work.
If I export the .org file manually, it executes the R source code and produces the complete PDF.
Here are a few possibly pertinent snippets from the custom-set-variables
section of my .emacs:
'(org-babel-load-languages
(quote
((emacs-lisp . t)
(J . t)
(calc . t)
(shell . t)
(ditaa . t)
(dot . t)
(plantuml . t)
(python . t)
(octave . t)
(ledger . t)
(sqlite . t)
(stan . t)
(R . t))))
'(org-confirm-babel-evaluate t)
'(org-export-backends (quote (ascii beamer html icalendar latex md odt)))
I've also tried this on Windows Server 2016 with cygwin bash, and it fails to produce anything. I'd appreciate insights into how to make this work on both platforms. While it would be nice, the solution doesn't need to be the same on both.
EDIT: I have tried exporting this file two ways: by setting org-confirm-babel-evaluate
to nil in my .emacs (not shown in this example) or by setting it to nil in a file variable in the first line of test.org (shown here). The syntax shown here was incorrect, missing a ;
after nil
. I fixed that, and now it no longer queries about R execution.
It does query for two other reasons. First, it asks if it can apply the local variables. I've now responded !
, and it no longer asks.
Second, it asks for the R starting project directory if there's not a live ESS session by the name R:emacsbatchtest
. I fixed that by adding
#+HEADER: :dir FQPN
to the source code block headers (where FQPN is the fully-qualified path name of the current directory).
Now I have a file that exports interactively with no interaction after the C-c C-e l o
.
Batch mode still fails to run the source or produce the pdf, presumably because '(safe-local-variable-values (quote ((org-confirm-babel-evaluate))))
is now in my init.el, which is not called in batch. As soon as I determine how to set that, I will try it.
EDIT 2:
As I noted in a comment, this works well on Linux, but it fails on W7.
By "this" I mean running emacs --batch --eval '(setq org-confirm-babel-evaluate nil)' -l test.el
using the previously provided test.el
file and a slightly modified test.org
file:
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:nil d:(not "LOGBOOK") date:t e:t
#+OPTIONS: email:nil f:t inline:t num:t p:nil pri:nil prop:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t title:t toc:t todo:t |:t
#+TITLE: Emacs Batch Test
#+DATE:
#+EMAIL:
#+LANGUAGE: en
#+SELECT_TAGS: export
#+EXCLUDE_TAGS: noexport
#+CREATOR: Emacs 25.2.1 (Org mode 8.3.4)
#+LATEX_CLASS: article
#+LATEX_CLASS_OPTIONS:
#+LATEX_HEADER:
#+LATEX_HEADER_EXTRA:
#+DESCRIPTION:
#+KEYWORDS:
#+SUBTITLE:
* Section 1
This is some text.
* Section 2
#+NAME: testcode1
#+HEADER: :session R:emacsbatchtest
#+HEADER: :dir FQDN
#+BEGIN_SRC R :exports both :results output
library(arm)
example(display)
#+END_SRC
* Section 3
#+NAME: testcode2
#+HEADER: :session R:emacsbatchtest
#+BEGIN_SRC R :exports both :results output
example(sim)
#+END_SRC
* Section 4
#+NAME: elispexample
#+HEADER: :exports both :results value
#+BEGIN_SRC emacs-lisp
(setq mylist '(a b c))
(cadr mylist)
#+END_SRC
I dropped the file local variable, thanks to setting it in the --eval
section, I added the :dir header in the first code block, and I added a second R code block and an emacs-lisp code block.
On GNU/Linux, it executes each code block and publishes the result in a PDF.
On W7, it produces test.tex
, but it fails to produce the PDF.
In addition, neither of the two R code blocks are executed, but the emacs-lisp code block is executed.
I think that means there's something wrong with executing R as a function call from inside org-mode and there's something wrong with finding pdflatex.
Perhaps it can't start R successfully; Cygwin has its challenges:
$ R
Fatal error: you must specify '--save', '--no-save' or '--vanilla'
Stealing from my init.el, perhaps this works:
$ /cygdrive/c/emacs/emacs-25.2-x86_64/bin/runemacs.exe --batch --eval "(setq org-confirm-babel-evaluate nil)" --eval '(setq ess-directory-containing-R "c:")' --eval '(setq ess-rterm-version-paths "C:/R/R-3.4.3/bin/x64/Rterm.exe")' --eval '(setq org-babel-R-command "c:/R/R-3.4.3/bin/R --slave --no-save")' -l test.el
Nope.
Does anyone see the problem? I think I tried everything pertinent I see in my init.el
.