【问题标题】:Export comments as comments将评论导出为评论
【发布时间】:2012-03-26 13:49:18
【问题描述】:

在 Org-mode 你可以制作 cmets,从 Org-mode 你可以导出到 LaTeX 但 Org-mode cmets 不会导出到 LaTeX cmets。如何让 Org-mode 将 Org-mode cmets 导出为 LaTeX cmets?

这是一个例子。以下

* Test

Text before comment
# Comment
Text after comment

Text before comment
#+BEGIN_COMMENT
Comment
#+END_COMMENT
Text after comment

出口到

\section{Test}
\label{sec-1}


Text before comment
Text after comment

Text before comment

Text after comment

但我希望将 Org 模式 cmets 导出为 LaTeX cmets。因此,我想要以下 LaTeX 输出:

\section{Test}
\label{sec-1}


Text before comment
% Comment
Text after comment

Text before comment
\begin{comment}
Comment
\end{comment}
Text after comment

我在 Emacs 23.3.1 中运行 Org-mode 7.6。

【问题讨论】:

  • AFAIK 这是不可能的。但我喜欢将 cmets 导出为输出格式的 cmets 的想法(文档中支持 cmets)

标签: emacs latex comments org-mode


【解决方案1】:

在当前的导出器下,我能想到的唯一可以让您导出 cmets 的方法是特定于后端的。您可以使用以下内容:

#+latex: comment

#+begin_latex
\begin{comment}
  comment
\end{comment}
#+end_latex

但是,两者都是人为设计的,如果您打算导出为多种格式,则需要对 HTML 等进行等效操作。

有一个 new exporter 正在开发中,但是这应该不太难实现(cmets 已经在解析器中被识别为块,所以它只需要一个方法来在导出时转换它们)。

我正在将此请求转发到邮件列表,看看是否可以将其包含在内。
编辑:线程位于here

编辑:来自 Org-Mode 维护者的回应

目前的出口商不允许这样做,但新的出口引擎 Nicolas 使之成为可能。

计划是在之前将新的导出引擎合并到 Org 的核心中 8.0版本,敬请期待。

【讨论】:

  • 我在\n# 上进行了搜索并替换为\n#+latex:% 。这会将 org-mode 中以 # 开头的所有行转换为 emacs 中以 % 开头的行,这完成了我认为 N.N. 的任务。
  • 这对我不起作用。在导出的 pdf 中,我仍然得到不需要的文本。
  • @bobsacameno 这是基于 OrgMode
【解决方案2】:

除了 Jonathan Leech-Pepin 的回答之外,对于给定的导出器后端,还有一种骇人听闻的方法。注释在 org-export-handle-comments 函数中处理,该函数由 org-exp.el 中的 org-export-preprocess-string 调用。每个导出器后端都不同,但让我们考虑一下 LaTeX 后端。

如果您查看 org-latex.el 中的 org-export-as-latex 函数,您可以找到对 org-export-preprocess-string 的调用。传递给org-export-preprocess-string 函数的东西之一是参数列表,特别是它包含一个:comments 参数,在LaTeX 的情况下它被设置为nil。此参数告诉 org-mode 导出器如何处理 cmets - 有关详细信息,请查看 org-exp.el 中对 org-export-handle-comments 的调用和实现。本质上,:comments 参数可以是显示如何处理 cmets 的格式字符串;如果是nil,这意味着没有格式处理,所以什么都不会打印。如果在org-export-as-latex 函数中,将:comments nil 替换为:comments "%% %s",那么这将在导出时的任何注释文本前面插入一个“%”。所以在你的情况下

this is text before a comment
# this is a comment
this is text after a comment

将导出为

this is text before a comment
% this is a comment
this is text after a comment

这不是最方便的处理方式,而且我不确定是否可以按文件指定 :comments 参数。也许乔纳森设置的线程中的某些内容会阐明这个主题。

请注意,您可能需要删除字节编译的 org-latex.elc 文件才能看到您在 org-latex.el 中的更改传播到导出。

【讨论】:

    猜你喜欢
    • 2013-12-31
    • 1970-01-01
    • 2011-04-15
    • 2013-07-10
    • 2011-12-18
    • 1970-01-01
    • 2023-03-12
    • 2021-09-09
    • 1970-01-01
    相关资源
    最近更新 更多