emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Stefanos Carlström" <stefanos.carlstrom@gmail.com>
To: emacs-orgmode@gnu.org
Cc: "Stefanos Carlström" <stefanos.carlstrom@gmail.com>
Subject: [PATCH] Added possibility of overriding PGF inclusion command
Date: Sun, 17 Jul 2016 15:35:32 +0200	[thread overview]
Message-ID: <1468762532-44794-1-git-send-email-stefanos.carlstrom@gmail.com> (raw)

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

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
preamble:

\newcommand\inputpgf[2]{{
    \let\pgfimageWithoutPath\pgfimage
    \renewcommand{\pgfimage}[2][]{\pgfimageWithoutPath[##1]{#1/##2}}
    \input{#1/#2}
  }}

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

TINYCHANGE
---
 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."
 	 image-code)
     (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.
 	(progn
-	  (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	other threads:[~2016-07-17 13:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-17 13:35 Stefanos Carlström [this message]
2016-07-30 19:57 ` [PATCH] Added possibility of overriding PGF inclusion command Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468762532-44794-1-git-send-email-stefanos.carlstrom@gmail.com \
    --to=stefanos.carlstrom@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).