emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [ox-latex] Bad default value for image width?
@ 2013-04-07 20:17 Rasmus
  2013-04-07 20:38 ` Rasmus Pank Roulund
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Rasmus @ 2013-04-07 20:17 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I don't like that tikz figures are wrapped in a resize box.  In
particular this plain example is wrapped in a resize box:

#+BEGIN_SRC Org
* tikz test 

[[file:test.tikz]]

#+ATTR_LATEX: :width ""
[[file:test.tikz]]
#+END_SRC

Produces:
#+BEGIN_SRC latex
[...]
\resizebox{.9\linewidth}{!}{\input{test.tikz}}
[...]
#+END_SRC

Default behavior should be to not wrap it in a resize box as most tikz
users will set the width appropriately in their code.  The reason is
the variable org-latex-image-default-width which is .9\linewidth by
default.  And I can't seem to set width to nothing. . .  The problem
is that resize box insertion depends on the following test

#+BEGINS_SRC emacs-lisp
 (when (or (org-string-nw-p width) (org-string-nw-p height))
   ...)
#+END_SRC

which is always true due to the default meaning that I can't escape
the resize box. . . 

Potential resolutions:
  1. change the default of org-latex-image-default-width
  2. allow for a non-width (:width nil)
  3. make a better test for the resize box.

Let me know and I might be able to look into it. 

–Rasmus

-- 
A clever person solves a problem. A wise person avoids it

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-07 20:17 [ox-latex] Bad default value for image width? Rasmus
@ 2013-04-07 20:38 ` Rasmus Pank Roulund
  2013-04-08 19:35 ` Bastien
  2013-04-09 22:02 ` Nicolas Goaziou
  2 siblings, 0 replies; 11+ messages in thread
From: Rasmus Pank Roulund @ 2013-04-07 20:38 UTC (permalink / raw)
  To: emacs-orgmode


In general this auto width code seems super annoying.  Consider this 

