10

What command-line arguments do I use to get Emacs to export an org-mode file to a Beamer PDF? (I want to create a Makefile that produces a PDF when the user runs make.)

I tried following this answer but couldn't get it to work:

$ emacs --batch foo.org -f org-beamer-export-to-pdf
Symbol's function definition is void: org-beamer-export-to-pdf
$ emacs --batch -l ox-beamer foo.org -f org-beamer-export-to-pdf
Cannot open load file: ox-beamer

The above error comes from the fact that the org-mode files are in a custom location and my ~/.emacs.d/init.el is not loaded (--batch implies -q a.k.a. --no-init-file).

If I tell Emacs to load my init file it will work:

$ emacs --batch -l ~/.emacs.d/init.el foo.org -f org-beamer-export-to-pdf

However, this doesn't work for other users that use ~/.emacs or ~/.emacs.el instead of ~/.emacs.d/init.el. I tried telling Emacs to load user-init-file but it didn't work:

$ emacs --batch --eval '(load user-init-file)' foo.org -f org-beamer-export-to-pdf
Wrong type argument: stringp, nil

Assuming all users can successfully press C-x C-e l P to export a Beamer PDF when using Emacs interactively, what non-interactive command will produce a PDF?

  • eval (require 'org) or something like that – your init file is doing some loading that --batch is prohibiting. – Sean Allred Mar 30 '15 at 3:56
  • Try something like emacs -u $USER --batch --eval '(message "-----> My user-init-file: "%s" user-init-file)'. If you don't load your init file, you probably need to require ox-beamer. – mutbuerger Mar 30 '15 at 16:31
  • You might find github.com/fniessen/orgmk useful. – Ista Mar 31 '15 at 18:30
8

The following worked for me:

emacs \
    -u "$(id -un)" \
    --batch \
    --eval '(load user-init-file)' \
    foo.org \
    -f org-beamer-export-to-pdf

Thanks go to @mutbuerger for the hint to pass -u <username> to get user-init-file defined.

  • In my case, I found that I needed to remove (load user-init-file) and replace it with specific (require 'blah) s-expressions for it to work (using emacs 24.5.1). – Mark Jun 28 '17 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.