You posted already the solution for the HTML backend. So I will address only the LaTeX backend here.
Pittingly, you did not describe how you want to export tex-fig
links to LaTeX.
I assume here you want to use \import{...}
for such figures as the org LaTeX export does for pgf
figures.
For that case we can just re-use the .pgf
branch of org-latex--inline-image
for our purpose. We just have to take care that we
- provide the right arguments
- fake a
.pgf
file name which we correct in the resulting exported string
At first glance the code seems a bit bulky. But, the bits of the code are quite general. So, the gv setter for org-element-property
can be used in general and I am surprised that the Org API didn't provide it already. Furthermore, my-org-let-info
can be useful for other exporters as well.
(require 'org-element)
(defun my-org-export-tex-fig (path description backend)
"Call the BACKEND specific tex-fig exporter.
The name of the exporter is `my-org-export-tex-fig:BACKEND'.
It is called with PATH and DESCRIPTION as arguments."
(let ((sym (intern-soft (format "my-org-export-tex-fig:%s" backend))))
(if sym
(funcall sym path description)
(user-error "Backend %s not implemented" backend))))
(defvar my-org-let-info nil
"Save `info' arg of `org-latex-link'.")
(defun my-org-let-info (fun link desc info)
"Save INFO locally in `my-org-latex-info'.
Just pass all args LINK, DESC, and INFO to FUN."
(let ((my-org-let-info (list link info)))
(funcall fun link desc info)))
(advice-add 'org-latex-link :around #'my-org-let-info)
(gv-define-simple-setter
org-element-property
(lambda (property element value)
(org-element-put-property element property value))
'fix-return)
(defun my-org-export-tex-fig:latex (path description)
"LaTeX specific tex-fig exporter.
Export org links of form [[tex-fig:PATH][DESCRIPTION]] to LaTeX."
(cl-letf* ((link (nth 0 my-org-let-info))
((org-element-property :path link)
(concat path ".pgf"))
(info (nth 1 my-org-let-info))
(ret (org-latex--inline-image link info)))
(replace-regexp-in-string "\\\\input{.*?\\(\\.pgf\\)}" "" ret t t 1)))
(org-link-set-parameters
"tex-fig" :export #'my-org-export-tex-fig)
The code is tested with Emacs 26.3 called as emacs -Q
.