gpt4 book ai didi

Emacs 组织 : Promote all headings of a subtree during export?

转载 作者:行者123 更新时间:2023-12-01 01:00:15 25 4
gpt4 key购买 nike

我经常使用 emacs org 将部分 org 文档导出到 latex/pdf。我想知道是否有一种方法可以在导出过程中提升所选部分的所有标题。例如,假设文件如下所示:

* Project 1
** Task 1 :export:
*** Introduction
Text text text.
*** Results
Text text text.
* Project 2

emacs org 导出到 latex 将生成以下结构的 tex 文件:
\section{Project 1}
\subsection{Task 1}
\subsubsection{Introduction}
Text text text.
\subsubsection{Results}
Text text text.

但是由于要导出的部分没有最高级别,因此具有以下结构会更有意义:
\section{Task 1}
\subsection{Introduction}
Text text text.
\subsection{Results}
Text text text.

或者,甚至更好:
\title{Task 1}
\maketitle
\section{Introduction}
Text text text.
\section{Results}
Text text text.

我想知道是否有人知道如何解决这个问题?不幸的是,我的 lisp 技能非常初级,看起来应该不会太难。

谢谢!

斯蒂芬

最佳答案

您描述的第一个行为可以通过将以下内容添加到您的 .emacs 来实现:

;; Define a function for turning a single subtree into a top-level tree
;; (:export: headings might be located at an arbitrary nesting level,
;; so a single call to "org-promote-subtree" is not enough):
(defun org-promote-to-top-level ()
"Promote a single subtree to top-level."
(let ((cur-level (org-current-level)))
(loop repeat (/ (- cur-level 1) (org-level-increment))
do (org-promote-subtree))))

;; Define a function that applies "org-promote-to-top-level"
;; to each :export: subtree:
(defun org-export-trees-to-top-level (backend)
"Promote all subtrees tagged :export: to top-level.
BACKEND is the export back-end being used, as a symbol."
(org-map-entries 'org-promote-to-top-level "+export"))

;; Make org-mode run "org-export-subtrees-to-top-level" as part of the export
;; process:
(add-hook 'org-export-before-parsing-hook 'org-export-trees-to-top-level)

实现第二个行为有点棘手,但您可以使用 org-export-trees-to-top-level如果这是您最终需要的功能,则将其作为起点。但是,我想指出的是,这不适用于具有多个 :export: 的文件。子树(除非您还想出一种方法来决定在这些情况下哪个标题将成为 \title)。

资料来源:
  • org-promote-to-top-level的逻辑基于 org-cycle-level 的源代码命令
  • Using the org-mode mapping API
  • Relevant information about export hooks
  • 关于Emacs 组织 : Promote all headings of a subtree during export?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24130487/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com