emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Centering graphics in LaTeX export
@ 2014-05-15 15:25 Francesco Pizzolante
  2014-05-15 15:28 ` John Hendy
  2014-05-16  8:51 ` Nicolas Goaziou
  0 siblings, 2 replies; 3+ messages in thread
From: Francesco Pizzolante @ 2014-05-15 15:25 UTC (permalink / raw)
  To: mailing-list-org-mode

Hi,

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?

Thanks.

Best regards,
 Francesco Pizzolante


--- C:\Users\fpz\Documents\home\.emacs.d\elpa\org-plus-contrib-20140512\ox-latex.el	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"
 						   "\\includesvg"
 						   image-code
 						   nil t))
 	(setq image-code (replace-regexp-in-string "\\.svg}"

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

end of thread, other threads:[~2014-05-16  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-15 15:25 Centering graphics in LaTeX export Francesco Pizzolante
2014-05-15 15:28 ` John Hendy
2014-05-16  8:51 ` 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).