19

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?

3
  • eval (require 'org) or something like that – your init file is doing some loading that --batch is prohibiting. Commented Mar 30, 2015 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
    Commented Mar 30, 2015 at 16:31
  • 1
    You might find github.com/fniessen/orgmk useful.
    – Ista
    Commented Mar 31, 2015 at 18:30

2 Answers 2

11

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.

1
  • 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
    Commented Jun 28, 2017 at 15:32
5

I'm using self-compiled emacs 27.0.9x on Linux and macOS. To generate my presentations, I use org-mode.

emacs -Q \
  --batch "(require 'ox-beamer)" \
  <input>.org -f org-beamer-export-to-pdf

works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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