emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Publish to HTML and LaTeX/PDF with cross-file links?
@ 2022-06-15  6:36 Jens Lechtenboerger
  2022-06-15 23:55 ` Tim Cross
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Lechtenboerger @ 2022-06-15  6:36 UTC (permalink / raw)
  To: emacs-orgmode

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?

Best wishes
Jens


[1] https://orgmode.org/manual/Publishing-links.html#Publishing-links


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

* Re: Publish to HTML and LaTeX/PDF with cross-file links?
  2022-06-15  6:36 Publish to HTML and LaTeX/PDF with cross-file links? Jens Lechtenboerger
@ 2022-06-15 23:55 ` Tim Cross
  2022-06-16  9:17   ` Jens Lechtenboerger
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Cross @ 2022-06-15 23:55 UTC (permalink / raw)
  To: emacs-orgmode


Jens Lechtenboerger <lechten@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). 


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

* Re: Publish to HTML and LaTeX/PDF with cross-file links?
  2022-06-15 23:55 ` Tim Cross
@ 2022-06-16  9:17   ` Jens Lechtenboerger
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Lechtenboerger @ 2022-06-16  9:17 UTC (permalink / raw)
  To: Tim Cross; +Cc: emacs-orgmode

On 2022-06-16, at 09:55, Tim Cross wrote:

> Jens Lechtenboerger <lechten@wi.uni-muenster.de> writes:
>
>> [...]
>> 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
> [...]

Thank you for the suggestion!

I am still undecided which way to go.  Maybe a refactoring of code
from ox-html (to be usable across backends) would be appropriate
here.

Best wishes
Jens


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

end of thread, other threads:[~2022-06-16  9:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-15  6:36 Publish to HTML and LaTeX/PDF with cross-file links? Jens Lechtenboerger
2022-06-15 23:55 ` Tim Cross
2022-06-16  9:17   ` Jens Lechtenboerger

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