在org-mode中,如何为LaTeX和HTML指定不同的导出选项?

inc*_*man 7 emacs org-mode

在组织模式中,我想为不同的导出类型指定不同的导出选项,即编号标题和导出到LaTeX/PDF的目录,没有编号,也没有用于导出到HTML的目录.

是否可以在不必每次手动编辑导出选项的情况下执行此操作?

ste*_*ter 5

ox.el(组织模式的通用导出引擎)中有一个过滤系统:

过滤器允许最终用户轻松调整转码输出.它们是钩子的功能对应物,因为集合中的每个过滤器都应用于前一个过滤器的返回值.

其中一个过滤器是: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.
Run Code Online (Sandbox Code Playgroud)

这意味着你可以定义一个类似于这个的函数:

(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)
Run Code Online (Sandbox Code Playgroud)

并将其添加到导出过滤器:

(add-to-list 'org-export-filter-options-functions 'my-org-export-change-options)
Run Code Online (Sandbox Code Playgroud)

该函数将由导出调用,并根据后端启用或禁用toc/section-numbers.