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