Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:48:48+00:00 2026-06-16T17:48:48+00:00

I would like to use Emacs in batch mode to export a number of

  • 0

I would like to use Emacs in batch mode to export a number of org files to HTML from the command-line. And I would like to get the same result than interactively using C-cC-eh, in particular:

  • honor file-local variables (such as org-export-publishing-directory)
  • honor all options specified through #+KEYWORD: headlines

Starting from the example given in org-export-as-html-batch, I got to this point:

emacs --batch \
    --visit=/tmp/foo.org \
    --eval "(defun safe-local-variable-p (sym val) t)" \
    --funcall hack-local-variables \
    --eval "(setq org-export-headline-levels 4)" \
    --funcall org-export-as-html-batch

However, some problems remain:

  • I need to explicitly specify the headline level and I fail to see why all other #+OPTIONS are honored (like toc:nil) but not this one

  • I had to manually trigger file-local variables parsing using hack-local-variables (I guess it is not automatically done in batch mode) but more importantly I had to resort to a hack to mark all local variables as safe (I’m sure there is much space for improvement here).


NB:

In case it matters, I’m using emacs 23.2.1 (Debian Squeeze flavour)

Here is a sample org file on which I tested this:

#+TITLE: Foo
#+OPTIONS: H:4 toc:nil author:nil

* 1
** 2
*** 3
**** 4

# Local Variables:
#  org-export-publishing-directory: "/some/where";
# End:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:48:49+00:00Added an answer on June 16, 2026 at 5:48 pm

    I eventually got the following script, which seems to fulfill all my requirements:

    #!/bin/sh
    ":"; exec emacs --script "$0" -- "$@" # -*-emacs-lisp-*-
    ;; 
    ;; Usage:
    ;;    org2html FILE1 [FILE2 ...]
    
    
    ;; Mark org-related variables as safe local variables,
    ;; regardless of their value.
    (defun my/always-safe-local-variable (val) t)
    (dolist (sym '(org-export-publishing-directory
                   org-export-html-preamble
                   org-export-html-postamble))
      (put sym 'safe-local-variable 'my/always-safe-local-variable))
    
    
    (defun my/org-export-as-html (filename)
      "Export FILENAME as html, as if `org-export-to-html' had been called
    interactively.
    
    This ensures that `org-export-headline-levels' is correctly read from
    the #+OPTIONS: headline."
      (save-excursion
        (find-file filename)
        (message "Exporting file `%s' to HTML" filename)
        (call-interactively 'org-export-as-html)))
    
    (mapcar 'my/org-export-as-html
            (cdr argv)) ;; "--" is the first element of argv
    

    A few notes on this script:

    • The executable emacs-lisp script trick comes from this question.

    • The only way I found to use the org-export-headline-levels value from the #+OPTIONS: headline is to call org-export-as-html interactively, instead of org-export-as-html-batch.

    • hack-local-variables does not need to be explicitly called, provided that local variables are marked as safe before the file is opened.

    • I think it is better to only mark org-related variables as safe, using the safe-local-variable symbol property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use Yahoo to get stock prices from within an Emacs
I use emacs to edit a number of file types, and would like an
I would like to use the dired mode of emacs as my file browser.
I'm using emacs with cdlatex-mode to edit LaTeX files. I would like to know
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use the ispell-buffer command in Emacs. It uses the English
I am new to emacs and I would like to use emacs-rails for editing
I would like to use the logout function from Django but not sure how
Emacs 24 added optional lexical bindings for local variables. I would like to use
I would like to use emacs to edit googleplus posts. Is there a script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.