emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Filtering in export hooks
@ 2011-09-06  8:49 suvayu ali
  2011-09-06  8:58 ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: suvayu ali @ 2011-09-06  8:49 UTC (permalink / raw)
  To: org-mode mailing list

Hi Orgers,

What is the recommended way to filter/select headlines I want to
preprocess in any of the export hooks? I have tried using tags like
this:

(let ((match "tag1|tag2"))
  (org-map-entries (lambda () (my-preprocess-function))
		   match))

But this only works when tags: is non-nil. Any hints on how I could
achieve something that "works always"?

Thanks for any response.

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Filtering in export hooks
  2011-09-06  8:49 Filtering in export hooks suvayu ali
@ 2011-09-06  8:58 ` Carsten Dominik
  2011-09-06  9:08   ` suvayu ali
  0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2011-09-06  8:58 UTC (permalink / raw)
  To: suvayu ali; +Cc: org-mode mailing list


On Sep 6, 2011, at 10:49 AM, suvayu ali wrote:

> Hi Orgers,
> 
> What is the recommended way to filter/select headlines I want to
> preprocess in any of the export hooks? I have tried using tags like
> this:
> 
> (let ((match "tag1|tag2"))
>  (org-map-entries (lambda () (my-preprocess-function))
> 		   match))
> 
> But this only works when tags: is non-nil. Any hints on how I could
> achieve something that "works always"?

May be I do not understand, but how about

(let ((match "tag1|tag2"))
 (when match
   (org-map-entries (lambda () (my-preprocess-function))
  		   match)))

- Carsten

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

* Re: Filtering in export hooks
  2011-09-06  8:58 ` Carsten Dominik
@ 2011-09-06  9:08   ` suvayu ali
  2011-09-06  9:49     ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: suvayu ali @ 2011-09-06  9:08 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode mailing list

Hi Carsten,

On Tue, Sep 6, 2011 at 10:58 AM, Carsten Dominik
<carsten.dominik@gmail.com> wrote:
>>
>> But this only works when tags: is non-nil. Any hints on how I could
>> achieve something that "works always"?
>
> May be I do not understand, but how about
>
> (let ((match "tag1|tag2"))
>  (when match
>   (org-map-entries (lambda () (my-preprocess-function))
>                   match)))
>

Sorry after going through my email again I realised it was ambiguous.
When I say it doesn't work, I don't mean Org throws an error when
tags:nil is set. The preprocessing gets skipped.

To restate my intentions more clearly; I want to preprocess headlines
that match the tags list "tag1|tag2" during latex export irrespective
of how the tags: option is setup. If this is not possible by a tags
match, what are my alternatives?

> - Carsten

Thanks a lot. :)

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Filtering in export hooks
  2011-09-06  9:08   ` suvayu ali
@ 2011-09-06  9:49     ` Carsten Dominik
  2011-09-06 10:16       ` suvayu ali
  2011-09-06 22:39       ` suvayu ali
  0 siblings, 2 replies; 7+ messages in thread
From: Carsten Dominik @ 2011-09-06  9:49 UTC (permalink / raw)
  To: suvayu ali; +Cc: org-mode mailing list


On Sep 6, 2011, at 11:08 AM, suvayu ali wrote:

> Hi Carsten,
> 
> On Tue, Sep 6, 2011 at 10:58 AM, Carsten Dominik
> <carsten.dominik@gmail.com> wrote:
>>> 
>>> But this only works when tags: is non-nil. Any hints on how I could
>>> achieve something that "works always"?
>> 
>> May be I do not understand, but how about
>> 
>> (let ((match "tag1|tag2"))
>>  (when match
>>   (org-map-entries (lambda () (my-preprocess-function))
>>                   match)))
>> 
> 
> Sorry after going through my email again I realised it was ambiguous.
> When I say it doesn't work, I don't mean Org throws an error when
> tags:nil is set. The preprocessing gets skipped.

Which of the preprocessing hooks are you using?  I am still confused
by your description, maybe you can make a small example and show exactly what works and what does not work?

- Carsten

