[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Help with export filter?
From: |
Rasmus |
Subject: |
Re: [O] Help with export filter? |
Date: |
Mon, 21 Jul 2014 12:50:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
Hi Tom,
address@hidden (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
> contents)))
> (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{.*?clearpage.*?}\\(.*\n\\)"
(downcase contents)))
(replace-match "\\\\clearpage\n\\1\\2" nil nil contents))))
(add-to-list 'org-export-filter-headline-functions 'tsd-filter-headline-tags)
* 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*. =tag2= is lost.
* ignore heading with clearpage :ignoreheading:clearpage:
clearpage before *here*
—Rasmus
--
🐉