【问题标题】:in org-mode, how to specify different export options for LaTeX and HTML?在 org 模式下,如何为 LaTeX 和 HTML 指定不同的导出选项?
【发布时间】:2014-01-03 23:16:24
【问题描述】:

在 org-mode 中,我想为不同的导出类型指定不同的导出选项,即用于导出到 LaTeX/PDF 的编号标题和目录,没有编号和导出到 HTML 的目录。

是否可以这样做而不必每次都手动编辑导出选项?

【问题讨论】:

    标签: emacs org-mode


    【解决方案1】:

    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.
    

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

    (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)
    

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

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

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

    【讨论】:

    • 我认为我没有完全理解。我将以上内容添加到我的 .emacs 中,我得到了 Lisp error: (void-function pcase) (pcase backend (`html (plist-put plist :with-toc nil) (plist-put plist :section-numbers nil)) (`latex (plist-put plist :with-toc t) (plist-put plist :section-numbers t))) my-org-export-change-options((:export-options nil :input-file
    • pcase 功能已添加到Emacs 24.1。我更新了答案,这样它就可以在没有pcase 的情况下工作。另请注意,我的答案已使用 Org-mode 版本 8.2.4 进行了测试(请查看 M-x org-version)。 Org-mode 将导出系统更改为 8.0 版本。如果您的 Org-mode
    猜你喜欢
    • 2012-02-09
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多