8
votes

In org-mode, I'd like to specify different export options for different export types, i.e. numbered headings and a table of contents for exporting to LaTeX/PDF, no numbering and no table of contents for exporting to HTML.

Is it possible to do this without having to manually edit the export options every time?

1

1 Answers

6
votes

In ox.el (the Generic Export Engine for Org Mode) there is a filter system:

Filters allow end-users to tweak easily the transcoded output. They are the functional counterpart of hooks, as every filter in a set is applied to the return value of the previous one.

One of the filters is :filter-options:

`:filter-options' applies to the property list containing export
options.  Unlike to other filters, functions in this list accept
two arguments instead of three: the property list containing
export options and the back-end.  Users can set its value through
`org-export-filter-options-functions' variable.

That means you can define a function similar to this one:

(defun my-org-export-change-options (plist backend)
  (cond 
    ((equal backend 'html)
     (plist-put plist :with-toc nil)
     (plist-put plist :section-numbers nil))
    ((equal backend 'latex)
     (plist-put plist :with-toc t)
     (plist-put plist :section-numbers t)))
  plist)

And add this to the export filter:

(add-to-list 'org-export-filter-options-functions 'my-org-export-change-options)

The function will be called by the export and depending on the backend it will enable or disable the toc/section-numbers.