* Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
@ 2017-02-08 19:52 Joon Ro
2017-02-08 19:53 ` Joon Ro
2017-02-08 20:48 ` Thomas S. Dye
0 siblings, 2 replies; 8+ messages in thread
From: Joon Ro @ 2017-02-08 19:52 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 642 bytes --]
Hi,
In latex export, sometimes I want to make sure a section starts in a new page.
It seems I should be able to add a hook to org-export-before-parsing-hook, so if it sees a section with :newpage: tag (for example), it adds #+LATEX: \newpage before the section header so I would get
\newpage
\section{Section Name}
in the exported file.
I have a couple of hooks already so in general I'm using the following code:
(org-map-entries
(lambda ()
(progn
))
"+newpage")
but I'm not sure how to add #+LATEX: \newpage before the section header - .
Best Regards,
Joon
[-- Attachment #2: Type: text/html, Size: 1918 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-08 19:52 Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook Joon Ro
@ 2017-02-08 19:53 ` Joon Ro
2017-02-08 20:48 ` Thomas S. Dye
1 sibling, 0 replies; 8+ messages in thread
From: Joon Ro @ 2017-02-08 19:53 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1624 bytes --]
Hi,
(I'm sorry for a duplicated email - it was sent my a mistake)
In latex export, sometimes I want to make sure a section starts in a new page.
It seems I should be able to add a hook to org-export-before-parsing-hook, so if it sees a section with :newpage: tag (for example), it adds #+LATEX: \newpage before the section header so I would get
\newpage
\section{Section Name}
in the exported file.
I have a couple of hooks already so in general I'm using the following code:
(org-map-entries
(lambda ()
(progn
))
"+newpage")
but I'm not sure how to add #+LATEX: \newpage before the section header - any help would be greatly appreciated.
Best,
Joon
________________________________
From: Joon Ro <joon.ro@outlook.com>
Sent: Wednesday, February 8, 2017 1:52:42 PM
To: emacs-orgmode@gnu.org
Subject: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
Hi,
In latex export, sometimes I want to make sure a section starts in a new page.
It seems I should be able to add a hook to org-export-before-parsing-hook, so if it sees a section with :newpage: tag (for example), it adds #+LATEX: \newpage before the section header so I would get
\newpage
\section{Section Name}
in the exported file.
I have a couple of hooks already so in general I'm using the following code:
(org-map-entries
(lambda ()
(progn
))
"+newpage")
but I'm not sure how to add #+LATEX: \newpage before the section header - .
Best Regards,
Joon
[-- Attachment #2: Type: text/html, Size: 5736 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-08 19:52 Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook Joon Ro
2017-02-08 19:53 ` Joon Ro
@ 2017-02-08 20:48 ` Thomas S. Dye
2017-02-09 0:01 ` Joon Ro
1 sibling, 1 reply; 8+ messages in thread
From: Thomas S. Dye @ 2017-02-08 20:48 UTC (permalink / raw)
To: Joon Ro; +Cc: emacs-orgmode@gnu.org
Aloha Joon,
Joon Ro writes:
> Hi,
>
>
> In latex export, sometimes I want to make sure a section starts in a new page.
>
> It seems I should be able to add a hook to org-export-before-parsing-hook, so if it sees a section with :newpage: tag (for example), it adds #+LATEX: \newpage before the section header so I would get
>
>
> \newpage
>
> \section{Section Name}
>
> in the exported file.
>
> I have a couple of hooks already so in general I'm using the following code:
>
> (org-map-entries
> (lambda ()
> (progn
>
> ))
> "+newpage")
>
> but I'm not sure how to add #+LATEX: \newpage before the section header - .
>
> Best Regards,
> Joon
I use this:
**** Ignore headline and/or start newpage on export
#+name: ignoreheading-and-or-newpage-on-export
#+BEGIN_SRC emacs-lisp :results silent
(defun tsd-ignore-headline-and-or-newpage (contents backend info)
"Ignore headlines with tag `ignoreheading' and/or start
headline on LaTeX new page with tag `newpage'."
(cond ((and (org-export-derived-backend-p backend 'latex 'beamer)
(string-match "\\`.*newpage.*\n" (downcase contents))
(string-match "\\`.*ignoreheading.*\n" (downcase contents)))
(replace-match "\\\\newpage" nil nil contents))
((and (org-export-derived-backend-p backend 'latex 'html 'ascii 'beamer)
(string-match "\\`.*ignoreheading.*\n" (downcase contents)))
(replace-match "" nil nil contents))
((and (org-export-derived-backend-p backend 'latex)
(string-match "\\(\\`.*\\)newpage\\(.*\n\\)" (downcase contents)))
(replace-match "\\\\newpage\\1\\2" nil nil contents))))
;; add function to filter list
;; (add-to-list 'org-export-filter-headline-functions
;; 'tsd-ignore-headline-and-or-newpage)
#+END_SRC
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-08 20:48 ` Thomas S. Dye
@ 2017-02-09 0:01 ` Joon Ro
2017-02-09 1:27 ` Nick Dokos
0 siblings, 1 reply; 8+ messages in thread
From: Joon Ro @ 2017-02-09 0:01 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2917 bytes --]
So far I have done:
(defun org/parse-headings (backend)
(if (member backend '(latex))
(org-map-entries
(lambda ()
(progn
(insert-string "#+LATEX: \\newpage")
))
"+newpage")
)
)
(add-hook 'org-export-before-parsing-hook 'org/parse-headings)
This puts #+LATEX: \\newpage before the subheading, but the problem is if I try to do (insert-string "#+LATEX: \\newpage"), exporting gets stuck with the message "org-babel-exp process txt at position 280541...". I suspect inserting a string messes up the position. How would I insert string with the newline character before a heading?
Best,
Joon
________________________________
From: Thomas S. Dye <tsd@tsdye.com>
Sent: Wednesday, February 8, 2017 2:48:47 PM
To: Joon Ro
Cc: emacs-orgmode@gnu.org
Subject: Re: [O] Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
Aloha Joon,
Joon Ro writes:
> Hi,
>
>
> In latex export, sometimes I want to make sure a section starts in a new page.
>
> It seems I should be able to add a hook to org-export-before-parsing-hook, so if it sees a section with :newpage: tag (for example), it adds #+LATEX: \newpage before the section header so I would get
>
>
> \newpage
>
> \section{Section Name}
>
> in the exported file.
>
> I have a couple of hooks already so in general I'm using the following code:
>
> (org-map-entries
> (lambda ()
> (progn
>
> ))
> "+newpage")
>
> but I'm not sure how to add #+LATEX: \newpage before the section header - .
>
> Best Regards,
> Joon
I use this:
**** Ignore headline and/or start newpage on export
#+name: ignoreheading-and-or-newpage-on-export
#+BEGIN_SRC emacs-lisp :results silent
(defun tsd-ignore-headline-and-or-newpage (contents backend info)
"Ignore headlines with tag `ignoreheading' and/or start
headline on LaTeX new page with tag `newpage'."
(cond ((and (org-export-derived-backend-p backend 'latex 'beamer)
(string-match "\\`.*newpage.*\n" (downcase contents))
(string-match "\\`.*ignoreheading.*\n" (downcase contents)))
(replace-match "\\\\newpage" nil nil contents))
((and (org-export-derived-backend-p backend 'latex 'html 'ascii 'beamer)
(string-match "\\`.*ignoreheading.*\n" (downcase contents)))
(replace-match "" nil nil contents))
((and (org-export-derived-backend-p backend 'latex)
(string-match "\\(\\`.*\\)newpage\\(.*\n\\)" (downcase contents)))
(replace-match "\\\\newpage\\1\\2" nil nil contents))))
;; add function to filter list
;; (add-to-list 'org-export-filter-headline-functions
;; 'tsd-ignore-headline-and-or-newpage)
#+END_SRC
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
[-- Attachment #2: Type: text/html, Size: 6281 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-09 0:01 ` Joon Ro
@ 2017-02-09 1:27 ` Nick Dokos
2017-02-09 1:36 ` Eric Abrahamsen
2017-02-09 2:58 ` Joon Ro
0 siblings, 2 replies; 8+ messages in thread
From: Nick Dokos @ 2017-02-09 1:27 UTC (permalink / raw)
To: emacs-orgmode
Joon Ro <joon.ro@outlook.com> writes:
> So far I have done:
>
> (defun org/parse-headings (backend)
> (if (member backend '(latex))
> (org-map-entries
> (lambda ()
> (progn
> (insert-string "#+LATEX: \\newpage")
> ))
> "+newpage")
> )
> )
>
> (add-hook 'org-export-before-parsing-hook 'org/parse-headings)
>
> This puts #+LATEX: \\newpage before the subheading, but the problem is if I try to do (insert-string "#+LATEX: \\newpage"), exporting gets stuck with the message "org-babel-exp process txt
> at position 280541...". I suspect inserting a string messes up the position. How would I insert string with the newline character before a heading?
>
See the doc for org-map-entries - it says:
,----
| The call to FUNC will be wrapped into a save-excursion form, so FUNC
| does not need to preserve point. After evaluation, the cursor will be
| moved to the end of the line (presumably of the headline of the
| processed entry) and search continues from there. Under some
| circumstances, this may not produce the wanted results. For example,
| if you have removed (e.g. archived) the current (sub)tree it could
| mean that the next entry will be skipped entirely. In such cases, you
| can specify the position from where search should continue by making
| FUNC set the variable ‘org-map-continue-from’ to the desired buffer
| position.
`----
So you'll have to manipulate org-map-continue-from appropriately.
--
Nick
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-09 1:27 ` Nick Dokos
@ 2017-02-09 1:36 ` Eric Abrahamsen
2017-02-09 2:58 ` Joon Ro
1 sibling, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2017-02-09 1:36 UTC (permalink / raw)
To: emacs-orgmode
Nick Dokos <ndokos@gmail.com> writes:
> Joon Ro <joon.ro@outlook.com> writes:
>
>> So far I have done:
>>
>> (defun org/parse-headings (backend)
>> (if (member backend '(latex))
>> (org-map-entries
>> (lambda ()
>> (progn
>> (insert-string "#+LATEX: \\newpage")
>> ))
>> "+newpage")
>> )
>> )
>>
>> (add-hook 'org-export-before-parsing-hook 'org/parse-headings)
>>
>> This puts #+LATEX: \\newpage before the subheading, but the problem is if I try to do (insert-string "#+LATEX: \\newpage"), exporting gets stuck with the message "org-babel-exp process txt
>> at position 280541...". I suspect inserting a string messes up the position. How would I insert string with the newline character before a heading?
>>
> See the doc for org-map-entries - it says:
>
> ,----
> | The call to FUNC will be wrapped into a save-excursion form, so FUNC
> | does not need to preserve point. After evaluation, the cursor will be
> | moved to the end of the line (presumably of the headline of the
> | processed entry) and search continues from there. Under some
> | circumstances, this may not produce the wanted results. For example,
> | if you have removed (e.g. archived) the current (sub)tree it could
> | mean that the next entry will be skipped entirely. In such cases, you
> | can specify the position from where search should continue by making
> | FUNC set the variable ‘org-map-continue-from’ to the desired buffer
> | position.
> `----
>
> So you'll have to manipulate org-map-continue-from appropriately.
I would think it would be easier to add at export time using
`org-export-filter-headline-functions'.
Eric
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-09 1:27 ` Nick Dokos
2017-02-09 1:36 ` Eric Abrahamsen
@ 2017-02-09 2:58 ` Joon Ro
2017-02-11 19:40 ` Joon Ro
1 sibling, 1 reply; 8+ messages in thread
From: Joon Ro @ 2017-02-09 2:58 UTC (permalink / raw)
To: Nick Dokos, emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 809 bytes --]
> So you'll have to manipulate org-map-continue-from appropriately.
Thanks a lot! Adding (setq org-map-continue-from (outline-next-heading)) after insert-string seemed to solve the problem.
(I added "newpage" to org-tags-exclude-from-inheritance, so the newpage does not get applied to subheadings)
(defun org/parse-headings-latex-newpage (backend)
; add \newpage to headings with :newpage: tag
(if (member backend '(latex))
(org-map-entries
(lambda ()
(progn
(insert-string "#+LATEX: \\newpage\n")
(setq org-map-continue-from (outline-next-heading))
))
"+newpage"))
)
(add-hook 'org-export-before-parsing-hook 'org/parse-headings-latex-newpage)
(add-to-list 'org-tags-exclude-from-inheritance '"newpage")
Best,
Joon
[-- Attachment #2: Type: text/html, Size: 2244 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
2017-02-09 2:58 ` Joon Ro
@ 2017-02-11 19:40 ` Joon Ro
0 siblings, 0 replies; 8+ messages in thread
From: Joon Ro @ 2017-02-11 19:40 UTC (permalink / raw)
To: Nick Dokos, emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1837 bytes --]
I spoke too early - if I have two headings with :newpage: tag in a row, my current code below skips the second heading.
It seems (setq org-map-continue-from (outline-next-heading)) in my code is the problem .. any help will be appreciated!
(defun org/parse-headings-newpage (backend)
; add \newpage to headings with :newpage: tag
(if (member backend '(latex))
(org-map-entries
(lambda ()
(insert-string "#+LATEX: \\newpage\n")
(if (outline-next-heading)
(setq org-map-continue-from (outline-next-heading)))
)
"+newpage"))
)
(add-hook 'org-export-before-parsing-hook 'org/parse-headings-newpage)
________________________________
From: Emacs-orgmode <emacs-orgmode-bounces+joon.ro=outlook.com@gnu.org> on behalf of Joon Ro <joon.ro@outlook.com>
Sent: Wednesday, February 8, 2017 8:58:40 PM
To: Nick Dokos; emacs-orgmode@gnu.org
Subject: Re: [O] Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook
> So you'll have to manipulate org-map-continue-from appropriately.
Thanks a lot! Adding (setq org-map-continue-from (outline-next-heading)) after insert-string seemed to solve the problem.
(I added "newpage" to org-tags-exclude-from-inheritance, so the newpage does not get applied to subheadings)
(defun org/parse-headings-latex-newpage (backend)
; add \newpage to headings with :newpage: tag
(if (member backend '(latex))
(org-map-entries
(lambda ()
(progn
(insert-string "#+LATEX: \\newpage\n")
(setq org-map-continue-from (outline-next-heading))
))
"+newpage"))
)
(add-hook 'org-export-before-parsing-hook 'org/parse-headings-latex-newpage)
(add-to-list 'org-tags-exclude-from-inheritance '"newpage")
Best,
Joon
[-- Attachment #2: Type: text/html, Size: 4419 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-02-11 19:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-08 19:52 Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook Joon Ro
2017-02-08 19:53 ` Joon Ro
2017-02-08 20:48 ` Thomas S. Dye
2017-02-09 0:01 ` Joon Ro
2017-02-09 1:27 ` Nick Dokos
2017-02-09 1:36 ` Eric Abrahamsen
2017-02-09 2:58 ` Joon Ro
2017-02-11 19:40 ` Joon Ro
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).