If you can do it from within emacs, then you can do it from the command line with something like this for HTML:
emacs --batch --eval "(require 'org)" notes.org --funcall org-html-export-to-html
or for PDF:
emacs --batch --eval "(require 'org)" appts.org --funcall org-latex-export-to-pdf
This assumes that you use the Org mode that is bundled with emacs: otherwise, the evaluation of the (require 'org)
form will fail. If you are installing Org mode from the git repo or from MELPA, you will need additional configuration.
See the emacs man page for an explanation of --batch
(note that it makes emacs to NOT load your init file), --eval
and --funcall
.
Note also that you don't get a choice for the output file name: for the input file notes.org
, it will be notes.html
, just replacing the org
suffix with the html
suffix.
EDIT: a comment by the OP mentions that the emacs init file needed to be loaded to provide various settings and that the way to do that is to use a command like this:
emacs --batch --load ~/.emacs --eval "(require 'org)" notes.org --funcall org-html-export-to-html
My recommendation however would be to separate the settings that are needed for org export and put them in a separate file, e.g. ~/.emacs.d/my-org-export-settings.el
. That way, all the export settings are in one file and only that file needs to be loaded for exporting from the command line; also ~/.emacs
(or ~/.emacs.d/init.el
) can use it as well by invoking (load-file "~/.emacs.d/my-org-export-settings.el")
, so that there is a single well-defined place where the settings affecting export can be set.
The reason for the recommendation is that the main init file inevitably grows since it accumulates settings for all sorts of different emacs packages. Then starting up emacs takes longer (and longer and longer...): that's OK if you start emacs once and then live in it for weeks on end as many of us do, but if you want to invoke it from the command line to do just one thing and exit, it becomes more and more annoying to wait for everything to be initialized before doing that one thing and then exiting, throwing all that initialization away. If you have a small, separate file that includes just what is necessary for your Org export needs, you don't need to load the main init file: you just load the small file and you are done in a jiffy.