From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Example of Make file for Org Mode LaTeX to pdf
Date: Mon, 07 Mar 2016 09:20:04 -0500 [thread overview]
Message-ID: <87oaaq5q0b.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: 87twkism4d.fsf@hornfels.zedat.fu-berlin.de
Here's a simple (GNU make) makefile to export something in batch mode:
--8<---------------cut here---------------start------------->8---
%.html: %.org
emacs -batch -l batch-export.el --eval "(batch-org-export-as 'html)" $<
%.pdf: %.tex
latexmk --shell-escape -pdf -xelatex $<
%.tex: %.org
emacs -batch -l batch-export.el --eval "(batch-org-export-as 'latex)" $<
--8<---------------cut here---------------end--------------->8---
Starting from foo.org, say
make foo.html foo.pdf
to produce the indicated exports.
I don't remember where I picked up the batch-org-export-as function, but
whoever wrote it, thanks! You might be able to simplify it: I've been
carrying it around unchanged for a couple of years, so there may be
simpler ways to do things nowadays, but AFAIK it works well with org
8.x. Here's the bach-export.el file (obviously the path in the second
line will need to be changed to suit your circumstances - I'm not sure
if the (require 'org-loaddefs) needs to be changed if e.g. you are using
org from ELPA - you might have to add a (package-initialize) too in this
case):
--8<---------------cut here---------------start------------->8---
;;; -*- mode: emacs-lisp -*-
(add-to-list 'load-path (expand-file-name "~/src/emacs/org/org-mode/lisp"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(setq org-export-backends '(html latex))
(require 'org-loaddefs)
(defun org-export-file-to (backend src dest)
(with-temp-buffer
(insert-file-contents src)
(org-export-to-file backend dest)))
(setq file-suffixes
'((html . ".html")
(latex . ".tex")
(pdf . ".pdf")))
(defun org-export-dest (backend f)
(concat (file-name-sans-extension f) (cdr (assoc backend file-suffixes))))
(defun batch-org-export-as (backend &optional noforce)
"Run `org-export-as' with the given backend on the files remaining on the command line.
Use this from the command line, with `-batch'; it won't work in
an interactive Emacs. Each file is processed even if an error
occurred previously. For example, invoke \"emacs -batch -f
batch-byte-compile $emacs/ ~/*.el\". If NOFORCE is non-nil,
don't recompile a file that seems to be already up-to-date."
;; command-line-args-left is what is left of the command line, from
;; startup.el.
(defvar command-line-args-left) ;Avoid 'free variable' warning
(if (not noninteractive)
(error "`batch-org-export-as' is to be used only with -batch"))
(let ((error nil))
(while command-line-args-left
(if (file-directory-p (expand-file-name (car command-line-args-left)))
;; Directory as argument.
(let (source dest)
(dolist (file (directory-files (car command-line-args-left)))
(if (and (string-match emacs-lisp-file-regexp file)
(not (auto-save-file-name-p file))
(setq source
(expand-file-name file
(car command-line-args-left)))
(setq dest (org-export-dest backend source))
(file-exists-p dest)
(file-newer-than-file-p source dest))
(if (null (org-export-file-to backend source dest))
(setq error t)))))
;; Specific file argument
(let* ((source (car command-line-args-left))
(dest (org-export-dest backend source)))
(if (or (not noforce)
(or (not (file-exists-p dest))
(file-newer-than-file-p source dest)))
(if (null (org-export-file-to backend (car command-line-args-left) dest))
(setq error t)))))
(setq command-line-args-left (cdr command-line-args-left)))
(kill-emacs (if error 1 0))))
--8<---------------cut here---------------end--------------->8---
HTH.
--
Nick
next prev parent reply other threads:[~2016-03-07 14:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-05 5:43 Example of Make file for Org Mode LaTeX to pdf Robert Love
2016-03-06 13:26 ` Myles English
2016-03-06 13:40 ` John Kitchin
2016-03-06 18:34 ` Eric S Fraga
2016-03-07 8:55 ` Loris Bennett
2016-03-07 14:20 ` Nick Dokos [this message]
2016-03-07 15:26 ` Eric S Fraga
2016-03-07 16:10 ` Loris Bennett
2016-03-09 3:38 ` Robert Love
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87oaaq5q0b.fsf@alphaville.usersys.redhat.com \
--to=ndokos@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).