4
votes

When using `org-export-as-html' in batch mode the html produced from code blocks has no syntax coloring.

How do I enable the syntax coloring in batch mode?

EDIT:

From the terminal I run emacs --script make.el. In make.el I include org and org-html and eventually call (org-export-as-html 3)

The following will bold/underline keywords but still no color:

    (add-to-list 'load-path "~/elisp/org/contrib/lisp")
    (require 'htmlize)
    (setq c-standard-font-lock-fontify-region-function 'font-lock-default-fontify-region) ;; fixes bug
    (org-export-as-html 3)

EDIT 2:

A couple more things I've tried - they make no difference:

    (setq org-src-fontify-natively t)
    (org-babel-do-load-languages 'org-babel-load-languages '((java .t)))

I've also tried loaded my entire .emacs

I'm using GNU Emacs 24.3.1 and Org 7.9.2

1
Try emacs --batch -l ~/.emacs ...abo-abo
Hi can you post the code you are using to export html? I guess you are not requireing the htmlize library which is needed to export syntax highlighted htmluser2053036
Have you tried loading htmlize, e.g. (load "~/elisp/org/contrib/lisp/htmlize"). That did the trick for me.slu

1 Answers

0
votes

Apparently, if you use the color-theme library, then (for occult reasons about which I have no clue yet) you can have colored outputs through htmlize when exporting in batch mode.

For example, evaluating the following code in an org buffer to export makes htmlize use colors defined by means of a theme, and that works when exporting both in batch mode and interactively (by creating a temporary frame and setting the appropriate color theme to avoid messing up the frame containing the org buffer to export):

(require 'cl)                           ;for `lexical-let'

(add-hook
 ;; This is for org 8.x (use `org-export-first-hook' for earlier versions).
 (make-local-variable 'org-export-before-processing-hook)
 (lambda (backend)
   (add-to-list (make-local-variable 'load-path) (expand-file-name "./etc"))
   (require 'color-theme)
   (color-theme-initialize)

   (when (display-graphic-p)            ;Are we running in interactive mode?
     ;; If so, create a temporary frame to install the color theme used by
     ;; htmlize:
     (lexical-let ((buff (switch-to-buffer-other-frame (current-buffer)))
                   (frame (selected-frame)))
       (setq color-theme-is-global nil)
       (make-frame-invisible frame)
       ;; Schedule deletion of temporary frame:
       (add-to-list
        ;; The following is for org 8.x (earlier versions use other hooks like
        ;; `org-latex-final-hook').
        (make-local-variable 'org-export-filter-final-output-functions)
        (lambda (string backend info) (delete-frame frame)))))

   ;; Install color theme.
   (color-theme-blippblopp)))