From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Export each top level heading to separate file Date: Sun, 5 Jan 2014 16:56:46 -0500 Message-ID: References: <52C88F11.4050601@verizon.net> <52C89C41.70506@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b33cb7e2f08ff04ef40384d Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vzvgj-0005hC-B3 for emacs-orgmode@gnu.org; Sun, 05 Jan 2014 16:56:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vzvge-0003RT-HM for emacs-orgmode@gnu.org; Sun, 05 Jan 2014 16:56:53 -0500 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]:45869) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vzvgd-0003RO-Vq for emacs-orgmode@gnu.org; Sun, 05 Jan 2014 16:56:48 -0500 Received: by mail-pd0-f174.google.com with SMTP id x10so17473835pdj.33 for ; Sun, 05 Jan 2014 13:56:46 -0800 (PST) In-Reply-To: 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: Ista Zahn Cc: emacs-orgmode Mailinglist , Alan L Tyree --047d7b33cb7e2f08ff04ef40384d Content-Type: text/plain; charset=ISO-8859-1 hmm.. I don't know if it was a bug, I ran the code on my system before sending it, and it worked for me ;) I am glad you figured it out on your system. you could avoid the double if statements like this: (defun my-exp-headings-to-markdown () "Export each top-level heading to markdown." (interactive) (org-map-entries (lambda () (let ((level (nth 1 (org-heading-components))) (title (nth 4 (org-heading-components)))) (when (= level 1) (org-entry-put (point) "EXPORT_FILE_NAME" title) (org-md-export-to-markdown nil 1 nil))))) nil nil)) The when macro is like an if macro, with no else body. John ----------------------------------- John Kitchin Associate Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu On Sun, Jan 5, 2014 at 2:49 PM, Ista Zahn wrote: > On Sun, Jan 5, 2014 at 8:40 AM, John Kitchin > wrote: > > Try this: > > > > > > (org-map-entries > > (lambda () > > (let ((level (nth 1 (org-heading-components))) > > (title (nth 4 (org-heading-components)))) > > (if (= level 1) > > (org-entry-put (point) ":EXPORT_FILE_NAME:" > title)))) > > nil nil) > > > > It seems to do what you want. > > Dear John, > > Thank you thank you! Using your code as I template I managed to write > a function that does what I wanted: > > (defun my-exp-headings-to-markdown () > "Export each top-level heading to markdown." > (interactive) > (org-map-entries > (lambda () > (let ((level (nth 1 (org-heading-components))) > (title (nth 4 (org-heading-components)))) > (if (= level 1) > (org-entry-put (point) "EXPORT_FILE_NAME" title)) > (if (= level 1) > (org-md-export-to-markdown nil 1 nil)))) > nil nil)) > > Note that I had to remove the ":" from the second argument to > "org-entry-put" to get it working properly on my system. Not sure if > that was a bug in your original example or not. > > Best, > Ista > > > > > John > > > > ----------------------------------- > > John Kitchin > > Associate Professor > > Doherty Hall A207F > > Department of Chemical Engineering > > Carnegie Mellon University > > Pittsburgh, PA 15213 > > 412-268-7803 > > http://kitchingroup.cheme.cmu.edu > > > > > > > > On Sat, Jan 4, 2014 at 7:36 PM, Ista Zahn wrote: > >> > >> On Sat, Jan 4, 2014 at 6:41 PM, Alan L Tyree > wrote: > >> > On 05/01/14 09:45, Charles Millar wrote: > >> >> > >> >> Ista and all, > >> >> > >> >> On 1/4/2014 5:29 PM, Ista Zahn wrote: > >> >>> > >> >>> Hi all, > >> >>> > >> >>> I'm looking for a way to export each top-level heading to a separate > >> >>> markdown file. Ideally I would like to have the exported files named > >> >>> according to the heading. For example I would like this org file > >> >>> > >> >>> ----------------------------------- > >> >>> * Section one > >> >>> Section one text > >> >>> * Section two > >> >>> ** Section two a > >> >>> Section two text > >> >>> * Section three > >> >>> Section three text > >> >>> ----------------------------------- > >> >>> > >> >>> To generate three files: > >> >>> > >> >>> --- Section one.md --- > >> >>> Section one text > >> >>> > >> >>> ----------------------------------- > >> >>> > >> >>> --- Section two.md--- > >> >>> ## Section two a > >> >>> > >> >>> Section two text > >> >>> > >> >>> ----------------------------------- > >> >>> > >> >>> --- Section three.md - > >> >>> # Section three > >> >>> > >> >>> Section three text > >> >>> > >> >>> ----------------------------------- > >> >>> > >> >>> I suspect that the publishing framework might support this, but I've > >> >>> thus far avoided it because it looks pretty complicated to set up. > >> >>> Before I dive in I'd like to know if the publishing framework is the > >> >>> correct place to look for this functionality or if there is an > easier > >> >>> way to do it. > >> >>> > >> >>> > >> >> > >> >> I have a similar question regarding LaTeX export. How to export a > >> >> heading > >> >> (any heading, regardless of level) within a file to heading.tex > instead > >> >> of > >> >> file.tex? So far the only solution I have cobbled together is to C-x > >> >> C-f > >> >> 'file.tex" and then C-x C-w "heading.tex" . I then typeset > heading.tex > >> >> using TeXworks. Perhaps I should note that my exported heading is > >> >> tagged so > >> >> that the heading is ignored. > >> >> > >> >> Charlie Millar > >> >> > >> >> --- > >> >> This email is free from viruses and malware because avast! Antivirus > >> >> protection is active. > >> >> http://www.avast.com > >> >> > >> >> > >> >> > >> > Use properties to set the export file name -- example: > >> > :PROPERTIES: > >> > :EXPORT_TITLE: Internet banking fraud > >> > :EXPORT_FILE_NAME: internet-fraud > >> > :EXPORT_AUTHOR: Alan L Tyree > >> > :Citation: (2011) 22 JBFLP 214 > >> > :EXPORT_OPTIONS: num:nil toc:nil > >> > :END: > >> > >> Thanks, gets me half the way there. Setting properties as you > >> described and exporting each sub-tree works properly. Now how can I do > >> this for all the top-level headings in a file? > >> > >> Best, > >> Ista > >> > >> > > >> > If I understood your question properly. > >> > > >> > Cheers, > >> > Alan > >> > > >> > > >> > > >> > -- > >> > Alan L Tyree http://www2.austlii.edu.au/~alan > >> > Tel: 04 2748 6206 sip:typhoon@iptel.org > >> > > >> > > >> > > > --047d7b33cb7e2f08ff04ef40384d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
hmm.. I don't know if it was a bug, I ran th= e code on my system before sending it, and it worked for me ;) I am glad yo= u figured it out on your system.

