emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Example of Make file for Org Mode LaTeX to pdf
@ 2016-03-05  5:43 Robert Love
  2016-03-06 13:26 ` Myles English
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Robert Love @ 2016-03-05  5:43 UTC (permalink / raw)
  To: emacs-orgmode list

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

Does anyone have a make file example that has emacs load an .org file, process it into LaTeX and export as PDF, all from the command line without the user doing anything more than type ‘make’?   All examples appreciated.

— 
Bob Love                    
"Insisting on perfect safety is for people who don't have the balls to live in the real world." -- Mary Shafer, NASA Dryden 





[-- Attachment #2: Type: text/html, Size: 2828 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  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
  2 siblings, 0 replies; 9+ messages in thread
From: Myles English @ 2016-03-06 13:26 UTC (permalink / raw)
  To: Robert Love; +Cc: emacs-orgmode list


Hello Bob,

Robert Love writes:

> Does anyone have a make file example that has emacs load an .org file,
> process it into LaTeX and export as PDF, all from the command line
> without the user doing anything more than type ‘make’?   All examples
> appreciated.

Fraid I don't have a makefile but I do have a CMakeLists.txt that CMake
uses to generate a makefile.  This method uses a CMake module called
UseLATEX.cmake to generate the PDF.  I haven't used it for a couple of
years so it might be a bit outdated.

The CMakeLists.txt also contains an example of how to generate all the R
graphics for the document.

If it looks a bit over complicated for your requirements perhaps just
looking at the line that contains "COMMAND emacs" would be useful for
you.

Hopefully someone else will show a nice, simple, self-contained example.

Myles


#+BEGIN_SRC sh :tangle CMakeLists.txt
      cmake_minimum_required(VERSION 2.8)
      
      project(thesis NONE)
            
      include(/usr/share/cmake-2.8/Modules/UseLATEX.cmake)
      
      # Set R executable
      set(R_COMPILE "/usr/bin/Rscript")
            # Set the location of data files
            ##set(DATA_DIR data)
            # Set the location of the directory for image files
      set(IMAGE_DIR graphicsauto)
      
            # Get a list of R files
      file(GLOB_RECURSE R_FILES "R/*.R")
      
      file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/R DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
      file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR})
      
      foreach(file ${R_FILES})
      message("processing ${file}")
      get_filename_component(basename "${file}" NAME_WE)
      
                # Command to run R
      if(R_COMPILE)
          message("Adding ........... ${CMAKE_CURRENT_BINARY_DIR}/R/${basename}.R")
  
          add_custom_command(
              OUTPUT
              ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR}/${basename}.eps
              DEPENDS
              ${CMAKE_CURRENT_BINARY_DIR}/R/${basename}.R
                      #      ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR}/${DATA_DIR}
              COMMAND
              ${R_COMPILE}
              ARGS
              ${CMAKE_CURRENT_BINARY_DIR}/R/${basename}.R
              ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR}/${basename}.eps
          )
          message("Running ${R_COMPILE} ${CMAKE_CURRENT_BINARY_DIR}/R/${basename}.R ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR}/${basename}.eps")
            
          endif(R_COMPILE)
            
                # Make a list of all R files (for ADD_LATEX_DOCUMENT depend)
          set(ALL_R_FILES ${ALL_R_FILES}
              ${CMAKE_CURRENT_BINARY_DIR}/${IMAGE_DIR}/${basename}.eps
          )
          endforeach(file)
            
            # ------- export mainThesis.org -----------------------
          latex_get_output_path(OUTPUT_DIR)  
          file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/mainThesis.org DESTINATION ${OUTPUT_DIR}/ )
          file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/thesis.el DESTINATION ${OUTPUT_DIR}/ )
      
          add_custom_target( orgfile ALL
              DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mainThesis.org )
      
          add_custom_target( elfile ALL
              DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thesis.el )
          
          add_custom_command(
              OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mainThesis.tex
              COMMAND emacs -Q --batch --eval \"(progn
                  (add-to-list 'load-path
                         (expand-file-name \\"~/.emacs.d/plugins/org-mode/lisp/\\"))
                       (add-to-list 'load-path
                      (expand-file-name \\"~/.emacs.d/plugins/org-mode/contrib/lisp/\\" t))
                  (require 'org)
                       (require 'ox)
                  (require 'org-exp)
                       (require 'org-inlinetask)
                  (require 'ob-plantuml)
                       (setq org-plantuml-jar-path \\"/home/myles/Downloads/plantuml.jar\\")
                       (org-babel-do-load-languages
                        'org-babel-load-languages
                      '((emacs-lisp . t)
                          (sh . t)
                          (plantuml . t)))
                       (setq org-confirm-babel-evaluate nil)
                       (setq org-latex-listings 'minted)
                  (setq org-latex-with-hyperref nil)
                     (add-to-list 'org-latex-packages-alist '(\\"\\" \\"minted\\"))
  
  (add-to-list 'org-latex-classes 
    '(\\"mynewthesis\\" \\"\\\\\\documentclass[11pt]{mythesis}\\"
     (\\"\\\\\\chapter{%s}\\" . \\"\\\\\\chapter*{%s}\\")
     (\\"\\\\\\section{%s}\\" . \\"\\\\\\section*{%s}\\")
     (\\"\\\\\\subsection{%s}\\" . \\"\\\\\\subsection*{%s}\\")
     (\\"\\\\\\subsubsection{%s}\\" . \\"\\\\\\subsubsection*{%s}\\")
     (\\"\\\\\\paragraph{%s}\\" . \\"\\\\\\paragraph*{%s}\\")))
                     (setq org-export-with-todo-keywords nil)
                 (load-library \\"/home/myles/lib/lisp/my-export.el\\")
                 (add-to-list 'org-export-before-parsing-hook 'my-export-delete-headlines-tagged-noheading)
                 (add-to-list 'org-export-filter-link-functions 'my-autoref-filter-link-func)
              (load-file \\"thesis.el\\")
                  (find-file \\"${CMAKE_CURRENT_BINARY_DIR}/mainThesis.org\\")
                  (org-latex-export-to-latex))\"
              DEPENDS orgfile elfile
              COMMENT "Exporting orgmode file to LaTeX using emacs")
          
          add_custom_target( mainfile ALL
              DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/mainThesis.tex )
            # ------ end mainThesis.org ---------------------------
          
            # add_custom_command(
            #         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/master.tex
            #         COMMAND echo "\\\\input{mainThesis.tex}" > ${CMAKE_CURRENT_BINARY_DIR}/master.tex
            #         DEPENDS orgfile
            #         COMMENT "Writing file master.tex")
          
            # add_custom_target( masterfile ALL
            #         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/master.tex )
          
          add_latex_document(master.tex
              BIBFILES texlib/mybiblatex.bib
              INPUTS biber.conf
              phd_papers.bib
              tex/title.tex
              tex/titleBasic.tex
              tex/abstract.tex
              tex/sharedMemory_sec.tex
                     texlib/mystyle.sty
                     tex/linked_nodes_test.tex
                     IMAGE_DIRS ${IMAGE_DIR} ../graphics/thirdParty ../graphics/VE
                     DEPENDS ${ALL_R_FILES}
                     DEFAULT_PDF
                     USE_NOMENCL)
#+END_SRC

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  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
  2 siblings, 0 replies; 9+ messages in thread
From: John Kitchin @ 2016-03-06 13:40 UTC (permalink / raw)
  To: Robert Love; +Cc: emacs-orgmode list

* Export org-files using a Makefile

#+BEGIN_SRC makefile :tangle Makefile
pdf:
        rm -f make-org.pdf
        emacs -batch make-org.org -f org-latex-export-to-pdf
        open make-org.pdf
#+END_SRC


works for me.

Robert Love writes:

> Does anyone have a make file example that has emacs load an .org file, process it into LaTeX and export as PDF, all from the
> command line without the user doing anything more than type ‘make’? All examples appreciated.
>
> —
> Bob Love
> "Insisting on perfect safety is for people who don't have the balls to live in the real world." -- Mary Shafer, NASA Dryden


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  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
  2 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2016-03-06 18:34 UTC (permalink / raw)
  To: Robert Love; +Cc: emacs-orgmode list

On Friday,  4 Mar 2016 at 23:43, Robert Love wrote:
> Does anyone have a make file example that has emacs load an .org file,
> process it into LaTeX and export as PDF, all from the command line
> without the user doing anything more than type ‘make’?  All examples
> appreciated.

I don't a makefile but I do have a single shell command that exports my
agenda to an ics file for uploading to google's calendar:

--8<---------------cut here---------------start------------->8---
emacs -Q --batch --debug-init \
    --directory=${HOME}/s/emacs \
    --load=custom.el \
    --load=esf-org.el --visit=${DIARY}.org --eval='(org-icalendar-export-to-ics)'
--8<---------------cut here---------------end--------------->8---

HTH
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.91.1, Org release_8.3.4-626-gb62d55

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  2016-03-06 18:34 ` Eric S Fraga
@ 2016-03-07  8:55   ` Loris Bennett
  2016-03-07 14:20     ` Nick Dokos
  2016-03-07 15:26     ` Eric S Fraga
  0 siblings, 2 replies; 9+ messages in thread
From: Loris Bennett @ 2016-03-07  8:55 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Friday,  4 Mar 2016 at 23:43, Robert Love wrote:
>> Does anyone have a make file example that has emacs load an .org file,
>> process it into LaTeX and export as PDF, all from the command line
>> without the user doing anything more than type ‘make’?  All examples
>> appreciated.
>
> I don't a makefile but I do have a single shell command that exports my
> agenda to an ics file for uploading to google's calendar:
>
> emacs -Q --batch --debug-init \
>     --directory=${HOME}/s/emacs \
>     --load=custom.el \
>     --load=esf-org.el --visit=${DIARY}.org --eval='(org-icalendar-export-to-ics)'
>
> HTH

I was interested in doing exactly this, but got the error described
here:

http://article.gmane.org/gmane.emacs.orgmode/105491

Would you be able to share what you load in custom.el and esf-org.el, or
a least explain what needs to be done?

Cheers,

Loris

-- 
This signature is currently under construction.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  2016-03-07  8:55   ` Loris Bennett
@ 2016-03-07 14:20     ` Nick Dokos
  2016-03-07 15:26     ` Eric S Fraga
  1 sibling, 0 replies; 9+ messages in thread
