From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: Help with export filter? Date: Mon, 21 Jul 2014 12:50:11 +0200 Message-ID: <8761ir0yvw.fsf@gmx.us> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9BB1-0005j3-Ka for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 06:50:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X9BAv-0004ne-BW for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 06:50:39 -0400 Received: from mout.gmx.net ([212.227.15.15]:51665) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X9BAu-0004nU-IP for emacs-orgmode@gnu.org; Mon, 21 Jul 2014 06:50:32 -0400 In-Reply-To: (Thomas S. Dye's message of "Sat, 19 Jul 2014 08:53:08 -1000") 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: tsd@tsdye.com Cc: emacs-orgmode@gnu.org Hi Tom, tsd@tsdye.com (Thomas S. Dye) writes: > Aloha all, > > Inspired by discussions and code on the mailing list, I managed to > cobble together the headline filter below. It "works" in that the > pdf output from LaTeX export is exactly what I want. I'm thrilled! > > It has one unwanted side effect. In the tex file, a headline tagged > with either :newpage: or :clearpage: includes some extra baggage, like > this: > > \newpage > \section*{Introduction\hfill{}\textsc{}} > \label{sec-5} > > I tried setting the option tags:nil, but then my export tags had no > effect. Can someone suggest how I can avoid the \hfill etc.? Or, am I > picking nits here? > > ***** Filter headline tags > > #+name: filter-headline-tags > #+BEGIN_SRC emacs-lisp :results silent > > (defun tsd-filter-headline-tags (contents backend info) > "Ignore headlines with tag `ignoreheading' and/or start LaTeX > section with `newpage' or `clearpage' command." > (cond ((and (org-export-derived-backend-p backend 'latex) > (string-match "\\`.*newpage.*\n" (downcase contents)) > (string-match "\\`.*ignoreheading.*\n" (downcase contents= ))) > (replace-match "\\\\newpage\n" nil nil contents)) > ((and (org-export-derived-backend-p backend 'latex) > (string-match "\\`.*clearpage.*\n" (downcase contents)) > (string-match "\\`.*ignoreheading.*\n" (downcase contents= ))) > (replace-match "\\\\clearpage\n" nil nil contents)) > ((and (org-export-derived-backend-p backend 'latex 'html 'ascii) > (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\n\\1\\2" nil nil contents)) > ((and (org-export-derived-backend-p backend 'latex) > (string-match "\\(\\`.*\\)clearpage\\(.*\n\\)" (downcase = contents))) > (replace-match "\\\\clearpage\n\\1\\2" nil nil contents)))) > #+END_SRC Here's an edited filter that works with the enclosed test document. Note that you could split this into different filters, but it may be non-trivial with this identification-scheme since things would be moving around. (defun tsd-filter-headline-tags (contents backend info) "Ignore headlines with tag `ignoreheading' and/or start LaTeX section with `newpage' or `clearpage' command." (cond ((and (org-export-derived-backend-p backend 'latex) (string-match "\\`.*newpage.*\n" (downcase contents)) ;; if you want to get rid of labels use the string ;; "\\`.*ignoreheading.*\n.*\n" (string-match "\\`.*ignoreheading.*\n" (downcase contents))) (replace-match "\\\\newpage\n" nil nil contents)) ((and (org-export-derived-backend-p backend 'latex) (string-match "\\`.*clearpage.*\n" (downcase contents)) (string-match "\\`.*ignoreheading.*\n" (downcase contents))) (replace-match "\\\\clearpage\n" nil nil contents)) ((and (org-export-derived-backend-p backend 'latex 'html 'ascii) (string-match "\\`.*ignoreheading.*\n" (downcase contents))) (replace-match "" nil nil contents)) ((and (org-export-derived-backend-p backend 'latex) (string-match "\\(\\`.*?\\)\\(?:\\\\hfill{}\\)?\\\\textsc{.*?newpage= .*?}\\(.*\n\\)" (downcase contents))) (replace-match "\\\\newpage\n\\1\\2" nil nil contents)) ((and (org-export-derived-backend-p backend 'latex) (string-match "\\(\\`.*?\\)\\(?:\\\\hfill{}\\)?\\\\textsc{.*?clearpa= ge.*?}\\(.*\n\\)" (downcase contents))) (replace-match "\\\\clearpage\n\\1\\2" nil nil contents)))) (add-to-list 'org-export-filter-headline-functions 'tsd-filter-headline-tag= s) * my first headline cont0 * ignored headline :ignoreheading: cont1 (ignored headline) * heading with newpage :newpage: newline before *here* * heading with clearpage :clearpage: clearpage before *here* * ignored heading with newpage :newpage:tag2: newline before *here*. =3Dtag2=3D is lost. * ignore heading with clearpage :ignoreheading:clearpage: clearpage before *here* =E2=80=94Rasmus --=20 =F0=9F=90=89