summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-07-25 23:22:01 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-07-25 23:31:25 +0200
commit096f4287a60d04470e0a71ea988816d1c3071ccc (patch)
tree94a5ab7a4d7f208f7d6c77a15b84eb9144953da3
parent67c29aa1e8b1ffd4dcfb0d86822e42a8139cf203 (diff)
downloadorg-mode-096f4287a60d04470e0a71ea988816d1c3071ccc.tar.gz
ox-latex: Allow toggling centering of images
* lisp/ox-latex.el (latex): Introduce new property :latex-images-centered. (org-latex-images-centered): New variable. (org-latex--inline-image): Handle new attribute :center, in addition to variable above. * doc/org.texi (Images in @LaTeX{} export): Document new behaviour (Publishing options): Reference :latex-images-centered.
-rw-r--r--doc/org.texi14
-rw-r--r--etc/ORG-NEWS5
-rw-r--r--lisp/ox-latex.el82
3 files changed, 66 insertions, 35 deletions
diff --git a/doc/org.texi b/doc/org.texi
index 1c3868c..3350ce0 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -12217,8 +12217,17 @@ To modify the placement option of any floating environment, set the
[[./img/hst.png]]
@end example
-If the @code{:comment-include} attribute is set to a non-@code{nil} value,
-the @LaTeX{} @code{\includegraphics} macro will be commented out.
+@vindex org-latex-images-centered
+@cindex center image (@LaTeX{} export)
+@cindex image, centering (@LaTeX{} export)
+Images are centered by default. However, one can disable this behavior by
+setting @code{:center} attribute to @code{nil}. To prevent any image from
+being centered throughout a document, set @code{org-latex-images-centered}
+instead.
+
+Eventually, if the @code{:comment-include} attribute is set to
+a non-@code{nil} value, the @LaTeX{} @code{\includegraphics} macro will be
+commented out.
@node Plain lists in @LaTeX{} export
@subsection Plain lists in @LaTeX{} export
@@ -14419,6 +14428,7 @@ however, override everything.
@item @code{:latex-image-default-height} @tab @code{org-latex-image-default-height}
@item @code{:latex-image-default-option} @tab @code{org-latex-image-default-option}
@item @code{:latex-image-default-width} @tab @code{org-latex-image-default-width}
+@item @code{:latex-images-centered} @tab @code{org-latex-images-centered}
@item @code{:latex-inactive-timestamp-format} @tab @code{org-latex-inactive-timestamp-format}
@item @code{:latex-inline-image-rules} @tab @code{org-latex-inline-image-rules}
@item @code{:latex-link-with-unknown-path-format} @tab @code{org-latex-link-with-unknown-path-format}
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2535a09..391e282 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -204,7 +204,10 @@ point for the SRC/EXAMPLE block.
(message "This is line 32")
,#+END_SRC
#+END_SRC
-
+**** Allow toggling center for images in LaTeX export
+With the global variable ~org-latex-images-centered~ or the local
+attribute ~:center~ it is now possible to center an image in LaTeX
+export.
*** Babel
**** Support for SLY in Lisp blocks
See ~org-babel-lisp-eval-fn~ to activate it.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 1a303a0..01bc8dd 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -127,6 +127,7 @@
(:latex-image-default-height nil nil org-latex-image-default-height)
(:latex-image-default-option nil nil org-latex-image-default-option)
(:latex-image-default-width nil nil org-latex-image-default-width)
+ (:latex-images-centered nil nil org-latex-images-centered)
(:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules)
(:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
@@ -681,6 +682,14 @@ The function result will be used in the section format string."
;;;; Links
+(defcustom org-latex-images-centered t
+ "When non-nil, images are centered."
+ :group 'org-export-latex
+ :version "25.1"
+ :package-version '(Org . "9.0")
+ :type 'boolean
+ :safe #'booleanp)
+
(defcustom org-latex-image-default-option ""
"Default option for images."
:group 'org-export-latex
@@ -2269,13 +2278,12 @@ used as a communication channel."
(cond ((string= float "wrap") 'wrap)
((string= float "sideways") 'sideways)
((string= float "multicolumn") 'multicolumn)
+ ((and (plist-member attr :float) (not float)) 'nonfloat)
((or float
(org-element-property :caption parent)
(org-string-nw-p (plist-get attr :caption)))
- (if (and (plist-member attr :float) (not float))
- 'nonfloat
- 'figure))
- ((and (not float) (plist-member attr :float)) nil))))
+ 'figure)
+ (t 'nonfloat))))
(placement
(let ((place (plist-get attr :placement)))
(cond
@@ -2284,6 +2292,9 @@ used as a communication channel."
((eq float 'figure)
(format "[%s]" (plist-get info :latex-default-figure-position)))
(t ""))))
+ (center
+ (if (plist-member attr :center) (plist-get attr :center)
+ (plist-get info :latex-images-centered)))
(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.
@@ -2334,8 +2345,8 @@ used as a communication channel."
(setq image-code
(format "\\includegraphics%s{%s}"
(cond ((not (org-string-nw-p options)) "")
- ((= (aref options 0) ?,)
- (format "[%s]"(substring options 1)))
+ ((string-prefix-p "," options)
+ (format "[%s]" (substring options 1)))
(t (format "[%s]" options)))
path))
(when (equal filetype "svg")
@@ -2348,46 +2359,53 @@ used as a communication channel."
image-code
nil t))))
;; Return proper string, depending on FLOAT.
- (cl-case float
- (wrap (format "\\begin{wrapfigure}%s
-%s\\centering
+ (pcase float
+ (`wrap (format "\\begin{wrapfigure}%s
+%s%s
%s%s
%s\\end{wrapfigure}"
- placement
- (if caption-above-p caption "")
- comment-include image-code
- (if caption-above-p "" caption)))
- (sideways (format "\\begin{sidewaysfigure}
-%s\\centering
+ placement
+ (if caption-above-p caption "")
+ (if center "\\centering" "")
+ comment-include image-code
+ (if caption-above-p "" caption)))
+ (`sideways (format "\\begin{sidewaysfigure}
+%s%s
%s%s
%s\\end{sidewaysfigure}"
- (if caption-above-p caption "")
- comment-include image-code
- (if caption-above-p "" caption)))
- (multicolumn (format "\\begin{figure*}%s
-%s\\centering
+ (if caption-above-p caption "")
+ (if center "\\centering" "")
+ comment-include image-code
+ (if caption-above-p "" caption)))
+ (`multicolumn (format "\\begin{figure*}%s
+%s%s
%s%s
%s\\end{figure*}"
- placement
- (if caption-above-p caption "")
- comment-include image-code
- (if caption-above-p "" caption)))
- (figure (format "\\begin{figure}%s
-%s\\centering
+ placement
+ (if caption-above-p caption "")
+ (if center "\\centering" "")
+ comment-include image-code
+ (if caption-above-p "" caption)))
+ (`figure (format "\\begin{figure}%s
+%s%s
%s%s
%s\\end{figure}"
- placement
- (if caption-above-p caption "")
- comment-include image-code
- (if caption-above-p "" caption)))
- (nonfloat
+ placement
+ (if caption-above-p caption "")
+ (if center "\\centering" "")
+ comment-include image-code
+ (if caption-above-p "" caption)))
+ ((guard center)
(format "\\begin{center}
%s%s
%s\\end{center}"
(if caption-above-p caption "")
image-code
(if caption-above-p "" caption)))
- (otherwise image-code))))
+ (_
+ (concat (if caption-above-p caption "")
+ image-code
+ (if caption-above-p caption ""))))))
(defun org-latex-link (link desc info)
"Transcode a LINK object from Org to LaTeX.