Re: [O] Centering graphics in LaTeX export

2014-05-16 Thread Nicolas Goaziou


Hello,

"Francesco Pizzolante"
 writes:

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

Thanks for this. A few, minor, comments follow.

> +(defcustom org-latex-images-centered t
> +  "When non-nil, images are exported in a center environment."
> +  :group 'org-export-latex
> +  :type 'boolean)

You need to add

  :version "24.5"
  :package-version '(Org . "8.3")

since this is a new variable.

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

I suggest to move the CENTERP binding above the previous comments.

> + path
> +(if centerp "\\par}\n" "")
> +))

No parens alone on a line, please.

You also need to update manual and document the feature.

Eventually, could you provide a proper commit message and send an
updated patch?


Regards,

-- 
Nicolas Goaziou




Re: [O] Centering graphics in LaTeX export

2014-05-15 Thread John Hendy
On Thu, May 15, 2014 at 10:25 AM, Francesco Pizzolante
 wrote:
> 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.

Sounds cool to me! I'm already always using an #+attr_latex line for
setting the width; being able to center it with the same line would be
pretty cool. That said, I'm guessing someone's going to point you in
this direction for the patch submission itself (I guess that "someone"
is me in this case).
- http://orgmode.org/worg/org-contribute.html#sec-4

[patch snipped]


Best regards,
John



[O] Centering graphics in LaTeX export

2014-05-15 Thread Francesco Pizzolante
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.0 +0200
+++ C:\Users\fpz\Documents\home\.emacs.d\elpa\org-plus-contrib-20140505 - 
Copy\ox-latex.el  2014-05-15 17:11:25.0 +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}"