From: Nick Dokos @ 2016-03-07 14:20 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  2016-03-07  8:55   ` Loris Bennett
  2016-03-07 14:20     ` Nick Dokos
@ 2016-03-07 15:26     ` Eric S Fraga
  2016-03-07 16:10       ` Loris Bennett
  1 sibling, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2016-03-07 15:26 UTC (permalink / raw)
  To: Loris Bennett; +Cc: Emacs Org mode mailing list

On Monday,  7 Mar 2016 at 09:55, Loris Bennett wrote:

[...]

> Would you be able to share what you load in custom.el and esf-org.el, or
> a least explain what needs to be done?

My custom.el is the emacs customisations (for variables and faces that
usually ends up in your .emacs) and esf-org.el is my full org
initialisation which is rather large and convoluted.  There is nothing
in either of those that should help solve the problem you are
having... but, then again, I'm not sure why you are having the problem
you encounter!

Do you get the same backtrace with -Q as in the previous post?

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.90.1, Org release_8.3.3-535-g7213aa

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  2016-03-07 15:26     ` Eric S Fraga
@ 2016-03-07 16:10       ` Loris Bennett
  2016-03-09  3:38         ` Robert Love
  0 siblings, 1 reply; 9+ messages in thread
From: Loris Bennett @ 2016-03-07 16:10 UTC (permalink / raw)
  To: emacs-orgmode

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> On Monday,  7 Mar 2016 at 09:55, Loris Bennett wrote:
>
> [...]
>
>> Would you be able to share what you load in custom.el and esf-org.el, or
>> a least explain what needs to be done?
>
> My custom.el is the emacs customisations (for variables and faces that
> usually ends up in your .emacs) and esf-org.el is my full org
> initialisation which is rather large and convoluted.  There is nothing
> in either of those that should help solve the problem you are
> having... but, then again, I'm not sure why you are having the problem
> you encounter!
>
> Do you get the same backtrace with -Q as in the previous post?

Apart from the Debian gubbins, yes.  However, I seem to have solved the
problem.

With the following ~/.emacs_minimal

  (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))

I get:

  $ emacs /home/loris/org/gtd.org -Q -batch --load ~/.emacs_minmal -eval '(org-icalendar-export-to-ics))' --kill
  Symbol's value as variable is void: org-agenda-default-appointment-duration

However, with ~/.emacs_minimal as

  (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
  (org-agenda-to-appt)

I get

  $ emacs /home/loris/org/gtd.org -Q -batch --load ~/.emacs_minmal -eval '(org-icalendar-export-to-ics))' --kill
  No event to add
  Saving file /home/loris/org/gtd.ics...
  Wrote /home/loris/org/gtd.ics

So I was just being too minimalist.  org-agenda-to-appt seems to be some
cruft I copied from here:

  http://sachachua.com/blog/2007/11/setting-up-appointment-reminders-in-org/

I'll go and look what it does whether I still need it.

Cheers,

Loris

-- 
This signature is currently under construction.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Example of Make file for Org Mode LaTeX to pdf
  2016-03-07 16:10       ` Loris Bennett
