简体   繁体   中英

in org-mode, how to specify different export options for LaTeX and HTML?

In org-mode, I'd like to specify different export options for different export types, ie 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM