Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

org-mode

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?

like image 699
incandescentman Avatar asked Jan 03 '14 23:01

incandescentman


People also ask

How do I export org mode?

To export your org file to a web page, type C-c C-e to start the exporter and then press h to select html and o to select open. A new web page should now open in your browser. Similarly, typing l and o in the exporter will convert the org file to latex and then compile it to produce a pdf and display that.

How do I use org Mode in Emacs?

To save the document, either press the save icon, or press C-x C-s, call it 1.org. Emacs does not actually understand you are editing an Org document, yet. To enable Org mode on your current document, type M-x org-mode which will enable the Org mode on the current document. Those are minuses, not underscores.


1 Answers

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.

like image 88
steckerhalter Avatar answered Oct 05 '22 00:10

steckerhalter