@ 2016-03-09  3:38         ` Robert Love
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Love @ 2016-03-09  3:38 UTC (permalink / raw)
  To: Loris Bennett; +Cc: emacs-orgmode

I have gotten many good ideas from these replies to my question.  Thanks to all.

> On Mar 7, 2016, at 10:10 AM, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> 
> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> 
>> On Monday,  7 Mar 2016 at 09:55, Loris Bennett wrote:
>> 
>> [...]
>> 
>>> Would you be able to share what you load in custom.el and esf-org.el, or
>>> a least explain what needs to be done?
>> 
>> My custom.el is the emacs customisations (for variables and faces that
>> usually ends up in your .emacs) and esf-org.el is my full org
>> initialisation which is rather large and convoluted.  There is nothing
>> in either of those that should help solve the problem you are
>> having... but, then again, I'm not sure why you are having the problem
>> you encounter!
>> 
>> Do you get the same backtrace with -Q as in the previous post?
> 
> Apart from the Debian gubbins, yes.  However, I seem to have solved the
> problem.
> 
> With the following ~/.emacs_minimal
> 
>  (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
> 
> I get:
> 
>  $ emacs /home/loris/org/gtd.org -Q -batch --load ~/.emacs_minmal -eval '(org-icalendar-export-to-ics))' --kill
>  Symbol's value as variable is void: org-agenda-default-appointment-duration
> 
> However, with ~/.emacs_minimal as
> 
>  (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
>  (org-agenda-to-appt)
> 
> I get
> 
>  $ emacs /home/loris/org/gtd.org -Q -batch --load ~/.emacs_minmal -eval '(org-icalendar-export-to-ics))' --kill
>  No event to add
>  Saving file /home/loris/org/gtd.ics...
>  Wrote /home/loris/org/gtd.ics
> 
> So I was just being too minimalist.  org-agenda-to-appt seems to be some
> cruft I copied from here:
> 
>  http://sachachua.com/blog/2007/11/setting-up-appointment-reminders-in-org/
> 
> I'll go and look what it does whether I still need it.
> 
> Cheers,
> 
> Loris
> 
> -- 
> This signature is currently under construction.


— 
Bob Love                    
"Neil Armstrong was the first human on the moon. Neil A backwards is alien." 

Listening to:  Promontory  by  Circa Paleo

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-03-09  3:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2016-03-07 15:26     ` Eric S Fraga
2016-03-07 16:10       ` Loris Bennett
2016-03-09  3:38         ` Robert Love

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).