emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Matt Lundin <mdl@imapmail.org>
Cc: Chris Malone <chris.m.malone@gmail.com>,
	emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Collapse LaTeX source before start of main document?
Date: Sat, 07 Jun 2014 15:48:40 -0400	[thread overview]
Message-ID: <877g4ssdpj.fsf@gmail.com> (raw)
In-Reply-To: <87lhtadkoi.fsf@gmail.com> (Eric Schulte's message of "Fri, 06 Jun 2014 13:03:25 -0400")

Eric Schulte <schulte.eric@gmail.com> writes:

> Matt Lundin <mdl@imapmail.org> writes:
>
>> Chris Malone <chris.m.malone@gmail.com> 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)

  reply	other threads:[~2014-06-07 19:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-04 15:36 Chris Malone
2011-05-04 16:18 ` Matt Lundin
2011-05-04 18:05   ` Chris Malone
2011-05-04 22:23     ` Matt Lundin
2012-09-27  9:07       ` Renier Marchand
2012-09-27 15:33         ` Nick Dokos
2014-06-06 17:03   ` Eric Schulte
2014-06-07 19:48     ` Eric Schulte [this message]
2011-05-04 22:25 ` Suvayu Ali
2011-05-05 14:23   ` Chris Malone
2011-05-05 14:46     ` Suvayu Ali
2011-05-05 15:37       ` Chris Malone
2011-05-05 17:37         ` Suvayu Ali
2011-05-05 17:45           ` chris.m.malone
2011-05-05 18:02             ` Suvayu Ali
2011-05-06 15:41               ` Eric S Fraga
2011-05-06 17:04                 ` Suvayu Ali
2011-05-06 12:34     ` Matt Lundin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877g4ssdpj.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=chris.m.malone@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mdl@imapmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).