> 
> To restate my intentions more clearly; I want to preprocess headlines
> that match the tags list "tag1|tag2" during latex export irrespective
> of how the tags: option is setup. If this is not possible by a tags
> match, what are my alternatives?
> 
>> - Carsten
> 
> Thanks a lot. :)
> 
> -- 
> Suvayu
> 
> Open source is the future. It sets us free.

- Carsten

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

* Re: Filtering in export hooks
  2011-09-06  9:49     ` Carsten Dominik
@ 2011-09-06 10:16       ` suvayu ali
  2011-09-06 11:33         ` suvayu ali
  2011-09-06 22:39       ` suvayu ali
  1 sibling, 1 reply; 7+ messages in thread
From: suvayu ali @ 2011-09-06 10:16 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode mailing list

Hi Carsten,

On Tue, Sep 6, 2011 at 11:49 AM, Carsten Dominik
<carsten.dominik@gmail.com> wrote:
> Which of the preprocessing hooks are you using?  I am still confused
> by your description, maybe you can make a small example and show exactly what works and what does not work?
>

This is what I am using at the moment:

(defun my-org-export-latex-wrap-todo ()
  "Wrap heading with arbitrary latex environment."
  (interactive)
  (let* ((tags (org-get-tags-string))
	 (heading (org-get-heading t))	; heading with todo
	 (content (org-get-entry))
	 (color (cond ((string-match ":QnA:" tags)  "color=blue!40")
		      ((string-match ":Qn:" tags) "color=yellow!40"))))
    (when color
      (org-mark-subtree)
      (delete-region (region-beginning) (region-end))
      (insert (concat
	       (format "\\todo[inline,%s]{\\textbf{%s}%%\n" color heading)
	       (format "%s\n}%%\n" content))))))

(add-hook 'org-export-preprocess-after-blockquote-hook
	  (lambda ()
	    (let ((match "QnA|Qn"))
	      (org-map-entries (lambda () (my-org-export-latex-wrap-todo))
			       match))))

This works great as long as the tags: option is non-nil (t or
not-in-toc). Setting it to nil just ignores it and everything gets
like a regular headline. I am not using org-export-preprocess-hook
because some of the latex gets escaped during the export (e.g. {..}
becomes \{..}).

I hope this is clearer.

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Filtering in export hooks
  2011-09-06 10:16       ` suvayu ali
@ 2011-09-06 11:33         ` suvayu ali
  0 siblings, 0 replies; 7+ messages in thread
From: suvayu ali @ 2011-09-06 11:33 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode mailing list

On Tue, Sep 6, 2011 at 12:16 PM, suvayu ali <fatkasuvayu+linux@gmail.com> wrote:
> I am not using org-export-preprocess-hook
> because some of the latex gets escaped during the export (e.g. {..}
> becomes \{..}).
>

Sorry I confused this with an old issue, the problem here is org
markup like /italics/ or *bold* and links don't get translated.

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Filtering in export hooks
  2011-09-06  9:49     ` Carsten Dominik
  2011-09-06 10:16       ` suvayu ali
