[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Collapse LaTeX source before start of main document?
From: |
Eric Schulte |
Subject: |
Re: [O] Collapse LaTeX source before start of main document? |
Date: |
Sat, 07 Jun 2014 15:48:40 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
Eric Schulte <address@hidden> writes:
> Matt Lundin <address@hidden> writes:
>
>> Chris Malone <address@hidden> writes:
>>
>> (Note: When using gmail, please adjust the settings to send your
>> messages as plain text only instead of multipart/alternative.)
>>
>>> When I include the actual contents of my abstract, this preliminary material
>>> section (the #+begin ... #+end block) is rather large. I'd like to be able
>>> to put this material into a headline so that I could collapse it - but I
>>> don't want this headline exported as content of the main document.
>>>
>>> In other words, is there a property or tag that I can add to a headline that
>>> causes LaTeX export to ignore the fact that it is a headline (i.e. \chapter,
>>> \section, \subsection, etc.), but still export its contents? Something
>>> like:
>>
>> You could add a hook to remove headlines with a "prelim" tag:
>>
>> --8<---------------cut here---------------start------------->8---
>> (defun my-org-export-remove-tagged-headlines (tag)
>> (save-excursion
>> (goto-char (point-min))
>> (while (re-search-forward (concat ":" tag ":") nil t)
>> (delete-region (point-at-bol) (point-at-eol)))))
>>
>> (add-hook 'org-export-preprocess-hook (lambda ()
>> (my-org-export-remove-tagged-headlines "prelim")))
>> --8<---------------cut here---------------end--------------->8---
>>
>
> I found the very useful but sadly outdated snippet from 2011. If anyone
> is interested, the following snippet implements the same functionality
> within the new export framework.
>
> --8<---------------cut here---------------start------------->8---
> (defun org-export-remove-prelim-headlines (tree backend info)
> "Remove headlines tagged \"prelim\" while retaining their
> contents before any export processing."
> (org-element-map tree org-element-all-elements
> (lambda (object)
> (when (and (equal 'headline (org-element-type object))
> (member "prelim" (org-element-property :tags object)))
> (mapc (lambda (el)
> (let ((new-object
> (if (equal 'headline (org-element-type el))
> (org-element-put-property el
> :level (1- (org-element-property :level el)))
> el)))
> (message "%s level %s"
> (org-element-property :raw-value new-object)
> (org-element-property :level new-object))
> (org-element-insert-before new-object object)))
> (cddr object))
> (org-element-extract-element object)))
> info nil org-element-all-elements)
> tree)
>
> (add-hook 'org-export-filter-parse-tree-functions
> 'org-export-remove-prelim-headlines)
> --8<---------------cut here---------------end--------------->8---
>
The following is a slightly improved implementation of the above.
--8<---------------cut here---------------start------------->8---
(defun org-export-remove-prelim-headlines (tree backend info)
"Remove headlines tagged \"prelim\" while retaining their
contents before any export processing."
(org-element-map tree org-element-all-elements
(lambda (object)
(when (and (equal 'headline (org-element-type object))
(member "prelim" (org-element-property :tags object)))
(mapc (lambda (el)
;; recursively promote all nested headlines
(org-element-map el 'headline
(lambda (el)
(when (equal 'headline (org-element-type el))
(org-element-put-property el
:level (1- (org-element-property :level el))))))
(org-element-insert-before el object))
(cddr object))
(org-element-extract-element object)))
info nil org-element-all-elements)
tree)
--8<---------------cut here---------------end--------------->8---
Best,
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D (see https://u.fsf.org/yw)