From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Collapse LaTeX source before start of main document? Date: Fri, 06 Jun 2014 13:03:25 -0400 Message-ID: <87lhtadkoi.fsf@gmail.com> References: <878vumsam8.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsxjl-0001Tl-TG for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:15:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wsxjh-0002ue-7P for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:15:29 -0400 Received: from mail-qa0-x231.google.com ([2607:f8b0:400d:c00::231]:35658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsxjh-0002ua-39 for emacs-orgmode@gnu.org; Fri, 06 Jun 2014 13:15:25 -0400 Received: by mail-qa0-f49.google.com with SMTP id cm18so4234332qab.8 for ; Fri, 06 Jun 2014 10:15:24 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Chris Malone , emacs-orgmode Matt Lundin writes: > Chris Malone 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--- In addition it promotes all headlines under the removed "prelim"-tagged headline. This is useful to support structures like the following. --8<---------------cut here---------------start------------->8--- * Appendix :prelim: #+LaTeX: \begin{appendices} ** Definitions ** Data Sets ** Tooling #+LaTeX: \end{appendices} --8<---------------cut here---------------end--------------->8--- Best, -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D (see https://u.fsf.org/yw)