Jens Lechtenboerger <lech...@wi.uni-muenster.de> writes:

> Hi all,
>
> I publish OER (https://oer.gitlab.io/) from Org sources and wonder
> about links to local files as documented at [1].  That page only
> talks about HTML export.  How can I achieve similar behavior for
> LaTeX/PDF export?
>
> More precisely: For HTML export, a link like
> [[file:foo.org::#custom-id][elsewhere]] turns into a hyperlink to
> “foo.html#custom-id”, which is what I want.
>
> However, for LaTeX/PDF export, the hyperlink points to the source
> file “foo.org”, which in my case is a broken link.  I would like
> that to be “foo.pdf” (or even something pointing at the proper
> section in the PDF file).
>
> Is this (easily) possible?
>

I think what you need is an export filter function for links in latex
exports. Have a look at the docstring for variable 
org-export-filter-link-functions. 

As a very basic example, the following should work


(defun my-latex-link-filter (text backend info)
  "Replace link to org files with pdf version."
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "\\.org" ".pdf" text)))

(add-to-list 'org-export-filter-link-functions
             'my-latex-link-filter)
             
Note that the above example is likely too 'basic'. For example, you need
to be wary of the file path if the exported PDF is going to be moved to
a different location. This is one of the limitations of file links. 

If you have a sufficiently complex publishing requirement, you might
find the org-publish module useful as it can provide a convenient way to
put all your publishing configuration into a single easier to manage
variable. (see org manual section on publishing). 

Reply via email to