From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Example of Make file for Org Mode LaTeX to pdf Date: Mon, 07 Mar 2016 09:20:04 -0500 Message-ID: <87oaaq5q0b.fsf@alphaville.usersys.redhat.com> References: <4A383BD1-2B7C-4AF3-909E-5D1561B1F933@airmail.net> <87r3fn4frl.fsf@ucl.ac.uk> <87twkism4d.fsf@hornfels.zedat.fu-berlin.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1acw1H-0000Zu-RH for emacs-orgmode@gnu.org; Mon, 07 Mar 2016 09:20:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1acw1D-0005Vk-Pa for emacs-orgmode@gnu.org; Mon, 07 Mar 2016 09:20:23 -0500 Received: from plane.gmane.org ([80.91.229.3]:56246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1acw1D-0005VY-Ie for emacs-orgmode@gnu.org; Mon, 07 Mar 2016 09:20:19 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1acw1B-0004j9-Dq for emacs-orgmode@gnu.org; Mon, 07 Mar 2016 15:20:17 +0100 Received: from pool-74-104-158-160.bstnma.fios.verizon.net ([74.104.158.160]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Mar 2016 15:20:17 +0100 Received: from ndokos by pool-74-104-158-160.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Mar 2016 15:20:17 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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