From ox-latex.el:
#+BEGIN_SRC emacs-lisp
 (width (cond ((plist-get attr :width))
	      ((plist-get attr :height) "")
	      ((eq float 'figure) "0.7\\textwidth")
	      ((eq float 'wrap) "0.48\\textwidth")
	      (t org-latex-image-default-width)))
#+END_SRC

Consider the following example: 

#+BEGIN_SRC org

#+BEGIN_SRC emacs-lisp
(make-local-variable 'org-latex-image-default-width)
(setq org-latex-image-default-width "")
#+END_SRC

#+NAME:firm-ts-fig
#+CAPTION: test
[[file:figs/test.tikz]]

no caption
[[file:figs/test.tikz]]

#+END_SRC

This exports as:

#+BEGIN_SRC LATEX
\begin{figure}[htb]
\centering
\resizebox{0.7\textwidth}{!}{\input{figs/test.tikz}}
\caption{\label{firm-ts-fig}test}
\end{figure}

no caption
\input{figs/test.tikz}
#+END_SRC

To me it is not intuitive why a certain width is imposed on me because
I add a caption. . .

Could we consider removing:

#+BEGIN_SRC emacs-lisp
 ((eq float 'figure) "0.7\\textwidth")
 ((eq float 'wrap) "0.48\\textwidth")
#+END_SRC

and maybe changing the default value of org-latex-image-default-width
to something non-intruding? 

-- 
Powered by magic pixies!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-07 20:17 [ox-latex] Bad default value for image width? Rasmus
  2013-04-07 20:38 ` Rasmus Pank Roulund
@ 2013-04-08 19:35 ` Bastien
  2013-04-09 21:08   ` Nicolas Goaziou
  2013-04-09 22:02 ` Nicolas Goaziou
  2 siblings, 1 reply; 11+ messages in thread
From: Bastien @ 2013-04-08 19:35 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 364 bytes --]

Hi Rasmus,

Rasmus <rasmus@gmx.us> writes:

> And I can't seem to set width to nothing. . .  

The attached patch should fix at least one problem: you should be
able to set the width manually now.

As for the default value of `org-latex-image-default-width' I tend
to agree, but maybe there are side-effects when setting this to nil.

Nicolas, what do you think?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ox-latex-tikz-width.patch --]
[-- Type: text/x-patch, Size: 599 bytes --]

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9c04695..b7ed687 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1812,7 +1812,7 @@ used as a communication channel."
 	 (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 (cond ((plist-get attr :width))
+	 (width (cond ((plist-get attr :width) (plist-get attr :width))
 		      ((plist-get attr :height) "")
 		      ((eq float 'figure) "0.7\\textwidth")
 		      ((eq float 'wrap) "0.48\\textwidth")

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-08 19:35 ` Bastien
@ 2013-04-09 21:08   ` Nicolas Goaziou
  2013-04-09 21:30     ` Bastien
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-09 21:08 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

Hello,

Bastien <bzg@gnu.org> writes:

> Rasmus <rasmus@gmx.us> writes:
>
>> And I can't seem to set width to nothing. . .  
>
> The attached patch should fix at least one problem: you should be
> able to set the width manually now.
>
> As for the default value of `org-latex-image-default-width' I tend
> to agree, but maybe there are side-effects when setting this to nil.
>
> Nicolas, what do you think?

`org-latex-image-default-width' has a good default value because it will
make sure that all images fit on the page, no matter their size.

I personally set it to "", but I wouldn't recommend it as a default
value.

As for the patch, I doubt it has any impact, since (cond ((a))) is
equivalent to (cond ((a a))).


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-09 21:08   ` Nicolas Goaziou
@ 2013-04-09 21:30     ` Bastien
  0 siblings, 0 replies; 11+ messages in thread
From: Bastien @ 2013-04-09 21:30 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> `org-latex-image-default-width' has a good default value because it will
> make sure that all images fit on the page, no matter their size.
>
> I personally set it to "", but I wouldn't recommend it as a default
> value.
>
> As for the patch, I doubt it has any impact, since (cond ((a))) is
> equivalent to (cond ((a a))).

Do you have any answer for the OP question?

-- 
 Bastien

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-07 20:17 [ox-latex] Bad default value for image width? Rasmus
  2013-04-07 20:38 ` Rasmus Pank Roulund
  2013-04-08 19:35 ` Bastien
@ 2013-04-09 22:02 ` Nicolas Goaziou
  2013-04-10 11:52   ` Rasmus
  2 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-09 22:02 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> I don't like that tikz figures are wrapped in a resize box.  

Set `org-latex-image-default-width' to "".

> In particular this plain example is wrapped in a resize box:
>
> #+BEGIN_SRC Org
> * tikz test 
>
> [[file:test.tikz]]
>
> #+ATTR_LATEX: :width ""
> [[file:test.tikz]]
> #+END_SRC
>
> Produces:
> #+BEGIN_SRC latex
> [...]
> \resizebox{.9\linewidth}{!}{\input{test.tikz}}
> [...]
> #+END_SRC
>
> Default behavior should be to not wrap it in a resize box as most tikz
> users will set the width appropriately in their code.  The reason is
> the variable org-latex-image-default-width which is .9\linewidth by
> default.  And I can't seem to set width to nothing. . .  The problem
> is that resize box insertion depends on the following test
>
> #+BEGINS_SRC emacs-lisp
>  (when (or (org-string-nw-p width) (org-string-nw-p height))
>    ...)
> #+END_SRC
>
> which is always true due to the default

That's not correct. It is always true because (:width "") means width
becomes "\"\"", not "". IOW, `org-export-read-attribute' is unable to
parse a real empty string.

> meaning that I can't escape the resize box. . .
>
> Potential resolutions:
>   1. change the default of org-latex-image-default-width

This wouldn't help to solve the general problem. Though, you can change
it in your config to something else, as suggested above.

>   2. allow for a non-width (:width nil)
>   3. make a better test for the resize box.
>
> Let me know and I might be able to look into it.

I think the correct solution would be to fix `org-export-read-attribute'
so it can read empty strings.

If "" is really read as "", """" will still be read as "\"\"\"\"", and
it will not be possible to obtain "\"\"".

Another possibility is to read the empty string as the empty string
instead of nil, that is

  #+attr_latex: :prop1 :prop2 1

becomes (:prop1 "" :prop2 "1") instead of (:prop1 nil :prop2 "1"). It
may be confusing, though.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-09 22:02 ` Nicolas Goaziou
@ 2013-04-10 11:52   ` Rasmus
  2013-04-10 16:53     ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Rasmus @ 2013-04-10 11:52 UTC (permalink / raw)
  To: n.goaziou; +Cc: emacs-orgmode

Nicolas,

>> I don't like that tikz figures are wrapped in a resize box.  
>
> Set `org-latex-image-default-width' to "".

But as my second email shows this still doesn't work with
captions. . .

This exmample:

#+BEGIN_SRC org
#+BEGIN_SRC emacs-lisp
(make-local-variable 'org-latex-image-default-width)
(setq org-latex-image-default-width "")
#+END_SRC

#+NAME:firm-ts-fig
#+CAPTION: test
[[file:figs/test.tikz]]

no caption
[[file:figs/test.tikz]]
#+END_SRC

> That's not correct. It is always true because (:width "") means width
> becomes "\"\"", not "". IOW, `org-export-read-attribute' is unable to
> parse a real empty string.

I see. 

> This wouldn't help to solve the general problem. Though, you can change
> it in your config to something else, as suggested above.

I have.  But I don't think it's a sensible default.  It's against what
your usual stand of Org not trying to be too clever.  You would also
not put tables in resize boxes to make them "fit" on the page.


Here's another example where the default causes a non-sensible
behavior.

#+BEGIN_SRC org
#+BEGIN_SRC emacs-lisp :exports none
(url-copy-file "http://orgmode.org/img/org-mode-unicorn-logo.png" "logo.png")
#+END_SRC

* My raster picture

This is a low res. picture with the right size^{TM}

[[file:logo.png]]
#+END_SRC


>>   2. allow for a non-width (:width nil)
>>   3. make a better test for the resize box.
>>
>> Let me know and I might be able to look into it.



> I think the correct solution would be to fix `org-export-read-attribute'
> so it can read empty strings.

I think this is the solution to a general problem.  But I still find
the default width to be wrong.  It only works as intended when I have
a slightly too large picture.  And then, if anything, I'd want full
page width.  

It's a bad default for
  - Picture smaller than textwidth
  - Picture crafted to the document which shouldn't have a width.

It's a decent solution for 
  - pictures which are unintentionally larger than textwidth.  But IMO
    it's my responsibility, and not Org's, to fix these
    images/situations.


In usually exhibit good judgment of these matters, so I'll take your
word for it.  But I fail to see its usefulness as a default.

> If "" is really read as "", """" will still be read as "\"\"\"\"", and
> it will not be possible to obtain "\"\"".

Fine with me. 

> Another possibility is to read the empty string as the empty string
> instead of nil, that is
>
>   #+attr_latex: :prop1 :prop2 1

I like the "" better.  It works better with my "intuitive logic".


–Rasmus


-- 
Hvor meget poesi tror De kommer ud af et glas isvand?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-10 11:52   ` Rasmus
@ 2013-04-10 16:53     ` Nicolas Goaziou
  2013-04-10 17:23       ` Rasmus
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-10 16:53 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

>> Set `org-latex-image-default-width' to "".
>
> But as my second email shows this still doesn't work with
> captions. . .
>
> This exmample:
>
> #+BEGIN_SRC org
> #+BEGIN_SRC emacs-lisp
> (make-local-variable 'org-latex-image-default-width)
> (setq org-latex-image-default-width "")
> #+END_SRC
>
> #+NAME:firm-ts-fig
> #+CAPTION: test
> [[file:figs/test.tikz]]
>
> no caption
> [[file:figs/test.tikz]]
> #+END_SRC

The problem is different here. More on this below.

>> This wouldn't help to solve the general problem. Though, you can change
>> it in your config to something else, as suggested above.
>
> I have.  But I don't think it's a sensible default.  It's against what
> your usual stand of Org not trying to be too clever.  You would also
> not put tables in resize boxes to make them "fit" on the page.

This is different. You always build tables from LaTeX so they are, in
a way, normalized. On the other hand, images can be imported from
various sources, with different sizes and resolutions.

> I think this is the solution to a general problem.  But I still find
> the default width to be wrong.  It only works as intended when I have
> a slightly too large picture.  And then, if anything, I'd want full
> page width.  
>
> It's a bad default for
>   - Picture smaller than textwidth
>   - Picture crafted to the document which shouldn't have a width.
>
> It's a decent solution for 
>   - pictures which are unintentionally larger than textwidth.  But IMO
>     it's my responsibility, and not Org's, to fix these
>     images/situations.

Exactly.

I'm not selling you the default value as the perfect solution: it isn't,
obviously. I even agree that in most situations, no default value is
better.

However, in my experience, the worst situation is the image (much)
larger than textwidth, which makes it difficult to even read the
produced document. It isn't as bad for enlarged small pictures.

So, the current default is good to control the worst case. And since
there is no decent solution in all situations, it makes sense here.
I think the same applies to default wrap width (.48\textwidth), which
ensures that the display will be coherent.

Now, the ".7\textwidth" for floats is harder to explain. I don't feel
very strong about it, and I don't mind removing it (meaning
`org-latex-image-default-width' would also apply
 to floats).

>> If "" is really read as "", """" will still be read as "\"\"\"\"", and
>> it will not be possible to obtain "\"\"".
>
> Fine with me. 
>
>> Another possibility is to read the empty string as the empty string
>> instead of nil, that is
>>
>>   #+attr_latex: :prop1 :prop2 1
>
> I like the "" better.  It works better with my "intuitive logic".

I have pushed a patch which should fix your initial problem about :width
"" not being taken into account.  Could you confirm the new behaviour
works as expected?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-10 16:53     ` Nicolas Goaziou
@ 2013-04-10 17:23       ` Rasmus
  2013-04-10 20:13         ` Nicolas Goaziou
  0 siblings, 1 reply; 11+ messages in thread
From: Rasmus @ 2013-04-10 17:23 UTC (permalink / raw)
  To: emacs-orgmode


Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

>> It's a bad default for
>>   - Picture smaller than textwidth
>>   - Picture crafted to the document which shouldn't have a width.
>>
>> It's a decent solution for 
>>   - pictures which are unintentionally larger than textwidth.  But IMO
>>     it's my responsibility, and not Org's, to fix these
>>     images/situations.
>
> Exactly.
>
> I'm not selling you the default value as the perfect solution: it isn't,
> obviously. I even agree that in most situations, no default value is
> better.

Agree.

> However, in my experience, the worst situation is the image (much)
> larger than textwidth, which makes it difficult to even read the
> produced document. It isn't as bad for enlarged small pictures.

Perhaps.  I'm not convinced.  If the float width is removed I can
change the default and never be affected by these design choices and
it's all good.

> Now, the ".7\textwidth" for floats is harder to explain. I don't feel
> very strong about it, and I don't mind removing it (meaning
> `org-latex-image-default-width' would also apply
>  to floats).

Using org-latex-image-default-width is more reasonable IMO.  Then at
least there won't be any 'nasty' surprises when adding caption and for
me I can set the default width to "" and be done with it.

For people who use it it might also be reasonable to introduce a
org-latex-wrap-image-default-width or making
org-latex-image-default-width a list ordered by type of element/float
type.

E.g. '((float . ".9\\textwidth") (wrap . ".5\\textwidth")). . . 

>> I like the "" better.  It works better with my "intuitive logic".
>
> I have pushed a patch which should fix your initial problem about :width
> "" not being taken into account.  Could you confirm the new behaviour
> works as expected?

I'll check it out and report back.  I can't access git from this
network (high port numbers are blocked for "security" reasons) so I'll
only try it out later.

Thanks,
Rasmus.

-- 
Hooray!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-10 17:23       ` Rasmus
@ 2013-04-10 20:13         ` Nicolas Goaziou
  2013-04-11 15:36           ` Bastien
  0 siblings, 1 reply; 11+ messages in thread
From: Nicolas Goaziou @ 2013-04-10 20:13 UTC (permalink / raw)
  To: Rasmus; +Cc: Bastien Guerry, emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Perhaps.  I'm not convinced.

Since I didn't introduce this feature in new exporter (it was already in
the previous one), it may be interesting to know the motivation of the
person who originally introduced it. I think it was Bastien (Cc'ed).

> If the float width is removed I can change the default and never be
> affected by these design choices and it's all good.

Done.

> For people who use it it might also be reasonable to introduce
> a org-latex-wrap-image-default-width or making
> org-latex-image-default-width a list ordered by type of element/float
> type.
>
> E.g. '((float . ".9\\textwidth") (wrap . ".5\\textwidth")). . . 

I'm not sure we need to go that far.

> I'll check it out and report back.  I can't access git from this
> network (high port numbers are blocked for "security" reasons) so I'll
> only try it out later.

Thank you.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [ox-latex] Bad default value for image width?
  2013-04-10 20:13         ` Nicolas Goaziou
@ 2013-04-11 15:36           ` Bastien
  0 siblings, 0 replies; 11+ messages in thread
From: Bastien @ 2013-04-11 15:36 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Rasmus <rasmus@gmx.us> writes:
>
>> Perhaps.  I'm not convinced.
>
> Since I didn't introduce this feature in new exporter (it was already in
> the previous one), it may be interesting to know the motivation of the
> person who originally introduced it. I think it was Bastien (Cc'ed).

The same than the one you expressed: make sure images fit the page.
I don't there was a way to set the width attribute per image at the
time.

>> For people who use it it might also be reasonable to introduce
>> a org-latex-wrap-image-default-width or making
>> org-latex-image-default-width a list ordered by type of element/float
>> type.
>>
>> E.g. '((float . ".9\\textwidth") (wrap . ".5\\textwidth")). . . 
>
> I'm not sure we need to go that far.

Not sure either, a bit too much for sure.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-04-11 15:36 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-07 20:17 [ox-latex] Bad default value for image width? Rasmus
2013-04-07 20:38 ` Rasmus Pank Roulund
2013-04-08 19:35 ` Bastien
2013-04-09 21:08   ` Nicolas Goaziou
2013-04-09 21:30     ` Bastien
2013-04-09 22:02 ` Nicolas Goaziou
2013-04-10 11:52   ` Rasmus
2013-04-10 16:53     ` Nicolas Goaziou
2013-04-10 17:23       ` Rasmus
2013-04-10 20:13         ` Nicolas Goaziou
2013-04-11 15:36           ` Bastien

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).