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.
This commit is contained in:
Nicolas Goaziou 2016-07-25 23:22:01 +02:00
parent 67c29aa1e8
commit 096f4287a6
3 changed files with 66 additions and 35 deletions

View File

@ -12217,8 +12217,17 @@ To modify the placement option of any floating environment, set the
[[./img/hst.png]] [[./img/hst.png]]
@end example @end example
If the @code{:comment-include} attribute is set to a non-@code{nil} value, @vindex org-latex-images-centered
the @LaTeX{} @code{\includegraphics} macro will be commented out. @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 @node Plain lists in @LaTeX{} export
@subsection 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-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-option} @tab @code{org-latex-image-default-option}
@item @code{:latex-image-default-width} @tab @code{org-latex-image-default-width} @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-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-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} @item @code{:latex-link-with-unknown-path-format} @tab @code{org-latex-link-with-unknown-path-format}

View File

@ -204,7 +204,10 @@ point for the SRC/EXAMPLE block.
(message "This is line 32") (message "This is line 32")
,#+END_SRC ,#+END_SRC
#+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 *** Babel
**** Support for SLY in Lisp blocks **** Support for SLY in Lisp blocks
See ~org-babel-lisp-eval-fn~ to activate it. See ~org-babel-lisp-eval-fn~ to activate it.

View File

@ -127,6 +127,7 @@
(:latex-image-default-height nil nil org-latex-image-default-height) (: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-option nil nil org-latex-image-default-option)
(:latex-image-default-width nil nil org-latex-image-default-width) (: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-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
(:latex-inline-image-rules nil nil org-latex-inline-image-rules) (: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) (: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 ;;;; 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 "" (defcustom org-latex-image-default-option ""
"Default option for images." "Default option for images."
:group 'org-export-latex :group 'org-export-latex
@ -2269,13 +2278,12 @@ used as a communication channel."
(cond ((string= float "wrap") 'wrap) (cond ((string= float "wrap") 'wrap)
((string= float "sideways") 'sideways) ((string= float "sideways") 'sideways)
((string= float "multicolumn") 'multicolumn) ((string= float "multicolumn") 'multicolumn)
((and (plist-member attr :float) (not float)) 'nonfloat)
((or float ((or float
(org-element-property :caption parent) (org-element-property :caption parent)
(org-string-nw-p (plist-get attr :caption))) (org-string-nw-p (plist-get attr :caption)))
(if (and (plist-member attr :float) (not float)) 'figure)
'nonfloat (t 'nonfloat))))
'figure))
((and (not float) (plist-member attr :float)) nil))))
(placement (placement
(let ((place (plist-get attr :placement))) (let ((place (plist-get attr :placement)))
(cond (cond
@ -2284,6 +2292,9 @@ used as a communication channel."
((eq float 'figure) ((eq float 'figure)
(format "[%s]" (plist-get info :latex-default-figure-position))) (format "[%s]" (plist-get info :latex-default-figure-position)))
(t "")))) (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) "%" "")) (comment-include (if (plist-get attr :comment-include) "%" ""))
;; It is possible to specify width and height in the ;; It is possible to specify width and height in the
;; ATTR_LATEX line, and also via default variables. ;; ATTR_LATEX line, and also via default variables.
@ -2334,8 +2345,8 @@ used as a communication channel."
(setq image-code (setq image-code
(format "\\includegraphics%s{%s}" (format "\\includegraphics%s{%s}"
(cond ((not (org-string-nw-p options)) "") (cond ((not (org-string-nw-p options)) "")
((= (aref options 0) ?,) ((string-prefix-p "," options)
(format "[%s]"(substring options 1))) (format "[%s]" (substring options 1)))
(t (format "[%s]" options))) (t (format "[%s]" options)))
path)) path))
(when (equal filetype "svg") (when (equal filetype "svg")
@ -2348,46 +2359,53 @@ used as a communication channel."
image-code image-code
nil t)))) nil t))))
;; Return proper string, depending on FLOAT. ;; Return proper string, depending on FLOAT.
(cl-case float (pcase float
(wrap (format "\\begin{wrapfigure}%s (`wrap (format "\\begin{wrapfigure}%s
%s\\centering %s%s
%s%s %s%s
%s\\end{wrapfigure}" %s\\end{wrapfigure}"
placement placement
(if caption-above-p caption "") (if caption-above-p caption "")
comment-include image-code (if center "\\centering" "")
(if caption-above-p "" caption))) comment-include image-code
(sideways (format "\\begin{sidewaysfigure} (if caption-above-p "" caption)))
%s\\centering (`sideways (format "\\begin{sidewaysfigure}
%s%s
%s%s %s%s
%s\\end{sidewaysfigure}" %s\\end{sidewaysfigure}"
(if caption-above-p caption "") (if caption-above-p caption "")
comment-include image-code (if center "\\centering" "")
(if caption-above-p "" caption))) comment-include image-code
(multicolumn (format "\\begin{figure*}%s (if caption-above-p "" caption)))
%s\\centering (`multicolumn (format "\\begin{figure*}%s
%s%s
%s%s %s%s
%s\\end{figure*}" %s\\end{figure*}"
placement placement
(if caption-above-p caption "") (if caption-above-p caption "")
comment-include image-code (if center "\\centering" "")
(if caption-above-p "" caption))) comment-include image-code
(figure (format "\\begin{figure}%s (if caption-above-p "" caption)))
%s\\centering (`figure (format "\\begin{figure}%s
%s%s
%s%s %s%s
%s\\end{figure}" %s\\end{figure}"
placement placement
(if caption-above-p caption "") (if caption-above-p caption "")
comment-include image-code (if center "\\centering" "")
(if caption-above-p "" caption))) comment-include image-code
(nonfloat (if caption-above-p "" caption)))
((guard center)
(format "\\begin{center} (format "\\begin{center}
%s%s %s%s
%s\\end{center}" %s\\end{center}"
(if caption-above-p caption "") (if caption-above-p caption "")
image-code image-code
(if caption-above-p "" caption))) (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) (defun org-latex-link (link desc info)
"Transcode a LINK object from Org to LaTeX. "Transcode a LINK object from Org to LaTeX.