From: Aaron Ecay <aaronecay@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ox-latex: provide width and height options for images
Date: Tue, 26 Feb 2013 14:22:34 -0500 [thread overview]
Message-ID: <1361906554-26709-1-git-send-email-aaronecay@gmail.com> (raw)
In-Reply-To: <87obf63mq6.fsf@gmail.com>
These are implemented with \resizebox, and thus are uniform across
different types of image inclusion (\includegraphics, \input of tikz
images). This differs from the older way of using width and height
optional args to \includegraphics.
Thus, the default value for org-latex-image-default-options is left
untouched, to avoid breaking compatibility with older code. After a
transition period, the 0.9\linewidth value should be moved into
org-latex-image-default-width, and the -options variable set to the
empty string.
Also introduce a convenience function to org-macs.el.
---
lisp/org-macs.el | 7 +++++++
lisp/ox-latex.el | 29 ++++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 172d5d1..3fe62cd 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -87,6 +87,13 @@
Otherwise return nil."
(and v (not (equal v "nil")) v))
+(defun org-not-nil-or-empty (v)
+ "Return V if V is not nil, the string \"nil\", or a string
+consisting of solely whitespace. Otherwise return nil."
+ (and (org-not-nil v)
+ (org-string-nw-p v)
+ v))
+
(defun org-substitute-posix-classes (re)
"Substitute posix classes in regular expression RE."
(let ((ss re))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 13da3f0..d1f47b8 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -471,11 +471,24 @@ which format headlines like for Org version prior to 8.0."
;;;; Links
+;;; NOTE: this variable is for backwards compatibility; eventually the
+;;; width setting should be moved to the default-width variable, and
+;;; this set to the empty string.
(defcustom org-latex-image-default-option "width=.9\\linewidth"
"Default option for images."
:group 'org-export-latex
:type 'string)
+(defcustom org-latex-image-default-width ""
+ "Default option for images."
+ :group 'org-export-latex
+ :type 'string)
+
+(defcustom org-latex-image-default-height ""
+ "Default option for images."
+ :group 'org-export-latex
+ :type 'string)
+
(defcustom org-latex-default-figure-position "htb"
"Default position for latex figures."
:group 'org-export-latex
@@ -1755,6 +1768,15 @@ used as a communication channel."
(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.
+ (width (format "%s" (or (plist-get attr :width)
+ org-latex-image-default-width)))
+ (height (format "%s" (or (plist-get attr :height)
+ org-latex-image-default-height)))
+ (resize (format "\\resizebox{%s}{%s}{%%s}"
+ (if (org-not-nil-or-empty width) width "!")
+ (if (org-not-nil-or-empty height) height "!")))
;; Options for "includegraphics" macro. Make sure it is
;; a string with square brackets when non empty. Default to
;; `org-latex-image-default-option' when possible.
@@ -1766,9 +1788,10 @@ used as a communication channel."
((eq float 'float) "[width=0.7\\textwidth]")
((eq float 'wrap) "[width=0.48\\textwidth]")
(t ""))))
- (image-code (if (equal filetype "tikz")
- (format "\\input{%s}" path)
- (format "\\includegraphics%s{%s}" options path))))
+ (image-code (format resize
+ (if (equal filetype "tikz")
+ (format "\\input{%s}" path)
+ (format "\\includegraphics%s{%s}" options path)))))
;; Return proper string, depending on FLOAT.
(case float
(wrap (format "\\begin{wrapfigure}%s
--
1.8.1.4
next prev parent reply other threads:[~2013-02-26 19:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-24 18:51 [PATCH] ob-R.el, ox-latex.el: support for tikz graphics Aaron Ecay
2013-02-25 15:19 ` Nicolas Goaziou
2013-02-26 10:50 ` Achim Gratz
2013-02-26 12:25 ` Myles English
2013-02-26 13:21 ` Nicolas Goaziou
2013-02-26 14:33 ` Achim Gratz
2013-02-26 19:21 ` Aaron Ecay
2013-02-26 19:22 ` Aaron Ecay [this message]
2013-02-26 23:04 ` [PATCH] ox-latex: provide width and height options for images Rasmus
2013-02-27 2:02 ` Aaron Ecay
2013-02-27 18:40 ` Achim Gratz
2013-02-27 8:23 ` Nicolas Goaziou
2013-03-06 4:02 ` aaronecay
2013-03-06 4:04 ` [PATCH] ox-latex: Support tikz images, :width, and :height Aaron Ecay
2013-03-06 8:35 ` [PATCH] ox-latex: provide width and height options for images Nicolas Goaziou
2013-02-26 18:25 ` [PATCH] ob-R.el, ox-latex.el: support for tikz graphics Achim Gratz
2013-02-26 19:49 ` Aaron Ecay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1361906554-26709-1-git-send-email-aaronecay@gmail.com \
--to=aaronecay@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).