From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UBL7JD5iUGE7PgAAgWs5BA (envelope-from ) for ; Sun, 26 Sep 2021 14:06:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id MOGlID5iUGGoEgAAbx9fmQ (envelope-from ) for ; Sun, 26 Sep 2021 12:06:22 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id EB3CC2AC28 for ; Sun, 26 Sep 2021 14:06:21 +0200 (CEST) Received: from localhost ([::1]:45446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUSvD-0006X1-QK for larch@yhetil.org; Sun, 26 Sep 2021 08:06:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUSpr-0006Ql-IX for emacs-orgmode@gnu.org; Sun, 26 Sep 2021 08:00:49 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:38869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUSpp-00064w-Dh for emacs-orgmode@gnu.org; Sun, 26 Sep 2021 08:00:47 -0400 Received: by mail-pj1-x102c.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so13172523pjc.3 for ; Sun, 26 Sep 2021 05:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:user-agent:message-id:mime-version; bh=Zq+1AuHkLO3esC5dJh7ZIqbNeRSxd1dtMPV2qHwMOWM=; b=JX9wvWmi0VWIIrDrt2J26zsWG/n+CiarPYymcyN1tHuwqIofiqLE75gVnD37g+164K bm21sINDjG6TJTg0FwN3G4+aT4Z/pbef4LLMBEiwG6ZXQBkJtIRv6dgdq5zzVFGE6oIT cB+BhZFlz72REzpP+nlM9ONItmoqz9qFxR5RjtZviTcYjjmZgVZdNHUzJSyJs+OBAvp/ 7QcGOaexTm4wIZm+Y+OhHC2MKeul4bcNbdSdJ1NHElWft/ZauZRQPyp4YF9iu4sfOukX 9Kl/reX8RbHtUr0J9zgF97wJA3c8kqwL/bNgmVtvYbgtBVtNDEIhYGnJr6EiELnkK4t/ FBtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:user-agent:message-id :mime-version; bh=Zq+1AuHkLO3esC5dJh7ZIqbNeRSxd1dtMPV2qHwMOWM=; b=ri0URZcnAwkIrSPlgxwnGRfCjYxfZW08ne4VFLgjdO5KNTZh42weOpr7DjWDGUpY6N d2CLPrMsVAXV2NsOP9T23tSVdT7VQu+bnIaacAY8IjgQk5TLy5IlE77HXrO9EZWOZnQe GHzhr3sGOEM3zCS7rZ65ii0Qtm05C3gSs/3MopAYHuJkz/ohHjK6Y1c8kQeg0IncygJc LZlz81b/3Sq8U//ixW/KIP2jcR8phi3x5jGR1FaCrv5rarge1iEmXPqXLx6dYQ7ENa3e vuOaHbRzkX0e1Tnaz3FZEgaheJkK8ZSnYpKHmbNgv8WxfwG8hTEFGDmeTn9+Nop0DcOQ gdew== X-Gm-Message-State: AOAM532IE+3VEZpkcqDCKLRogqza2h+s90LfUOm3pWdDOpLoXn2FMUSo WSwytxSWlIdKqOjgk4fT6bk4XKdCcBQ= X-Google-Smtp-Source: ABdhPJzFb4XQ6AvdnfvpVnK+LK2E9vL7Gc6g2CBAleElIA+Uh51c0my2pUerx36n5gxZC1YMVJ9Swg== X-Received: by 2002:a17:90b:4a4c:: with SMTP id lb12mr13303856pjb.55.1632657643318; Sun, 26 Sep 2021 05:00:43 -0700 (PDT) Received: from localhost (61-245-128-160.3df580.per.nbn.aussiebb.net. [61.245.128.160]) by smtp.gmail.com with ESMTPSA id w206sm13985714pfc.45.2021.09.26.05.00.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 05:00:42 -0700 (PDT) From: Timothy To: Org Mode List Subject: [PATCH] Date: Sun, 26 Sep 2021 19:51:15 +0800 User-agent: mu4e 1.6.5; emacs 28.0.50 Message-ID: <87fstreec8.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=tecosaur@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1632657982; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Zq+1AuHkLO3esC5dJh7ZIqbNeRSxd1dtMPV2qHwMOWM=; b=efQdJ1UzBnI57oz+w7NBLRH++4p8ac10jwWPwpM0NEX0FFEQw/3wrwM0Tfs4XmQTN0ChBx ETksm6JPEY/+odKkT7SOetIgSNv7ouJUDk51pKW8q3F5poV6zYnQEViwhiLcQWD5mOSV/U pziZ8A+58Xj4bwu6mDw6wjAnxqCAT4cdtLcu0n7oTPVq6F+F2dx8ixHNFNUSwnv9PABpaC xcpBMWNTd2KyPzVcLSCAQI/twpN1KssBYy7sfXa3RPB4LBMw6DdYVSANqKxEF2lEz17Ly+ pcC7sr1Happa1TERBA3THyTwLduh2iWuRBZ/FSxyup4yF2sFmqDlF52fAG8JxA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632657982; a=rsa-sha256; cv=none; b=uNwvj18rWbzKblV7wxNsarj2kFvGb9F5DDRV7i4I4AS4hnO39vzI5IUBN3Hm+pU0H5L6HI CXlZwV6NDTqS3Jqn6UFSuwFpVYRAQwDzVt69pbCKE0tufOWxP15Azh+JY+oXDo1cl4oF/Z MyAky0xKXv2JxVwp91rmjOzQ1twSehf8nbjXQ8ES9ip8M4F8ak0tG/ClemApJVeay15Bif kmyEMfPY98btYbl9dWl6F9CqxtSr4B4lvT1ALRWGToz900i+QU+NtGFl2uKdPlnCgntRhT gHysWje4GmbEWoArFtFEB7qqmqVadH1EcpzLT9IwiNU1unIp80aJl73PgET9EA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JX9wvWmi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.96 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JX9wvWmi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: EB3CC2AC28 X-Spam-Score: -1.96 X-Migadu-Scanner: scn1.migadu.com X-TUID: GcJ2fENgSxol --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Everyone, I=E2=80=99ve recently been wondering why it is that for sensibly sized imag= es in a LaTeX-export-oriented document I need to do both: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+attr_org: :width 400 =E2=94=82 #+attr_latex: :width 0.4\linewidth =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 When in HTML, just =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+attr_html: :width 400px =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 is fine. This has lead me to have a look at `org-display-inline-images', and I=E2=80= =99ve realised that the `#+attr_latex' width of `0.4\linewidth' is actually picked up, and interpreted as a width of `0.4' pixels. I think it would make much more sen= se for fractional values between zero and one to be interpreted as that portion of= the text width in the buffer. On second thoughts, given that the document width= can be slightly larger than the text width, perhaps an upper bound just a bit h= igher =E2=80=94 say 2, could be better. I=E2=80=99ve prepared a patch which implements this logic, by converting ex= tracted widths that are: =E2=81=83 floats, and =E2=81=83 within the range [0,2] and sizes them as that proportion of the text width in the buffer, which is determined by checking 1. `visual-fill-column-width', when that package is installed and the mode = active 2. `fill-column', when auto fill is active 3. `(window-text-width)', if neither of the above two cases hold Please let me know what you think =F0=9F=99=82. All the best, Timothy --==-=-= Content-Type: text/html; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable =

Hi Everyone,

I=E2=80=99ve recently been wondering why it is that for sensibly sized imag= es in a LaTeX-export-oriented document I need to do both:

#+attr_org: :width 400
#+attr_latex: :width 0.4\linewidth

When in HTML, just

#+attr_html: :width 400px

is fine.

This has lead me to have a look at org-display-inline-im= ages, and I=E2=80=99ve realised that the #+attr_latex width of = 0.4\linewidth is actually picked up, and interpreted as a width of 0.4 pixels. I think it w= ould make much more sense for fractional values between zero and one to be interpreted as that portion of= the text width in the buffer. On second thoughts, given that the document width= can be slightly larger than the text width, perhaps an upper bound just a bit h= igher =E2=80=94 say 2, could be better.

I=E2=80=99ve prepared a patch which implements this logic, by converting ex= tracted widths that are:

  • floats, and
  • within the range [0,2]

and sizes them as that proportion of the text width in the buffer, which is determined by checking

  1. visua= l-fill-column-width, when that package is installed and the mode acti= ve
  2. fill-column, when auto fill is active
  3. (window-text-width), if neither of the above t= wo cases hold

Please let me know what you think =F0=9F=99=82.

All the best,
Timothy

--==-=-=-- --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-Display-proportional-image-widths.patch >From bc8aa862f513946599efe4a9bb420e54c504ab3b Mon Sep 17 00:00:00 2001 From: TEC Date: Fri, 24 Sep 2021 01:39:31 +0800 Subject: [PATCH] org: Display proportional image widths * lisp/org.el (org-display-inline-images): When the image width is given as a float less than 2, interpret the value as that portion of the text area width. This works well with cases such as "#+attr_latex: :width 0.6\linewidth" as this will now be interpreted as 60% of the text area width. The upper bound is set to 2 not 1, as more than 100% of the text width can be realistic, e.g. "1.2\linewidth" in LaTeX, but more than 200% seems unrealistic. --- lisp/org.el | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 66ca73d5e..ce2ac7404 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16622,22 +16622,37 @@ (defun org-display-inline-images (&optional include-linked refresh beg end) (cond ((eq org-image-actual-width t) nil) ((listp org-image-actual-width) - (or - ;; First try to find a width among - ;; attributes associated to the paragraph - ;; containing link. - (pcase (org-element-lineage link '(paragraph)) - (`nil nil) - (p - (let* ((case-fold-search t) - (end (org-element-property :post-affiliated p)) - (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)")) - (when (org-with-point-at - (org-element-property :begin p) - (re-search-forward re end t)) - (string-to-number (match-string 1)))))) - ;; Otherwise, fall-back to provided number. - (car org-image-actual-width))) + (let ((width + (or + ;; First try to find a width among + ;; attributes associated to the paragraph + ;; containing link. + (pcase (org-element-lineage link '(paragraph)) + (`nil nil) + (par (let* ((case-fold-search t) + (end (org-element-property :post-affiliated par)) + (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)")) + (when (org-with-point-at + (org-element-property :begin par) + (re-search-forward re end t)) + (string-to-number (match-string 1))))))) + ;; Otherwise, fall-back to provided number. + (car org-image-actual-width)))) + (when width + (if (and (floatp width) (<= 0 width 2.0)) + ;; A float in [0,2] should be interpereted as this portion of + ;; the text width in the window. This works well with cases like + ;; #+attr_latex: :width 0.X\{line,page,column,etc.}width, + ;; as the "0.X" is pulled out as a float. We use 2 as the upper + ;; bound as cases such as 1.2\linewidth are feasible. + (round (* width + (window-pixel-width) + (/ (or (and (bound-and-true-p visual-fill-column-mode) + (or visual-fill-column-width auto-fill-function)) + (when auto-fill-function fill-column) + (window-text-width)) + (float (window-total-width))))) + width)))) ((numberp org-image-actual-width) org-image-actual-width) (t nil))) -- 2.33.0 --=-=-=--