emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Ignoring empty subtrees/new exporter
@ 2013-01-05 19:36 Florian Beck
  2013-01-06  6:31 ` Jambunathan K
  2013-01-06 10:24 ` Nicolas Goaziou
  0 siblings, 2 replies; 5+ messages in thread
From: Florian Beck @ 2013-01-05 19:36 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

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))

This does ALMOST what I want: it ignores sections that are completely 
empty. But I also want to ignore sections that have only empty 
subsections (and so on, recursively). For example:

* Chapter
** this subtree should be ignored
*** no content
*** no content
** this subtree should not be ignored
*** subsection
**** finally, content
something weird
*** subsection

Any ideas? I tried parsing the HEADLINE stuff (the first argument), but 
it looks a bit intimidating.

It's not super important, because it's a draft obviously, but it would 
be nice.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ignoring empty subtrees/new exporter
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Jambunathan K @ 2013-01-06  6:31 UTC (permalink / raw)
  To: Florian Beck; +Cc: emacs-orgmode

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.

Sometimes I create documents - not drafts, but final deliverables - with
empty sections and plain headlines.  This way I get emboldened text that
stands out without resorting to emphasis.

You are probably writing a Thesis.  Oftentimes, I create documents that
aren't as formal as Thesis.  They are plain one-to-one-s which need to
look good, that is all.
-- 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ignoring empty subtrees/new exporter
  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
  2013-01-06 21:54   ` Florian Beck
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2013-01-06 10:24 UTC (permalink / raw)
  To: Florian Beck; +Cc: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ignoring empty subtrees/new exporter
  2013-01-06 10:24 ` Nicolas Goaziou
@ 2013-01-06 21:54   ` Florian Beck
  2013-01-07 19:46     ` Florian Beck
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Beck @ 2013-01-06 21:54 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

On 01/06/2013 11:24 AM, Nicolas Goaziou wrote:

> 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:

Thanks a lot!  A derived backend seems like a good idea. Unfortunatly, 
the function org-export-with-backend isn't in the latest 
org-plus-contrib package (20121231). I'll try it then.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Ignoring empty subtrees/new exporter
  2013-01-06 21:54   ` Florian Beck
@ 2013-01-07 19:46     ` Florian Beck
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Beck @ 2013-01-07 19:46 UTC (permalink / raw)
  Cc: emacs-orgmode, Nicolas Goaziou

On 01/06/2013 10:54 PM, Florian Beck wrote:
> On 01/06/2013 11:24 AM, Nicolas Goaziou wrote:
>
>> 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:
>
> Thanks a lot!  A derived backend seems like a good idea. Unfortunatly,
> the function org-export-with-backend isn't in the latest
> org-plus-contrib package (20121231). I'll try it then.

Well, I've switched to the git version. The version in 
"org-plus-contrib" is a very one from the maint-branch, which kind of 
defeats the purpose of the package, doesn't it? Anyway, your suggestion 
now works perfectly, thanks again.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-07 19:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2013-01-06 21:54   ` Florian Beck
2013-01-07 19:46     ` Florian Beck

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).