emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Florian Beck <fb@miszellen.de>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Ignoring empty subtrees/new exporter
Date: Sun, 06 Jan 2013 11:24:59 +0100	[thread overview]
Message-ID: <877gnq622s.fsf@gmail.com> (raw)
In-Reply-To: <50E880A8.4080003@miszellen.de> (Florian Beck's message of "Sat, 05 Jan 2013 20:36:08 +0100")

Hello,

Florian Beck <fb@miszellen.de> 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

  parent reply	other threads:[~2013-01-06 10:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-05 19:36 Ignoring empty subtrees/new exporter Florian Beck
2013-01-06  6:31 ` Jambunathan K
2013-01-06 10:24 ` Nicolas Goaziou [this message]
2013-01-06 21:54   ` Florian Beck
2013-01-07 19:46     ` Florian Beck

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=877gnq622s.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=fb@miszellen.de \
    /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).