将评论导出为评论

6
在Org-mode中,您可以添加注释,并且从Org-mode导出到LaTeX,但是Org-mode注释不会被导出为LaTeX注释。如何使Org-mode将Org-mode注释导出为LaTeX注释?
以下是一个示例。下面的内容:
``` #+BEGIN_COMMENT This is an Org-mode comment. #+END_COMMENT ```
在LaTeX中将被导出为:
``` % This is an Org-mode comment. ```
* 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-mode的注释导出为LaTeX注释。因此,我想要以下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。


1
据我所知,这是不可能的。但我喜欢将注释作为输出格式中的注释导出的想法(那些支持文档中的注释)。 - kindahero
2个回答

5

在当前的导出器下,我能想到的唯一允许您导出评论的方法是特定于后端的。您可以使用类似以下内容的东西:

#+latex: comment

或者

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

然而,两者都是人为的,如果您想要导出到多个格式,则需要对HTML等进行相应处理。正在开发一个新出口器,但这不应该过于难以实现(解析器已将注释标识为块,因此只需要一种方法在导出时将其转换)。我将此请求转发到邮件列表,以查看是否可以包含它。
编辑:线程位于此处
编辑:Org-Mode维护者的回复:

当前的导出器不允许此操作,但Nicolas的新导出引擎使其成为可能。

计划在8.0版本之前将新的导出引擎合并到Org的核心中,请保持关注。


1
我对\n# 进行了搜索和替换,将其变为\n#+latex:% 。这将把所有在org-mode中以# 开头的行转换为emacs中以% 开头的行,从而实现了我认为N.N.任务的目标。 - CPBL
这对我不起作用。在导出的PDF中,我仍然得到了不想要的文本。 - bobsacameno
@bobsacameno 这是基于 OrgMode <8.0 版本的。由于导出引擎的更改,现在的过程会有所不同。 - Jonathan Leech-Pepin

3
除了Jonathan Leech-Pepin的答案之外,还有一种粗糙的方法可以针对给定的导出器后端进行操作。评论由org-exp.el中的org-export-handle-comments函数处理并调用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导出器如何处理注释-有关细节,请参阅org-exp.el中对org-export-handle-comments的调用和实现。基本上,:comments参数可以是格式字符串,显示如何处理注释;如果它是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参数。也许Jonathan设置的线程中有一些内容可以阐明这个问题。
请注意,为了使org-latex.el中的更改传播到导出中,您可能需要删除已编译的org-latex.elc文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接