you could avoid the double if= statements like this:

(defun my-exp-headings-to-markdown ()
=A0 "Export each top-leve= l heading to markdown."
=A0 (interactive)
=A0 (org-map-entries=A0=A0 (lambda ()
=A0=A0=A0=A0 (let ((level (nth 1 (org-heading-compon= ents)))
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 (title (nth 4 (org-heading-compon= ents))))
=A0=A0=A0=A0=A0=A0 (when (=3D level 1)
=A0=A0=A0=A0=A0=A0=A0=A0 (org-en= try-put (point) "EXPORT_FILE_NAME" title)
=A0=A0=A0=A0=A0=A0= =A0=A0 (org-md-export-to-markdown nil 1 nil)))))
=A0=A0 nil nil))

The when macro is like an if macro, with no else body.

John

-------= ----------------------------
John Kitchin
Associate Professor
Dohe= rty Hall A207F
Department of Chemical Engineering
Carnegie Mellon Uni= versity
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

<= /div>

On Sun, Jan 5, 2014 at 2:49 PM, Ista Zah= n <istazahn@gmail.com> wrote:
On Sun, Jan 5, 2014 at 8:40 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:<= br> > Try this:
>
>
> (org-map-entries
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda ()
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(let ((level (nth 1 (org-heading-compon= ents)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(title (nth 4 (org-heading-= components))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if (=3D level 1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-entry-put (point) &quo= t;:EXPORT_FILE_NAME:" title))))
> =A0nil nil)
>
> It seems to do what you want.

Dear John,

Thank you thank you! Using your code as I template I managed to write
a function that does what I wanted:

(defun my-exp-headings-to-markdown ()
=A0 "Export each top-level heading to markdown."
=A0 (interactive)
=A0 (org-map-entries
=A0 =A0(lambda ()
=A0 =A0 =A0(let ((level (nth 1 (org-heading-components)))
=A0 (title (nth 4 (org-heading-components))))
=A0 =A0 =A0 =A0(if (=3D level 1)
=A0 (org-entry-put (point) "EXPORT_FILE_NAME" title))
=A0 =A0 =A0 =A0(if (=3D level 1)
=A0 (org-md-export-to-markdown nil 1 nil))))
=A0 =A0nil nil))

Note that I had to remove the ":" from the second argument to
"org-entry-put" to get it working properly on my system. Not sure= if
that was a bug in your original example or not.

Best,
Ista

>
> John
>
> -----------------------------------
> John Kitchin
> Associate Professor
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803 > http:/= /kitchingroup.cheme.cmu.edu
>
>
>
> On Sat, Jan 4, 2014 at 7:36 PM, Ista Zahn <istazahn@gmail.com> wrote:
>>
>> On Sat, Jan 4, 2014 at 6:41 PM, Alan L Tyree <alantyree@gmail.com> wrote:
>> > On 05/01/14 09:45, Charles Millar wrote:
>> >>
>> >> Ista and all,
>> >>
>> >> On 1/4/2014 5:29 PM, Ista Zahn wrote:
>> >>>
>> >>> Hi all,
>> >>>
>> >>> I'm looking for a way to export each top-level he= ading to a separate
>> >>> markdown file. Ideally I would like to have the expor= ted files named
>> >>> according to the heading. For example I would like th= is org file
>> >>>
>> >>> -----------------------------------
>> >>> * Section one
>> >>> Section one text
>> >>> * Section two
>> >>> ** Section two a
>> >>> Section two text
>> >>> * Section three
>> >>> Section three text
>> >>> -----------------------------------
>> >>>
>> >>> To generate three files:
>> >>>
>> >>> --- Section one.md ---
>> >>> Section one text
>> >>>
>> >>> -----------------------------------
>> >>>
>> >>> --- Section two.md---
>> >>> ## Section two a
>> >>>
>> >>> Section two text
>> >>>
>> >>> -----------------------------------
>> >>>
>> >>> --- Section three.md -
>> >>> # Section three
>> >>>
>> >>> Section three text
>> >>>
>> >>> -----------------------------------
>> >>>
>> >>> I suspect that the publishing framework might support= this, but I've
>> >>> thus far avoided it because it looks pretty complicat= ed to set up.
>> >>> Before I dive in I'd like to know if the publishi= ng framework is the
>> >>> correct place to look for this functionality or if th= ere is an easier
>> >>> way to do it.
>> >>>
>> >>>
>> >>
>> >> I have a similar question regarding LaTeX export. How to = export a
>> >> heading
>> >> (any heading, regardless of level) within a file to headi= ng.tex instead
>> >> of
>> >> file.tex? So far the only solution I have cobbled togethe= r is to C-x
>> >> C-f
>> >> 'file.tex" and then C-x C-w "heading.tex&qu= ot; . =A0I then typeset heading.tex
>> >> using TeXworks. Perhaps I should note that my exported he= ading is
>> >> tagged so
>> >> that the heading is ignored.
>> >>
>> >> Charlie Millar
>> >>
>> >> ---
>> >> This email is free from viruses and malware because avast= ! Antivirus
>> >> protection is active.
>> >> http:/= /www.avast.com
>> >>
>> >>
>> >>
>> > Use properties to set the export file name -- example:
>> > =A0 :PROPERTIES:
>> > =A0 :EXPORT_TITLE: Internet banking fraud
>> > =A0 :EXPORT_FILE_NAME: internet-fraud
>> > =A0 :EXPORT_AUTHOR: Alan L Tyree
>> > =A0 :Citation: (2011) 22 JBFLP 214
>> > =A0 :EXPORT_OPTIONS: num:nil toc:nil
>> > =A0 :END:
>>
>> Thanks, gets me half the way there. Setting properties as you
>> described and exporting each sub-tree works properly. Now how can = I do
>> this for all the top-level headings in a file?
>>
>> Best,
>> Ista
>>
>> >
>> > If I understood your question properly.
>> >
>> > Cheers,
>> > Alan
>> >
>> >
>> >
>> > --
>> > Alan L Tyree =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0http://www2.austlii= .edu.au/~alan
>> > Tel: =A004 2748 6206 =A0 =A0 =A0 =A0 =A0 =A0 =A0sip:typhoon@iptel.org
>> >
>> >
>>
>

--047d7b33cb7e2f08ff04ef40384d--