[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Centering graphics in LaTeX export

From: Francesco Pizzolante
Subject: [O] Centering graphics in LaTeX export
Date: Thu, 15 May 2014 17:25:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt)


Here's a small patch that enables centering graphics in LaTeX exports
(as it already exists for tables).

Currently, the only way to center images is by adding a caption (which
is not always needed) or by adding #+begin_center / #+end_center around
images (but it must be done for every image as we cannot define
a default behavior for centering images).

Thanks to this patch:

- an image can be centered by adding the ':center t' attribute in
  a '#+ATTR_LATEX' directive (as for tables);

- default centering of images can be achieved by setting the
  'org-latex-images-centered' variable to t.

Could you please apply this patch?


Best regards,
 Francesco Pizzolante

    2014-05-15 17:09:08.000000000 +0200
+++ C:\Users\fpz\Documents\home\.emacs.d\elpa\org-plus-contrib-20140505 - 
Copy\ox-latex.el      2014-05-15 17:11:25.000000000 +0200
@@ -401,12 +401,17 @@
   "Default option for images."
   :group 'org-export-latex
   :version "24.4"
   :package-version '(Org . "8.0")
   :type 'string)
+(defcustom org-latex-images-centered t
+  "When non-nil, images are exported in a center environment."
+  :group 'org-export-latex
+  :type 'boolean)
 (defcustom org-latex-image-default-width ".9\\linewidth"
   "Default width for images.
 This value will not be used if a height is provided."
   :group 'org-export-latex
   :version "24.4"
   :package-version '(Org . "8.0")
@@ -1710,12 +1715,15 @@
                  ((eq float 'figure)
                   (format "[%s]" org-latex-default-figure-position))
                  (t ""))))
         (comment-include (if (plist-get attr :comment-include) "%" ""))
         ;; It is possible to specify width and height in the
         ;; ATTR_LATEX line, and also via default variables.
+        (centerp (if (plist-member attr :center)
+                      (plist-get attr :center)
+                   org-latex-images-centered))
         (width (cond ((plist-get attr :width))
                      ((plist-get attr :height) "")
                      ((eq float 'wrap) "0.48\\textwidth")
                      (t org-latex-image-default-width)))
         (height (cond ((plist-get attr :height))
                       ((or (plist-get attr :width)
@@ -1749,18 +1757,21 @@
       ;; - include the image with \includegraphics.
       (when (org-string-nw-p width)
        (setq options (concat options ",width=" width)))
       (when (org-string-nw-p height)
        (setq options (concat options ",height=" height)))
       (setq image-code
-           (format "\\includegraphics%s{%s}"
+           (format "%s\\includegraphics%s{%s}%s"
+                    (if centerp "{\\centering\n" "")
                    (cond ((not (org-string-nw-p options)) "")
                          ((= (aref options 0) ?,)
                           (format "[%s]"(substring options 1)))
                          (t (format "[%s]" options)))
-                   path))
+                   path
+                    (if centerp "\\par}\n" "")
+                    ))
       (when (equal filetype "svg")
        (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
                                                   nil t))
        (setq image-code (replace-regexp-in-string "\\.svg}"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]