* 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
* Re: Centering graphics in LaTeX export
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
1 sibling, 0 replies; 3+ messages in thread
From: John Hendy @ 2014-05-15 15:28 UTC (permalink / raw)
To: Francesco Pizzolante; +Cc: mailing-list-org-mode
On Thu, May 15, 2014 at 10:25 AM, Francesco Pizzolante
<fpz@missioncriticalit.com> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Centering graphics in LaTeX export
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
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2014-05-16 8:51 UTC (permalink / raw)
To: Francesco Pizzolante; +Cc: mailing-list-org-mode
Hello,
"Francesco Pizzolante"
<fpz-djc/iPCCuDYQheJpep6IedvLeJWuRmrY@public.gmane.org> 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
^ 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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.