Emacs org: promote all subtree headers during export?

I use emacs org to export parts of org documents to latex / pdf. I was wondering if there is a way to promote all the titles of the selected parts in the export process. For example, suppose a file looks like this:

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

Exporting emacs org to latex will create a tex file with the following structure:

\section{Project 1}
\subsection{Task 1}
\subsubsection{Introduction}
    Text text text. 
\subsubsection{Results}
    Text text text.

But since the exported part is not the highest level, it would be more appropriate to have the following structure:

\section{Task 1}
\subsection{Introduction}
    Text text text. 
\subsection{Results}
    Text text text.

Or even better:

\title{Task 1}
\maketitle
\section{Introduction}
    Text text text. 
\section{Results}
    Text text text.

I was wondering if anyone has an idea how to do this? My lisp skills are unfortunately very rudimentary, it seems like this shouldn't be too complicated.

Thank!

Stephan

+4
source share
1

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


:

+4

Source: https://habr.com/ru/post/1543922/


All Articles