Re: [O] [PATCH] ox-latex: provide width and height options for images
Hello, aarone...@gmail.com writes: This should now be handled. The new patch will follow this email. In related news, I have completed the FSF copyright assignment process, so the patch can be merged whenever it is deemed ready. Your patch looks good. I have pushed it with minor stylistic changes. Also, could you send the confirmation of your assignment process from FSF to Bastien? Thank you for your work. Regards, -- Nicolas Goaziou
Re: [O] [PATCH] ox-latex: provide width and height options for images
2013ko otsailak 27an, Nicolas Goaziou-ek idatzi zuen: Thank you for your patch. Here are a few comments. Thank you for the comments! I think the patch is simpler and better thanks to them. 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. I tend to agree with Rasmus. It would be better to keep height and width options in \includegraphics when possible. Okay. 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. We don't need this precaution. The exporter code for 8.0 introduced many incompatibilities already. Also, this one is easy to discover. Okay. I think it's a good step forward. It will need to be documented in the comments at the beginning of ox-latex.el, where all attributes properties relative to different syntactical elements are explained. Okay – see what you think of the documentation in the new patch. Here, you can obtain \resizebox{!}{!}{%s}, which is wrong, isn't it? No...it is a no-op. That said, the code should no longer do this. This needs to be changed as these options would interfere with :width argument. For example, (eq float 'float) could set :width property if it is undefined. Obviously, this means the check has to be done before WIDTH and HEIGHT strings are built. This should now be handled. The new patch will follow this email. In related news, I have completed the FSF copyright assignment process, so the patch can be merged whenever it is deemed ready. Thanks again, -- Aaron Ecay
Re: [O] [PATCH] ox-latex: provide width and height options for images
Hello, Aaron Ecay aarone...@gmail.com writes: Thank you for your patch. Here are a few comments. 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. I tend to agree with Rasmus. It would be better to keep height and width options in \includegraphics when possible. 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. We don't need this precaution. The exporter code for 8.0 introduced many incompatibilities already. Also, this one is easy to discover. +(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)) I'm not sure it's worth creating a new function for it. Anyway, the first line of a docstring should be a sentence on its own. (defcustom org-latex-image-default-option width=.9\\linewidth Default option for images. :group 'org-export-latex :type 'string) We can set it to . +(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) I think it's a good step forward. It will need to be documented in the comments at the beginning of ox-latex.el, where all attributes properties relative to different syntactical elements are explained. (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 !))) Here, you can obtain \resizebox{!}{!}{%s}, which is wrong, isn't it? ;; 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 This needs to be changed as these options would interfere with :width argument. For example, (eq float 'float) could set :width property if it is undefined. Obviously, this means the check has to be done before WIDTH and HEIGHT strings are built. - (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) See comments above. Thank you again, Regards, -- Nicolas Goaziou
Re: [O] [PATCH] ox-latex: provide width and height options for images
Rasmus writes: For tikz figures resizing should be done via the scale argument to preserve the right font sizes. If people want to resize a tikz figure they should do so in their tikz code. No, that doesn't work for many tikz pictures; in particular it doesn't work for tikz files produced by gnuplot. There are reams of threads on stackoverflow on this topic… Regards, Achim. -- +[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]+ Samples for the Waldorf Blofeld: http://Synth.Stromeko.net/Downloads.html#BlofeldSamplesExtra
[O] [PATCH] ox-latex: provide width and height options for images
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
Re: [O] [PATCH] ox-latex: provide width and height options for images
Aaron Ecay aarone...@gmail.com writes: WDYT? [...] 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. I don't like it. Why would we use resizebox rather than the the arguments in includegraphics for pictures? From a TeXnish perspective it seems wrong and inelegant to me (totally subjective). For tikz figures resizing should be done via the scale argument to preserve the right font sizes. If people want to resize a tikz figure they should do so in their tikz code. That being said, better tikz handling in Org is a wonderful idea. –Rasmus -- Need more coffee. . .
Re: [O] [PATCH] ox-latex: provide width and height options for images
2013ko otsailak 26an, Rasmus-ek idatzi zuen: I don't like it. Why would we use resizebox rather than the the arguments in includegraphics for pictures? Because it achieves the same result, but allows the operation to be more uniform from the org side of things. A \resizebox is something that org can stuff any image into and have it be resized, so org doesn’t have to deal with the different ways of resizing things. One thing that might be suspected is that passing the width and height to \includegraphics would allow it to scale down an image that is included at less than 100% size, shrinking the resultant pdf. But this is not what happens (at least for jpg images), in my testing. For tikz figures resizing should be done via the scale argument to preserve the right font sizes. If people want to resize a tikz figure they should do so in their tikz code. There’s two ways of resizing tikz images: rescaling the distances between things and leaving the text alone, or resizing the whole image including the text. This supports the latter. Achim’s suggestion about nested tikzpicture environments (which I intend to implement) takes care of the former. -- Aaron Ecay