emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Help with export filter?
@ 2014-07-19 18:53 Thomas S. Dye
  2014-07-21 10:50 ` Rasmus
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas S. Dye @ 2014-07-19 18:53 UTC (permalink / raw)
  To: Org-mode

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

All the best,
Tom


-- 
T.S. Dye & Colleagues, Archaeologists
735 Bishop St, Suite 315, Honolulu, HI 96813
Tel: 808-529-0866, Fax: 808-529-0884
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2014-07-19 18:53 Help with export filter? Thomas S. Dye
@ 2014-07-21 10:50 ` Rasmus
  2014-07-21 15:55   ` Thomas S. Dye
  2015-08-12 13:33   ` Samuel Loury
  0 siblings, 2 replies; 9+ messages in thread
From: Rasmus @ 2014-07-21 10:50 UTC (permalink / raw)
  To: tsd; +Cc: emacs-orgmode

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 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

-- 
🐉

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2014-07-21 10:50 ` Rasmus
@ 2014-07-21 15:55   ` Thomas S. Dye
  2015-08-12 13:33   ` Samuel Loury
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas S. Dye @ 2014-07-21 15:55 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Aloha Rasmus,

Rasmus <rasmus@gmx.us> writes:

> Hi Tom,
>
>
> 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

Thanks very much for your help.  The new filter does just what I want.

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2014-07-21 10:50 ` Rasmus
  2014-07-21 15:55   ` Thomas S. Dye
@ 2015-08-12 13:33   ` Samuel Loury
  2015-08-12 13:46     ` Nicolas Goaziou
  1 sibling, 1 reply; 9+ messages in thread
From: Samuel Loury @ 2015-08-12 13:33 UTC (permalink / raw)
  To: Rasmus, tsd; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2607 bytes --]

Hi all,
Rasmus <rasmus@gmx.us> writes:

> 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 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

This I just the feature I need today. Thank you for sharing. Do you know
what is missing to add the feature to org-mode instead of adding in each
user's .emacs file?

My best,
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2015-08-12 13:33   ` Samuel Loury
@ 2015-08-12 13:46     ` Nicolas Goaziou
  2015-08-12 14:32       ` Samuel Loury
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2015-08-12 13:46 UTC (permalink / raw)
  To: Samuel Loury; +Cc: emacs-orgmode, Rasmus

Hello

Samuel Loury <konubinix@gmail.com> writes:

> This I just the feature I need today. Thank you for sharing. Do you know
> what is missing to add the feature to org-mode instead of adding in each
> user's .emacs file?

This function apparently includes many features. Which one are you
talking about?

The :ignoreheading: part has been discussed already on this ML (and it's
a FAQ, IIRC). The major problem is that it is not clearly defined as
a parse tree operation.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2015-08-12 13:46     ` Nicolas Goaziou
@ 2015-08-12 14:32       ` Samuel Loury
  2015-08-12 14:42         ` Nicolas Goaziou
  2015-08-12 22:36         ` Rasmus
  0 siblings, 2 replies; 9+ messages in thread
From: Samuel Loury @ 2015-08-12 14:32 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

