From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joon Ro Subject: Re: Adding #+LATEX: \newpage before section header using org-export-before-parsing-hook Date: Thu, 9 Feb 2017 00:01:34 +0000 Message-ID: References: , Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_000_CY4PR15MB1622518B2659B9864E774800EB420CY4PR15MB1622namp_" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbcBB-00044s-Gj for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 19:01:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbcB7-0006z1-7X for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 19:01:41 -0500 Received: from col004-omc3s9.hotmail.com ([65.55.34.147]:53640) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cbcB6-0006yo-OE for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 19:01:37 -0500 In-Reply-To: Content-Language: en-US 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" To: "emacs-orgmode@gnu.org" --_000_CY4PR15MB1622518B2659B9864E774800EB420CY4PR15MB1622namp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 in= serting a string messes up the position. How would I insert string with the= newline character before a heading? Best, Joon ________________________________ From: Thomas S. Dye 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-e= xport-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 co= de: > > (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 co= ntents))) (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 --_000_CY4PR15MB1622518B2659B9864E774800EB420CY4PR15MB1622namp_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

So far I have done:


(defun org/parse-headings (backend)
  (if (member backend '(latex))
      (org-map-entries
       (lambda ()
         (progn
           (insert-string "#+LA= TEX: \\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 proc= ess txt at position 280541...". I suspect inserting a string mess= es up the position. How would I insert string with the newline charact= er before a heading?

Best,
Joon



From: Thomas S. Dye <t= sd@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 n= ew page.
>
> It seems I should be able to add a hook to org-export-before-parsing-h= ook, so if it sees a section with :newpage: tag (for example), it adds #= 3;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 h= eader - .
>
> 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 s= tart
  headline on LaTeX new page with tag `newpage'."
    (cond ((and (org-export-derived-backend-p backend 'latex= 'beamer)
            &nb= sp;   (string-match "\\`.*newpage.*\n" (downcase conten= ts))
            &nb= sp;   (string-match "\\`.*ignoreheading.*\n" (downcase = contents)))
           (replace-match= "\\\\newpage" nil nil contents))
          ((and (org-export-de= rived-backend-p backend 'latex 'html 'ascii 'beamer)
            &nb= sp;   (string-match "\\`.*ignoreheading.*\n" (downcase = contents)))
           (replace-match= "" nil nil contents))
          ((and (org-export-de= rived-backend-p backend 'latex)
            &nb= sp;     (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
--_000_CY4PR15MB1622518B2659B9864E774800EB420CY4PR15MB1622namp_--