1

I am using org files to organize my research projects. I am using org both on Linux and Windows. While I am exporting org files to LaTeX or Beamer, a link to a local file on Windows starts with [[C:\Users\MYSELF\Document\org...][Text]], whereas a link to a same synced local file on Linux starts with [[/home/MYSELF/local/docs/org....][Text]].

I thought that #+MACRO: docs_path system_specific_docs_heading can do the job but it expands only on specific locations and not replacing this in links. I tried and write a function hooking on rg-export-filter-latex-fragment-functions but it did not replace strings in the link definitions either.

I am wondering if there is an efficient way to make these change in the link definitions automatically when I am exporting to the LaTeX/Beamer.

1

[This answer requires that you write some lisp.]

I think the best way is to define your own custom link type. The idea would be to have a single org file that could be processed on either of the two systems and the export would treat the link type differently. For example the link [[sysdep:foo][foo]] would be exported as \href{file:///windows-sys-doc-path/foo} on the windows system, but as \href{file:///linux-sys-doc-path/foo} on the linux system.

For that you would need to add the link type:

(org-link-set-parameters "sysdep"
                         :store 'org-sysdep-store-link
                         :export 'org-sysdep-export
                         :follow 'org-sysdep-open)

and then provide definitions for the three sysdep functions.

Look in the contrib/lisp/org-man.el for an example of how to provide a custom link type for man-pages and see if you can define the functions above. The general idea for each function would be to check the variable system-type which tells you what type of system the emacs instance is running on (the value is a symbol - two examples are 'gnu/.linux and 'windows-nt but there are many others - see the documentation of system-type for all the possibilities). Then based on the value of that variable, each function would do different things.

Not a complete answer by any means, but I hope it's helpful. And maybe others will chime in with different methods.

  • Thank you so much Nick. I ended up writing a function to do 'replace-match' that is called by 'org-export-before-processing-hook with different strings for each system. Your solution seems more elegant and I will definitely try your suggestion. – lenient7 Mar 12 '18 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.