emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Added possibility of overriding PGF inclusion command
@ 2016-07-17 13:35 Stefanos Carlström
  2016-07-30 19:57 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Stefanos Carlström @ 2016-07-17 13:35 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Stefanos Carlström

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

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

* Re: [PATCH] Added possibility of overriding PGF inclusion command
  2016-07-17 13:35 [PATCH] Added possibility of overriding PGF inclusion command Stefanos Carlström
@ 2016-07-30 19:57 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2016-07-30 19:57 UTC (permalink / raw)
  To: Stefanos Carlström; +Cc: emacs-orgmode

Hello,

Stefanos Carlström <stefanos.carlstrom@gmail.com> writes:

> * 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

Thank you for your patch.

However, you can easily achieve the same using a filter, can't you?

If a function needs to be introduced, it would be better to factor out
the whole "tikz" and "pgf" handling, i.e.,

  (progn
    (setq image-code (format "\\input{%s}" path))
    (when (org-string-nw-p options)
      (setq image-code
            (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
                    options
                    image-code)))
    (when (or (org-string-nw-p width) (org-string-nw-p height))
      (setq image-code (format "\\resizebox{%s}{%s}{%s}"
                               (if (org-string-nw-p width) width "!")
                               (if (org-string-nw-p height) height "!")
                               image-code))))

and have a variable holding a function to handle this such extensions,
and doing the above as a default.

Anyway, that's just an idea and people more knowledgeable on the subject
may want to chime in.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2016-07-30 19:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-17 13:35 [PATCH] Added possibility of overriding PGF inclusion command Stefanos Carlström
2016-07-30 19:57 ` Nicolas Goaziou

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