@ 2011-09-06 22:39       ` suvayu ali
  1 sibling, 0 replies; 7+ messages in thread
From: suvayu ali @ 2011-09-06 22:39 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: org-mode mailing list

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

Hi Carsten,

On Tue, Sep 6, 2011 at 11:49 AM, Carsten Dominik
<carsten.dominik@gmail.com> wrote:
>
> Which of the preprocessing hooks are you using?  I am still confused
> by your description, maybe you can make a small example and show
> exactly what works and what does not work?

I finally managed to isolate the issue and construct a working example.
To replicate, in a minimal session evaluating the code blocks in the
attached org file should be sufficient. The issue is described in the
org file.

Thanks a lot,

-- 
Suvayu

Open source is the future. It sets us free.

[-- Attachment #2: test.org --]
[-- Type: text/x-org, Size: 3444 bytes --]

#+OPTIONS:   H:4 num:nil toc:t \n:nil @:nil ::t |:t ^:t -:t f:t *:t <:nil
#+OPTIONS:   TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:nil

#+LaTeX_HEADER: \usepackage[backgroundcolor=green!40]{todonotes}
#+LaTeX_HEADER: \usepackage{makerobust}
#+LaTeX_HEADER: \MakeRobustCommand\begin
#+LaTeX_HEADER: \MakeRobustCommand\end
#+LaTeX_HEADER: \MakeRobustCommand\item


* COMMENT Setup

The following code is supposed to wrap the headlines matched by the
tags search "QnA|Qn" with a =\todo[inline]{..}= Latex macro. I am
using the tags to determine the colour of the todo block.

** Case 1

This gets exported for all values of the =tags:= option. But markup
like /italics/, *bold* or +strikethrough+ are not translated to Latex.
Links are also not translated properly.

#+begin_src emacs-lisp
;; org export hooks
(defun my-org-export-latex-wrap-todo ()
  "Wrap heading with arbitrary latex environment."
  (interactive)
  (let* ((tags (org-get-tags-string))
	 (heading (org-get-heading t))	; heading with todo
	 (content (org-get-entry))
	 (color (cond ((string-match ":QnA:" tags)  "color=blue!40")
		      ((string-match ":Qn:" tags) "color=yellow!40"))))
    (when color
      (org-mark-subtree)
      (delete-region (region-beginning) (region-end))
      (insert (concat
	       (format "\\todo[inline,%s]{\\textbf{%s}\\protect\\linebreak{}%%\n"
		       color heading)
	       (format "%s\n}%%\n" content))))))

;; FIXME: doesn't export markup like /italics/ or *bold* and links properly
(add-hook 'org-export-preprocess-hook
	  (lambda ()
	    (let ((match "QnA|Qn"))
	      (org-map-entries (lambda () (my-org-export-latex-wrap-todo))
			       match))))
#+end_src

** Case 2

The wrapping fails when the tags option is =tags:nil= but everything
gets translated to Latex properly. However when the =tags:= option is
non-nil, the wrapping works but the latex translation fails.

#+begin_src emacs-lisp
  ;; org export hooks
  (defun my-org-export-latex-wrap-todo ()
    "Wrap heading with arbitrary latex environment."
    (interactive)
    (let* ((tags (org-get-tags-string))
           (heading (org-get-heading t))  ; heading with todo
           (content (org-get-entry))
           (color (cond ((string-match ":QnA:" tags)  "color=blue!40")
                        ((string-match ":Qn:" tags) "color=yellow!40"))))
      (when color
        (org-mark-subtree)
        (delete-region (region-beginning) (region-end))
        (insert (concat
                 (format "\\todo[inline,%s]{\\textbf{%s}\\protect\\linebreak{}%%\n"
                         color heading)
                 (format "%s\n}%%\n" content))))))
  
  ;; FIXME: doesn't work with tags:nil
  (add-hook 'org-export-preprocess-after-blockquote-hook
         (lambda ()
           (let ((match "QnA|Qn"))
             (org-map-entries (lambda () (my-org-export-latex-wrap-todo))
                              match))))
#+end_src


* Bs⁰ decay
** Regular tree
Some text
1. maybe a list
2. with 2 items and some *bold text*

** Decay model 								 :Qn:
1. Justify neglecting CP violation
   - in decay for the DsK channel
   - in Bs mixing for both DsK and Dsπ channels
3. Verify master equations

** Mass hypothesis							:QnA:
1. Why do we need mass hypothesis?
   - /Energy resolution/ of the *HCAL* is not good.
   - +General purpose experiments don't care about jet constituents+.
2. Some link to [[*Regular%20tree][Regular tree]] that fails to export properly.

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

end of thread, other threads:[~2011-09-06 22:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-06  8:49 Filtering in export hooks suvayu ali
2011-09-06  8:58 ` Carsten Dominik
2011-09-06  9:08   ` suvayu ali
2011-09-06  9:49     ` Carsten Dominik
2011-09-06 10:16       ` suvayu ali
2011-09-06 11:33         ` suvayu ali
2011-09-06 22:39       ` suvayu ali

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