emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Help on org-export-filter-link-functions
@ 2014-10-03 11:19 Daimrod
  2014-10-04 16:40 ` John Kitchin
  0 siblings, 1 reply; 5+ messages in thread
From: Daimrod @ 2014-10-03 11:19 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I've wrote a simple filter to customize how links are exported in
latex:
#+BEGIN_SRC
(defun dmd--latex-bib-link-filter (data backend info)
  "Convert a bib link to a citation (e.g. bib:foo93 -> \cite{foo93})."
  (let* ((beg (next-property-change 0 data))
         (link (if beg (get-text-property beg :parent data))))
    (cond ((and link
                (org-export-derived-backend-p backend 'latex)
                (string= (org-element-property :type link) "bib"))
           (format "\\cite{%s}" (org-element-property :path link)))
          ((and link
                (org-export-derived-backend-p backend 'latex)
                (string= (org-element-property :type link) "file")
                (string= (org-element-property :path link) "~/.bib.bib"))
           (format "\\cite{%s}" (org-element-property :search-option link)))
          (t data))))
#+END_SRC

And I was wondering whether there is an easier way to retrieve the org
properties stored in the text properties of DATA.

Best,

-- 
Daimrod/Greg

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

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

* Re: Help on org-export-filter-link-functions
  2014-10-03 11:19 Help on org-export-filter-link-functions Daimrod
@ 2014-10-04 16:40 ` John Kitchin
  2014-10-05  1:13   ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: John Kitchin @ 2014-10-04 16:40 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode

Daimrod <daimrod@gmail.com> writes:

Why don't you just define how the link should be exported in your link
definition?

for example:
https://github.com/jkitchin/jmax/blob/master/org/org-ref.org#the-links

You can see a link that is defined, with different export formats for
different backends.

I am intrigued by your function! It does not seem to work for all types
of links though, for example I tried on on some file links,
e.g. file:bib.bib, and [[file.bib]], but these fall in the (t data)
case. [[file:bib.bib][bibliography]] on the other hand gets handled and
you can access the element properties. 

I tried a similar approach on a table, but it did not work as I
expected. Apparently the next property change puts you in a table-cell,
rather than the parent table.

I too am wondering if there is a defined way to get to the element
properties within a filter function. For example, in this post
http://kitchingroup.cheme.cmu.edu/blog/2014/09/22/Showing-what-data-went-into-a-code-block-on-export/
I concocted a preprocess scheme to get a list of table names, and then a
filter function to put the names in the export on each table. It would
be much more elegant to get it directly from the table element somehow.




> Hi,
>
> I've wrote a simple filter to customize how links are exported in
> latex:
>
> #+BEGIN_SRC
> (defun dmd--latex-bib-link-filter (data backend info)
>   "Convert a bib link to a citation (e.g. bib:foo93 -> \cite{foo93})."
>   (let* ((beg (next-property-change 0 data))
>          (link (if beg (get-text-property beg :parent data))))
>     (cond ((and link
>                 (org-export-derived-backend-p backend 'latex)
>                 (string= (org-element-property :type link) "bib"))
>            (format "\\cite{%s}" (org-element-property :path link)))
>           ((and link
>                 (org-export-derived-backend-p backend 'latex)
>                 (string= (org-element-property :type link) "file")
>                 (string= (org-element-property :path link) "~/.bib.bib"))
>            (format "\\cite{%s}" (org-element-property :search-option link)))
>           (t data))))
> #+END_SRC
>
> And I was wondering whether there is an easier way to retrieve the org
> properties stored in the text properties of DATA.
>
> Best,

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

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

* Re: Help on org-export-filter-link-functions
  2014-10-04 16:40 ` John Kitchin
@ 2014-10-05  1:13   ` Rasmus
  2014-10-05 13:11     ` John Kitchin
  0 siblings, 1 reply; 5+ messages in thread
From: Rasmus @ 2014-10-05  1:13 UTC (permalink / raw)
  To: emacs-orgmode

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I too am wondering if there is a defined way to get to the element
> properties within a filter function.

qNo.  But sometimes you can recover it from the text-properties, if it
is not a verb, (~·~, =·=).  Her's an example:

  (defun rasmus/get-org-headline-string-element  (headline backend info)
    "Return the org element representation of a headline."
    (let ((prop-point (next-property-change 0 headline)))
      (and prop-point (plist-get (text-properties-at prop-point headline) :parent))))

-- 
And I faced endless streams of vendor-approved Ikea furniture. . .

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

* Re: Help on org-export-filter-link-functions
  2014-10-05  1:13   ` Rasmus
@ 2014-10-05 13:11     ` John Kitchin
  2014-10-05 22:24       ` Rasmus
  0 siblings, 1 reply; 5+ messages in thread
From: John Kitchin @ 2014-10-05 13:11 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

hmmm... the sometimes makes me nervous. I found even for links, this
only works sometimes. That doesn't seem reliable to me.

I think extending existing backends
(e.g. http://orgmode.org/manual/Advanced-configuration.html) is probably
more reliable for getting element properties, and approximately the same
amount of work.

I guess it just depends on how significantly you are modifying the
export, and what information you need to modify it. Filters are great
for simple wrapping and regexp based modifications. A derived backend is
better if you need reliable element properties, and a different format
than the default export.


> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I too am wondering if there is a defined way to get to the element
>> properties within a filter function.
>
> qNo.  But sometimes you can recover it from the text-properties, if it
> is not a verb, (~·~, =·=).  Her's an example:
>
>   (defun rasmus/get-org-headline-string-element  (headline backend info)
>     "Return the org element representation of a headline."
>     (let ((prop-point (next-property-change 0 headline)))
>       (and prop-point (plist-get (text-properties-at prop-point headline) :parent))))

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

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

* Re: Help on org-export-filter-link-functions
  2014-10-05 13:11     ` John Kitchin
@ 2014-10-05 22:24       ` Rasmus
  0 siblings, 0 replies; 5+ messages in thread
From: Rasmus @ 2014-10-05 22:24 UTC (permalink / raw)
  To: emacs-orgmode

Hi John,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> hmmm... the sometimes makes me nervous. I found even for links, this
> only works sometimes. That doesn't seem reliable to me.

With headlines the case where it does not work is for verb-only
headings.  I guess that could occur more frequently with links, though
I have never done anything serious with links. q  

> I think extending existing backends
> (e.g. http://orgmode.org/manual/Advanced-configuration.html) is probably
> more reliable for getting element properties, and approximately the same
> amount of work.
 
In practice derived classes could be a lot of work.

There is also two hooks that run before processing, but you'd need to
be able to solve the issue with org syntax.  In practice this is not a
limitation as you can use snippets for whatever backend.

> I guess it just depends on how significantly you are modifying the
> export, and what information you need to modify it. Filters are great
> for simple wrapping and regexp based modifications. A derived backend is
> better if you need reliable element properties, and a different format
> than the default export.

Yeah.

–Rasmus

-- 
I almost cut my hair, it happened just the other day

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

end of thread, other threads:[~2014-10-05 22:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-03 11:19 Help on org-export-filter-link-functions Daimrod
2014-10-04 16:40 ` John Kitchin
2014-10-05  1:13   ` Rasmus
2014-10-05 13:11     ` John Kitchin
2014-10-05 22:24       ` 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).