[-- Attachment #1: Type: text/plain, Size: 1608 bytes --]

Dear Nicolas,

Thank you for the prompt reply.
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Samuel Loury <konubinix@gmail.com> writes:
>
>> This I just the feature I need today. Thank you for sharing. Do you know
>> what is missing to add the feature to org-mode instead of adding in each
>> user's .emacs file?
>
> This function apparently includes many features. Which one are you
> talking about?

I used the clearpage and newpage features. The only other way I found
out was to add a bit of latex just before the heading.

--8<---------------cut here---------------start------------->8---
* My heading
  Some content with images.
@@latex:\clearpage@@
* My other heading, totally cleared
  some other content
--8<---------------cut here---------------end--------------->8---

What I dislike with this way of doing is that the latex fragment is
inside the heading above while I would prefer to associate it with the
second heading. The semantic in my case is "I am starting a brand new
topic, clear the floats from the last topic so that they won't pollute
my new topic".

I find the solution with the code of Thomas S. Dye very elegant:
--8<---------------cut here---------------start------------->8---
* My heading
  Some content with images.
* My other heading, totally cleared             :clearpage:
  some other content
--8<---------------cut here---------------end--------------->8---

I hope I clarified the use and the what for.

Best regards,
-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2015-08-12 14:32       ` Samuel Loury
@ 2015-08-12 14:42         ` Nicolas Goaziou
  2015-08-12 14:54           ` Samuel Loury
  2015-08-12 22:36         ` Rasmus
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2015-08-12 14:42 UTC (permalink / raw)
  To: Samuel Loury; +Cc: emacs-orgmode, Rasmus

Samuel Loury <konubinix@gmail.com> writes:

> I find the solution with the code of Thomas S. Dye very elegant:
> * My heading
>   Some content with images.
> * My other heading, totally cleared             :clearpage:
>   some other content
>
> I hope I clarified the use and the what for.

AFAICT, this is a very specific, cosmetic, feature targeting a single
family of export back-ends (i.e., LaTeX and derivatives).

I see nothing wrong to letting users implement it themselves, as they
see fit (e.g., one could prefer using a less visible node property for
that).

Regards,

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2015-08-12 14:42         ` Nicolas Goaziou
@ 2015-08-12 14:54           ` Samuel Loury
  0 siblings, 0 replies; 9+ messages in thread
From: Samuel Loury @ 2015-08-12 14:54 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Samuel Loury <konubinix@gmail.com> writes:
>
>> I find the solution with the code of Thomas S. Dye very elegant:
>> * My heading
>>   Some content with images.
>> * My other heading, totally cleared             :clearpage:
>>   some other content
>>
>> I hope I clarified the use and the what for.
>
> AFAICT, this is a very specific, cosmetic, feature targeting a single
> family of export back-ends (i.e., LaTeX and derivatives).
>
> I see nothing wrong to letting users implement it themselves, as they
> see fit (e.g., one could prefer using a less visible node property for
> that).

I agree with you.

Thank you for taking the time to answer.

-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Help with export filter?
  2015-08-12 14:32       ` Samuel Loury
  2015-08-12 14:42         ` Nicolas Goaziou
@ 2015-08-12 22:36         ` Rasmus
  1 sibling, 0 replies; 9+ messages in thread
From: Rasmus @ 2015-08-12 22:36 UTC (permalink / raw)
  To: emacs-orgmode

Samuel Loury <konubinix@gmail.com> writes:

> Dear Nicolas,
>
> Thank you for the prompt reply.
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Samuel Loury <konubinix@gmail.com> writes:
>>
>>> This I just the feature I need today. Thank you for sharing. Do you know
>>> what is missing to add the feature to org-mode instead of adding in each
>>> user's .emacs file?
>>
>> This function apparently includes many features. Which one are you
>> talking about?
>
> I used the clearpage and newpage features. The only other way I found
> out was to add a bit of latex just before the heading.

As Nicolas says, we'd need to think carefully as to how to incorporate
such things across backends for it to be worthwhile to include.  For
clearpage you'd have something like "\f" in ascii and there's an odt
equivalent as well.  For html it's less clear.

New features should be implemented like headline properties.

I would still like to see a proper ignoreheading, but it's a proper
definition of this behavior is hard.

Note: For all Tom's examples it would be enough to have a way to insert
arbitrary code just before (and maybe just after) a headline.  An
"export_before_BACKEND" property, say.

Rasmus

-- 
Vote for Dick Taid in an election near you!

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-08-12 22:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-19 18:53 Help with export filter? Thomas S. Dye
2014-07-21 10:50 ` Rasmus
2014-07-21 15:55   ` Thomas S. Dye
2015-08-12 13:33   ` Samuel Loury
2015-08-12 13:46     ` Nicolas Goaziou
2015-08-12 14:32       ` Samuel Loury
2015-08-12 14:42         ` Nicolas Goaziou
2015-08-12 14:54           ` Samuel Loury
2015-08-12 22:36         ` Rasmus

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).