emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Wrong numbering after removal of headline
@ 2014-06-30 19:02 York Zhao
  2014-06-30 19:37 ` Thomas S. Dye
  2014-06-30 21:38 ` Nicolas Goaziou
  0 siblings, 2 replies; 7+ messages in thread
From: York Zhao @ 2014-06-30 19:02 UTC (permalink / raw)
  To: emacs-orgmode

Hi list,

As an example, I have the follow org-mode buffer:

* Level1
** Level2
*** Level3

If I export this to LaTeX (C-x C-e l p), it produces the following:

--8<---------------cut here---------------start------------->8---

Contents

1 Level1
1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .

--8<---------------cut here---------------end--------------->8---

Which is good. However, since what I need is that I don't want to produce the
"level1" heading, so I added the following code:

(defun yz/org-export-ignore-headline (contents backend info)
  "Ignore headlines with tag `ignoreheading'."
  (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
             (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
    (replace-match "" nil nil contents)))

(add-to-list 'org-export-filter-headline-functions
             'yz/org-export-ignore-headline)

And I added tag "ignorheading" to the "Level1" heading. It works and produced:

--8<---------------cut here---------------start------------->8---

0.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
0.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .

--8<---------------cut here---------------end--------------->8---

However, the headline numbering now starts from 0 which is wrong , what I want
is:

1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .

Can anyone please tell me how I could achieve this?

Thanks in advance

York

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

* Re: Wrong numbering after removal of headline
  2014-06-30 19:02 Wrong numbering after removal of headline York Zhao
@ 2014-06-30 19:37 ` Thomas S. Dye
  2014-06-30 21:32   ` York Zhao
  2014-06-30 21:38 ` Nicolas Goaziou
  1 sibling, 1 reply; 7+ messages in thread
From: Thomas S. Dye @ 2014-06-30 19:37 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

Aloha York,

York Zhao <gtdplatform@gmail.com> writes:

> Hi list,
>
> As an example, I have the follow org-mode buffer:
>
> * Level1
> ** Level2
> *** Level3
>
> If I export this to LaTeX (C-x C-e l p), it produces the following:
>
>
> Contents
>
> 1 Level1
> 1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> 1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>
> Which is good. However, since what I need is that I don't want to produce the
> "level1" heading, so I added the following code:
>
> (defun yz/org-export-ignore-headline (contents backend info)
>   "Ignore headlines with tag `ignoreheading'."
>   (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
>              (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
>     (replace-match "" nil nil contents)))
>
> (add-to-list 'org-export-filter-headline-functions
>              'yz/org-export-ignore-headline)
>
> And I added tag "ignorheading" to the "Level1" heading. It works and produced:
>
>
> 0.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> 0.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>
> However, the headline numbering now starts from 0 which is wrong , what I want
> is:
>
> 1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> 1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>
> Can anyone please tell me how I could achieve this?

You could promote the Level2 subtree.

hth,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: Wrong numbering after removal of headline
  2014-06-30 19:37 ` Thomas S. Dye
@ 2014-06-30 21:32   ` York Zhao
  2014-06-30 21:37     ` Thomas S. Dye
  0 siblings, 1 reply; 7+ messages in thread
From: York Zhao @ 2014-06-30 21:32 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-orgmode

> You could promote the Level2 subtree.

I had thought about this, but I don't think this will be trivial.

On Mon, Jun 30, 2014 at 3:37 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
> Aloha York,
>
> York Zhao <gtdplatform@gmail.com> writes:
>
>> Hi list,
>>
>> As an example, I have the follow org-mode buffer:
>>
>> * Level1
>> ** Level2
>> *** Level3
>>
>> If I export this to LaTeX (C-x C-e l p), it produces the following:
>>
>>
>> Contents
>>
>> 1 Level1
>> 1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> 1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>
>>
>> Which is good. However, since what I need is that I don't want to produce the
>> "level1" heading, so I added the following code:
>>
>> (defun yz/org-export-ignore-headline (contents backend info)
>>   "Ignore headlines with tag `ignoreheading'."
>>   (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
>>              (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
>>     (replace-match "" nil nil contents)))
>>
>> (add-to-list 'org-export-filter-headline-functions
>>              'yz/org-export-ignore-headline)
>>
>> And I added tag "ignorheading" to the "Level1" heading. It works and produced:
>>
>>
>> 0.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> 0.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>
>>
>> However, the headline numbering now starts from 0 which is wrong , what I want
>> is:
>>
>> 1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> 1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>
>> Can anyone please tell me how I could achieve this?
>
> You could promote the Level2 subtree.
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com

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

* Re: Wrong numbering after removal of headline
  2014-06-30 21:32   ` York Zhao
@ 2014-06-30 21:37     ` Thomas S. Dye
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas S. Dye @ 2014-06-30 21:37 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

M-S-left with point on the Level2 heading?

Tom

York Zhao <gtdplatform@gmail.com> writes:

>> You could promote the Level2 subtree.
>
> I had thought about this, but I don't think this will be trivial.
>
> On Mon, Jun 30, 2014 at 3:37 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>> Aloha York,
>>
>> York Zhao <gtdplatform@gmail.com> writes:
>>
>>> Hi list,
>>>
>>> As an example, I have the follow org-mode buffer:
>>>
>>> * Level1
>>> ** Level2
>>> *** Level3
>>>
>>> If I export this to LaTeX (C-x C-e l p), it produces the following:
>>>
>>>
>>> Contents
>>>
>>> 1 Level1
>>> 1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>> 1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>>
>>>
>>> Which is good. However, since what I need is that I don't want to produce the
>>> "level1" heading, so I added the following code:
>>>
>>> (defun yz/org-export-ignore-headline (contents backend info)
>>>   "Ignore headlines with tag `ignoreheading'."
>>>   (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
>>>              (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
>>>     (replace-match "" nil nil contents)))
>>>
>>> (add-to-list 'org-export-filter-headline-functions
>>>              'yz/org-export-ignore-headline)
>>>
>>> And I added tag "ignorheading" to the "Level1" heading. It works and produced:
>>>
>>>
>>> 0.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>> 0.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>>
>>>
>>> However, the headline numbering now starts from 0 which is wrong , what I want
>>> is:
>>>
>>> 1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>> 1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>>
>>> Can anyone please tell me how I could achieve this?
>>
>> You could promote the Level2 subtree.
>>
>> hth,
>> Tom
>>
>> --
>> Thomas S. Dye
>> http://www.tsdye.com
>
>

-- 
Thomas S. Dye
http://www.tsdye.com

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

* Re: Wrong numbering after removal of headline
  2014-06-30 19:02 Wrong numbering after removal of headline York Zhao
  2014-06-30 19:37 ` Thomas S. Dye
@ 2014-06-30 21:38 ` Nicolas Goaziou
  2014-06-30 22:23   ` York Zhao
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2014-06-30 21:38 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

Hello,

York Zhao <gtdplatform@gmail.com> writes:

> As an example, I have the follow org-mode buffer:
>
> * Level1
> ** Level2
> *** Level3
>
> If I export this to LaTeX (C-x C-e l p), it produces the following:
>
>
> Contents
>
> 1 Level1
> 1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> 1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>
> Which is good. However, since what I need is that I don't want to produce the
> "level1" heading, so I added the following code:
>
> (defun yz/org-export-ignore-headline (contents backend info)
>   "Ignore headlines with tag `ignoreheading'."
>   (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
>              (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
>     (replace-match "" nil nil contents)))
>
> (add-to-list 'org-export-filter-headline-functions
>              'yz/org-export-ignore-headline)

Don't do that at the filter level, which is too late for heavy structure
editing.  Use `org-export-before-parsing-hook' instead.  See section
12.14 in manual for an example.


Regards,

-- 
Nicolas Goaziou

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

* Re: Wrong numbering after removal of headline
  2014-06-30 21:38 ` Nicolas Goaziou
@ 2014-06-30 22:23   ` York Zhao
  2014-06-30 23:01     ` York Zhao
  0 siblings, 1 reply; 7+ messages in thread
From: York Zhao @ 2014-06-30 22:23 UTC (permalink / raw)
  To: York Zhao, emacs-orgmode

Hi Nicolas,

> Don't do that at the filter level, which is too late for heavy structure
> editing. Use `org-export-before-parsing-hook' instead.

I realized this, and had changed to use `org-export-before-parsing-hook', here
is my code:

(defun my-headline-removal (backend)
  "Ignore headlines with tag `ignoreheading'."
  (save-excursion
    (when (eq org-export-current-backend 'latex)
      (org-map-entries (lambda ()
                         (when (member "ignoreheading"
(org-get-tags-at nil 'local))
                           (save-excursion
                             (org-map-tree 'org-promote))
                           (delete-region (line-beginning-position)
                                          (line-end-position))))))))

(add-hook 'org-export-before-parsing-hook 'my-headline-removal)

But I'm getting the error: "org-map-tree: Symbol's value as variable is void:
org-called-with-limited-levels". Any idea?

Thanks


On Mon, Jun 30, 2014 at 5:38 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Hello,
>
> York Zhao <gtdplatform@gmail.com> writes:
>
>> As an example, I have the follow org-mode buffer:
>>
>> * Level1
>> ** Level2
>> *** Level3
>>
>> If I export this to LaTeX (C-x C-e l p), it produces the following:
>>
>>
>> Contents
>>
>> 1 Level1
>> 1.1 Level2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>> 1.1.1 Level3 . . . . . . . . . . . . . . . . . . . . . . . . . . .
>>
>>
>> Which is good. However, since what I need is that I don't want to produce the
>> "level1" heading, so I added the following code:
>>
>> (defun yz/org-export-ignore-headline (contents backend info)
>>   "Ignore headlines with tag `ignoreheading'."
>>   (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii)
>>              (string-match "\\`.*ignoreheading.*\n" (downcase contents)))
>>     (replace-match "" nil nil contents)))
>>
>> (add-to-list 'org-export-filter-headline-functions
>>              'yz/org-export-ignore-headline)
>
> Don't do that at the filter level, which is too late for heavy structure
> editing.  Use `org-export-before-parsing-hook' instead.  See section
> 12.14 in manual for an example.
>
>
> Regards,
>
> --
> Nicolas Goaziou

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

* Re: Wrong numbering after removal of headline
  2014-06-30 22:23   ` York Zhao
@ 2014-06-30 23:01     ` York Zhao
  0 siblings, 0 replies; 7+ messages in thread
From: York Zhao @ 2014-06-30 23:01 UTC (permalink / raw)
  To: York Zhao, emacs-orgmode

Finally, I got it all work and am happy with the result, here is the code:

(defun yz/org-export-ignore-headline (backend)
  "Ignore headlines with tag `ignoreheading'."
  (save-excursion
    (let ((org-allow-promoting-top-level-subtree t))
      (org-map-entries
       (lambda ()
         (when (member "ignoreheading" (org-get-tags-at nil 'local))
           (org-promote-subtree)
           (delete-region (line-beginning-position) (line-end-position))))))))

(add-hook 'org-export-before-parsing-hook 'yz/org-export-ignore-headline)

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

end of thread, other threads:[~2014-06-30 23:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-30 19:02 Wrong numbering after removal of headline York Zhao
2014-06-30 19:37 ` Thomas S. Dye
2014-06-30 21:32   ` York Zhao
2014-06-30 21:37     ` Thomas S. Dye
2014-06-30 21:38 ` Nicolas Goaziou
2014-06-30 22:23   ` York Zhao
2014-06-30 23:01     ` York Zhao

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