From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id QnGzBShlUGGIQgAAgWs5BA (envelope-from ) for ; Sun, 26 Sep 2021 14:18:48 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OC3qAChlUGEcSwAAB5/wlQ (envelope-from ) for ; Sun, 26 Sep 2021 12:18:48 +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 8807E30D16 for ; Sun, 26 Sep 2021 14:18:47 +0200 (CEST) Received: from localhost ([::1]:56008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUT7G-0006Hn-Gs for larch@yhetil.org; Sun, 26 Sep 2021 08:18:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUT4x-0006Fn-Rh for emacs-orgmode@gnu.org; Sun, 26 Sep 2021 08:16:23 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:42508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUT4w-0007tK-7q for emacs-orgmode@gnu.org; Sun, 26 Sep 2021 08:16:23 -0400 Received: by mail-pj1-x102e.google.com with SMTP id rm6-20020a17090b3ec600b0019ece2bdd20so1498833pjb.1 for ; Sun, 26 Sep 2021 05:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:user-agent:from:to:subject:date:in-reply-to:message-id :mime-version; bh=oBcccHwCquOockuVzzmCUc1TzBG6BU8im07YvXEWD/A=; b=fLtFJ0FX1fzBUbUX+XmkX+youWm8D7cLTgKQAnzQ0ZW4s7Fts+CXEEWmqZzUeu0IkR WG2V2M36htF5s6EGONvxSmye7m4cfIgGQg177VxuXTdQws1WkxsisEUGaAJN6AkQgLNN bd7ymu9PsqFKTEz9tSMLZu5FLGJp+769RVjO4qEB1b+CsvrBEbDZnQgX/TLjccHE22ee qHvJQt26GTO4KFvPdBin7tL8C3pHeulw0Gej8vNl3TSYJ55pvnQfPqmzsk0WzuukvSKO 6/GQGLcbw9D+GYXa0WlkoZJkA+dCQ6KtIZv2DN7Lsh0SxjzAlIlRv4ikkPGnOlVF9Cqa 7h4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:user-agent:from:to:subject:date :in-reply-to:message-id:mime-version; bh=oBcccHwCquOockuVzzmCUc1TzBG6BU8im07YvXEWD/A=; b=Hnmn8Hov6Srfy7qozjlE5EtZTGIgXd1nWGdbX/cNNUH6O3Wdg6SaE35CP3wbU7rlaL lJQWqEq5EOGdhSk2KJL6bedjEoYdaYm/ZBf1aXSuuQINLNlvggsJfmj+ymGsNqoXUePD 4rhKso5fUAdMdINLM31iZ50j5WZFV6Gp43Dv3pxsXQFt9rulBHAHPXl9AM/ir7ZhaeVU eLJugHouLyTsiQmvsNldZr0HDOwwtMrXg3+hBu15wq8h+BijBSYTv2Z4QRf3SfyoX0HI hBNcGAZkTRPJVozQmSUYhnA3a+xn3/IWalCgZ4scoGJ6tdjFlHCfOl89d0H/WRFCXlpC YAJw== X-Gm-Message-State: AOAM532J2sEO5I2mv8CAQ5lODNxEy+q4M5dLmCDHRuKulCRlCyzBW5SK XehiA5RJHWkr0ESRe7/+WJ5lGloVg9k= X-Google-Smtp-Source: ABdhPJwtICScFzs/pptZ9sE8T2CQ+MWhGBGTBlLcTqyneMlT4ClVEmNlZj4BP3+lHOx8OwLPc3IsLA== X-Received: by 2002:a17:90a:cc9:: with SMTP id 9mr6296601pjt.142.1632658580475; Sun, 26 Sep 2021 05:16:20 -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 r193sm14013745pfc.197.2021.09.26.05.16.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 05:16:20 -0700 (PDT) References: <87fstreec8.fsf@gmail.com> User-agent: mu4e 1.6.5; emacs 28.0.50 From: Timothy To: Org Mode List Subject: Re: [PATCH] Date: Sun, 26 Sep 2021 20:14:40 +0800 In-reply-to: <87fstreec8.fsf@gmail.com> Message-ID: <877df3edm6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=tecosaur@gmail.com; helo=mail-pj1-x102e.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, 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=1632658727; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=oBcccHwCquOockuVzzmCUc1TzBG6BU8im07YvXEWD/A=; b=ckZabldp345l3uxXdX5pbCc9lFfkc9EU5xphccUlT5G87IVXi2bVqRNL/qc4AMFtmrajM+ fFkL9x9JqBT65LFsuyJpoXb9y1JZueE0KSE/Nu7FP2gqOzz/J6fPrsfmhz5vH+neNvzKyg kNBWtx3FbCSa/s/PMiH5dkwPGRXbbqJ9I2L0Voe6diS4AJ3M5eDFF++wRPQWDHGq33iQm3 +XnR1weBkaWmx4IOGaTucYiHwQhIdtjYX0+D6it1/ZpfB4Y9fektAMOogOL0iinE4AhlVv 9SzAQi8/17o4RTOtI07aiWoQAFJpQO2Y5G82FUP2Ykr1TNirisy8I1jZSsklvw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1632658727; a=rsa-sha256; cv=none; b=YsO+nXbtqTlx5rU5JBXvOjhbMrsCHOPP/OBVuu47jjOlTd+n0nwCysa0PethRU+koTywBo 1aUsyhOXiirQqD9gO5iYk0eIvUhrOQ4hyJDLbETDUHrEK3po7LeX56CQGxmdGzy1WDCzur xlRmyriGt3TS/YtvESrnaQG8ncw9QziFrxBD499HILnZK89F5SZHzgGC0fsRhe3spBBsSY Y5BmBM8tFy+UNeyQg/QXdGBrM4OsvdBchkjuOKJgfPOaslG7WB8Q5WnG6wxtlEuszjY+Wm +o9Z8LG1zt0UP1t4qaizeIays6Jk0FoOdHZt7kjB/k5SjwjxCZDvFXx+H7RfSw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fLtFJ0FX; 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.06 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fLtFJ0FX; 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: 8807E30D16 X-Spam-Score: -1.06 X-Migadu-Scanner: scn0.migadu.com X-TUID: Svq4MV3lVVEO --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello again, > I=E2=80=99ve prepared a patch which implements this logic I've just noticed that I had (when x (if (floatp x) ..)) which is a bit silly, so I've removed the unnecessary when. Here's the updated patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-Display-proportional-image-widths.patch >From 2d8f151bb996e0159793b590baea50c530e3ed11 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 | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 66ca73d5e..1a1feda78 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16622,22 +16622,36 @@ (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)))) + (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 --=-=-=--