From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Generate a table of contents without exporting Date: Tue, 01 Apr 2014 17:52:47 -0400 Message-ID: <87ppl0sonk.fsf@alphaville.bos.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV6cN-00024a-KM for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 17:53:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WV6cF-0003UP-KE for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 17:53:15 -0400 Received: from plane.gmane.org ([80.91.229.3]:57200) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV6cF-0003U8-Dx for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 17:53:07 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WV6c9-0004l1-F3 for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 23:53:01 +0200 Received: from nat-pool-bos-t.redhat.com ([66.187.233.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Apr 2014 23:53:01 +0200 Received: from ndokos by nat-pool-bos-t.redhat.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Apr 2014 23:53:01 +0200 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: emacs-orgmode@gnu.org Charles Berry writes: > RG Williams gmail.com> writes: > >> >> Hi, >> I know you can generate a table of contents when exporting, but can you do >> it just within org? For context, I'm uploading an .org file to github and I >> don't need to export it to another format because github recognizes and >> displays it just fine. It's long so a ToC would be nice. Do I just have to >> write it myself? >> >> > > AFAIK, you do have to write it yourself, but org-mode provides decent tools > for doing it. Here is an example. Run the src-block and a table of contents > will appear near the top. Change the content and rerun the src-block and > the t-o-c will change accordingly. > > It doesn't deal with rules for omitting headlines like > COMMENT, :noexport:, etc, but if you are simply copying the .org file, > maybe it is good enough. > > > #+RESULTS: Table_of_Contents > > * h > lower H > * i > lower I > * j > lower J > ** 1 > one > ** 2 > two > > #+NAME: Table_of_Contents > #+BEGIN_SRC emacs-lisp :wrap example > (mapconcat 'identity > (org-element-map > (org-element-parse-buffer 'headline) 'headline > (lambda (hl) (let > ((lev > (org-element-property :level hl)) > (htitle (org-element-property :title hl))) > (concat (make-string lev ? ) "- " htitle )))) "\n") > #+END_SRC > > Another more manual way: export to text and cut-and-paste the TOC into a noexport top-level section. Nick