* ox-latex.el (org-latex--inline-image): The user can now customize the
  way PGF images are included by changing the (new) variable

If the PGF file is stored in a subdirectory and references an external
image file in the same directory, LaTeX will complain about not finding
it.  A workaround could be to define a function like this in the


and customizing `org-latex-inline-pgf-command' to hold this function:

(lambda (path)
  (let ((dir-name (substring (file-name-directory path) 0 -1))
        (file-name (file-name-nondirectory path)))
    (format "\\inputpgf{%s}{%s}" dir-name file-name)))

This way, LaTeX will be able to find the external images.  The idea came
from here: http://tex.stackexchange.com/a/282110/9742

 lisp/ox-latex.el | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0901726..419f608 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -730,6 +730,19 @@ default we use here encompasses both."
   :type '(alist :key-type (string :tag "Type")
                :value-type (regexp :tag "Path")))
+(defcustom org-latex-inline-pgf-command
+  (lambda (path) (format "\\input{%s}" path))
+  "Function used to include PGF images as links. By default, the
+pgf images is included with a simple \input{file.pgf} command,
+but the user might want to redefine this behaviour, if the pgf
+file is stored in a subdirectory, and it references external
+image files, as is the case when saving to PGF format from
+matplotlib. The user can then specify a LaTeX command that takes
+care of providing the correct search path for the external
+dependencies, by redefining \pgfimage suitably."
+  :group 'org-export-latex
+  :type 'function)
 (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}"
   "Format string for links with unknown path type."
   :group 'org-export-latex
@@ -2300,12 +2313,12 @@ used as a communication channel."
     (if (member filetype '("tikz" "pgf"))
        ;; For tikz images:
-       ;; - use \input to read in image file.
+       ;; - use \input (default, can be overridden) to read in image file.
        ;; - if options are present, wrap in a tikzpicture environment.
        ;; - if width or height are present, use \resizebox to change
        ;;   the image size.
-         (setq image-code (format "\\input{%s}" path))
+         (setq image-code (funcall org-latex-inline-pgf-command path))
          (when (org-string-nw-p options)
            (setq image-code
                  (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
2.7.4 (Apple Git-66)

Reply via email to