From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Ignoring empty subtrees/new exporter Date: Sun, 06 Jan 2013 11:24:59 +0100 Message-ID: <877gnq622s.fsf@gmail.com> References: <50E880A8.4080003@miszellen.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:43204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrnTT-0003wr-By for emacs-orgmode@gnu.org; Sun, 06 Jan 2013 05:29:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrnTR-0004MB-Vj for emacs-orgmode@gnu.org; Sun, 06 Jan 2013 05:29:03 -0500 Received: from mail-wg0-f51.google.com ([74.125.82.51]:33392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrnTR-0004M4-OK for emacs-orgmode@gnu.org; Sun, 06 Jan 2013 05:29:01 -0500 Received: by mail-wg0-f51.google.com with SMTP id gg4so8508340wgb.18 for ; Sun, 06 Jan 2013 02:29:00 -0800 (PST) In-Reply-To: <50E880A8.4080003@miszellen.de> (Florian Beck's message of "Sat, 05 Jan 2013 20:36:08 +0100") 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: Florian Beck Cc: emacs-orgmode Hello, Florian Beck writes: > I have a document with many sections not yet written (i.e. heading > without content) and I would like them to be ignored in the exported > file. I know, I could manually tag these headings with :noexport:, but > what about a more automated approach? > > Now, I tried this: > > > (defun ignore-empty-section (headline contents info) > (when contents > (org-e-latex-headline headline contents info))) > > > (add-to-list 'org-e-latex-translate-alist > '(headline . ignore-empty-section)) The global idea is correct, but I find that the implementation is too low level. It also taints original e-latex back-end. I suggest the following instead: #+begin_src emacs-lisp (defun ignore-empty-section (headline contents info) (when (org-string-nw-p contents) (org-export-with-backend 'e-latex headline contents info))) (org-export-define-derived-backend my-draft-latex e-latex :translate-alist ((headline . ignore-empty-section)) ;; Optionally add a sub-menu entry in the latex menu. :menu-entry (?l 99 ((?d "As a draft PDF file" my-draft-latex)))) (defun my-draft-latex (&optional async subtreep visible-only body-only ext-plist) (interactive) (let ((outfile (org-export-output-file-name ".tex" subtreep))) (if async (org-export-async-start (lambda (f) (org-export-add-to-stack f 'e-latex)) `(expand-file-name (org-e-latex-compile (org-export-to-file 'my-draft-latex ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))) (org-e-latex-compile (org-export-to-file 'my-draft-latex outfile subtreep visible-only body-only ext-plist))))) #+end_src Note that if you don't want the hassle of creating a derived back-end, you can also implement a function that will remove every section containing only sections or nothing from the buffer, and add it to `org-export-before-processing-hook' (or `org-export-before-parsing-hook'). Regards, -- Nicolas Goaziou