* Patch to allow adjusting latex fragment display scale factor
@ 2021-10-11 4:32 Matt Huszagh
2021-10-11 4:40 ` Matt Huszagh
0 siblings, 1 reply; 7+ messages in thread
From: Matt Huszagh @ 2021-10-11 4:32 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]
Hi,
I've created a patch to allow adjusting the scale factor used for inline
latex image fragments. This involves a customizable variable that can
either be set to a scale factor (defaults to 1.0) or a function that
evaluates to a scale factor.
This feature is in addition to the existing scale factor adjustment
capability provided by `org-preview-latex-process-alist' through
`:image-size-adjust'. Wherease image-size-adjust performs scaling at the
time of image generation, the new change performs it during
display. This can lead to significant time saving and suffers no loss of
quality for vector graphics.
As an example of use, I have several functions for changing frame
scaling. I've added
(if (eq major-mode 'org-mode)
(progn
(org-clear-latex-preview)
;; 16 corresponds to the C-u C-u arg prefix.
(org-latex-preview 16)))
to these functions so that changing the frame scaling also
correspondingly changes the latex preview/fragment scaling to match the
new size of the surrounding text. Because of this new feature, this
change is effectively instantaneous for reasonably numbers of
overlays. Obviously, something similar could be done for
`text-scale-adjust' (e.g., through `advice-add').
Feedback appreciated.
Matt
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Allow-customizing-overlay-put-scale-factor.patch --]
[-- Type: text/x-patch, Size: 1912 bytes --]
From 8247947aa6141cde9c58205e0266f0e674226f95 Mon Sep 17 00:00:00 2001
From: Matt Huszagh <huszaghmatt@gmail.com>
Date: Sun, 10 Oct 2021 21:20:31 -0700
Subject: [PATCH] org.el: Allow customizing overlay-put scale factor
* lisp/org.el (org-latex-fragment-scale): Add customizable variable
that is equal to or evaluates to a scale factor used to scale inline
latex fragments.
(org--make-preview-overlay): Adjust latex fragment overlay generation
to account for the new custom scale factor.
---
lisp/org.el | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lisp/org.el b/lisp/org.el
index dbc288a3c..f5e9ff8d1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -388,6 +388,15 @@ text."
:type '(symbol function integer)
:group 'org)
+(defcustom org-latex-fragment-scale 1.0
+ "Scaling factor used for LaTeX image fragments.
+This can either be a number or a function that takes the image
+data and image type as parameters and evaluates to a number. The
+function can be useful for context-aware scaling, such as setting
+the scale factor to be consistent with the surrounding text size."
+ :type '(number function)
+ :group 'org)
+
;;; Version
(org-check-version)
@@ -16007,7 +16016,13 @@ as a string. It defaults to \"png\"."
(delete-overlay o))))
(overlay-put ov
'display
- (list 'image :type imagetype :file image :ascent ascent)))))
+ (list 'image
+ :type imagetype
+ :file image
+ :ascent ascent
+ :scale (if (functionp org-latex-fragment-scale)
+ (funcall org-latex-fragment-scale image imagetype)
+ org-latex-fragment-scale))))))
(defun org-clear-latex-preview (&optional beg end)
"Remove all overlays with LaTeX fragment images in current buffer.
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2021-10-11 4:32 Patch to allow adjusting latex fragment display scale factor Matt Huszagh
@ 2021-10-11 4:40 ` Matt Huszagh
2024-01-19 6:49 ` Matt Huszagh
0 siblings, 1 reply; 7+ messages in thread
From: Matt Huszagh @ 2021-10-11 4:40 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1485 bytes --]
Matt Huszagh <huszaghmatt@gmail.com> writes:
> I've created a patch to allow adjusting the scale factor used for inline
> latex image fragments. This involves a customizable variable that can
> either be set to a scale factor (defaults to 1.0) or a function that
> evaluates to a scale factor.
>
> This feature is in addition to the existing scale factor adjustment
> capability provided by `org-preview-latex-process-alist' through
> `:image-size-adjust'. Wherease image-size-adjust performs scaling at the
> time of image generation, the new change performs it during
> display. This can lead to significant time saving and suffers no loss of
> quality for vector graphics.
>
> As an example of use, I have several functions for changing frame
> scaling. I've added
>
> (if (eq major-mode 'org-mode)
> (progn
> (org-clear-latex-preview)
> ;; 16 corresponds to the C-u C-u arg prefix.
> (org-latex-preview 16)))
>
> to these functions so that changing the frame scaling also
> correspondingly changes the latex preview/fragment scaling to match the
> new size of the surrounding text. Because of this new feature, this
> change is effectively instantaneous for reasonably numbers of
> overlays. Obviously, something similar could be done for
> `text-scale-adjust' (e.g., through `advice-add').
>
> Feedback appreciated.
Apologies, the patch I sent is slightly wrong. The line numbers also
reflect an earlier patch I made. Here is a corrected version.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Allow-customizing-overlay-put-scale-factor.patch --]
[-- Type: text/x-patch, Size: 1882 bytes --]
From 3c0e74a8659edb52c1200a02f8a20216b348c4ac Mon Sep 17 00:00:00 2001
From: Matt Huszagh <huszaghmatt@gmail.com>
Date: Sun, 10 Oct 2021 21:20:31 -0700
Subject: [PATCH] org.el: Allow customizing overlay-put scale factor
* lisp/org.el (org-latex-fragment-scale): Add customizable variable
that is equal to or evaluates to a scale factor used to scale inline
latex fragments.
(org--make-preview-overlay): Adjust latex fragment overlay generation
to account for the new custom scale factor.
---
lisp/org.el | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lisp/org.el b/lisp/org.el
index 405f0f0f9..052212efb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -320,6 +320,15 @@ identifier."
:version "24.1"
:group 'org-id)
+(defcustom org-latex-fragment-scale 1.0
+ "Scaling factor used for LaTeX image fragments.
+This can either be a number or a function that takes the image
+data and image type as parameters and evaluates to a number. The
+function can be useful for context-aware scaling, such as setting
+the scale factor to be consistent with the surrounding text size."
+ :type '(number function)
+ :group 'org)
+
;;; Version
(org-check-version)
@@ -15936,7 +15945,13 @@ as a string. It defaults to \"png\"."
(delete-overlay o))))
(overlay-put ov
'display
- (list 'image :type imagetype :file image :ascent 'center))))
+ (list 'image
+ :type imagetype
+ :file image
+ :ascent 'center
+ :scale (if (functionp org-latex-fragment-scale)
+ (funcall org-latex-fragment-scale image imagetype)
+ org-latex-fragment-scale)))))
(defun org-clear-latex-preview (&optional beg end)
"Remove all overlays with LaTeX fragment images in current buffer.
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2021-10-11 4:40 ` Matt Huszagh
@ 2024-01-19 6:49 ` Matt Huszagh
2024-01-19 13:26 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Matt Huszagh @ 2024-01-19 6:49 UTC (permalink / raw)
To: emacs-orgmode@gnu.org, Ihor Radchenko
Hi,
Bringing this back up. Ihor, I've added you to the thread directly
(hope that's ok).
Any thoughts? I have not yet updated it for the most recent changes to
main, but I can do that.
Matt
On Sun, Oct 10, 2021 at 9:40 PM Matt Huszagh <huszaghmatt@gmail.com> wrote:
>
> Matt Huszagh <huszaghmatt@gmail.com> writes:
>
> > I've created a patch to allow adjusting the scale factor used for inline
> > latex image fragments. This involves a customizable variable that can
> > either be set to a scale factor (defaults to 1.0) or a function that
> > evaluates to a scale factor.
> >
> > This feature is in addition to the existing scale factor adjustment
> > capability provided by `org-preview-latex-process-alist' through
> > `:image-size-adjust'. Wherease image-size-adjust performs scaling at the
> > time of image generation, the new change performs it during
> > display. This can lead to significant time saving and suffers no loss of
> > quality for vector graphics.
> >
> > As an example of use, I have several functions for changing frame
> > scaling. I've added
> >
> > (if (eq major-mode 'org-mode)
> > (progn
> > (org-clear-latex-preview)
> > ;; 16 corresponds to the C-u C-u arg prefix.
> > (org-latex-preview 16)))
> >
> > to these functions so that changing the frame scaling also
> > correspondingly changes the latex preview/fragment scaling to match the
> > new size of the surrounding text. Because of this new feature, this
> > change is effectively instantaneous for reasonably numbers of
> > overlays. Obviously, something similar could be done for
> > `text-scale-adjust' (e.g., through `advice-add').
> >
> > Feedback appreciated.
>
> Apologies, the patch I sent is slightly wrong. The line numbers also
> reflect an earlier patch I made. Here is a corrected version.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2024-01-19 6:49 ` Matt Huszagh
@ 2024-01-19 13:26 ` Ihor Radchenko
2024-01-22 5:11 ` Timothy
0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2024-01-19 13:26 UTC (permalink / raw)
To: Matt Huszagh, Timothy, Karthik Chikmagalur
Cc: emacs-orgmode@gnu.org, Ihor Radchenko
Matt Huszagh <huszaghmatt@gmail.com> writes:
> Bringing this back up. Ihor, I've added you to the thread directly
> (hope that's ok).
>
> Any thoughts? I have not yet updated it for the most recent changes to
> main, but I can do that.
As you found in another thread, we have a WIP overhaul of the whole
LaTeX preview system. I hope that it can be merged in the coming few
months.
AFAIU, the new system will allow setting the scale factor - see
https://git.tecosaur.net/tec/org-mode/src/branch/dev/lisp/org-latex-preview.el#L57
Although, it does not look like a function is accepted as an allowed
value.
CCing Timothy and Karthik - they may have comments on the possibility to
allow function as :scale value.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2024-01-19 13:26 ` Ihor Radchenko
@ 2024-01-22 5:11 ` Timothy
2024-01-22 5:26 ` Matt Huszagh
0 siblings, 1 reply; 7+ messages in thread
From: Timothy @ 2024-01-22 5:11 UTC (permalink / raw)
To: Ihor Radchenko
Cc: Matt Huszagh, Karthik Chikmagalur, emacs-orgmode@gnu.org,
Ihor Radchenko
[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]
Hi Matt and Ihor,
>> Any thoughts? I have not yet updated it for the most recent changes to
>> main, but I can do that.
>
> As you found in another thread, we have a WIP overhaul of the whole
> LaTeX preview system. I hope that it can be merged in the coming few
> months.
>
> AFAIU, the new system will allow setting the scale factor - see
> <https://git.tecosaur.net/tec/org-mode/src/branch/dev/lisp/org-latex-preview.el#L57>
> Although, it does not look like a function is accepted as an allowed
> value.
>
> CCing Timothy and Karthik - they may have comments on the possibility to
> allow function as :scale value.
I must admit that with the new system, I don’t see much value in accepting a
function: we now scale the previews based on a combination of the :scale
parameter and their actual LaTeX display size.
All the best,
Timothy
--
Timothy (‘tecosaur’/‘TEC’), Org mode contributor.
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/tec>.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2024-01-22 5:11 ` Timothy
@ 2024-01-22 5:26 ` Matt Huszagh
2024-01-22 9:47 ` Ihor Radchenko
0 siblings, 1 reply; 7+ messages in thread
From: Matt Huszagh @ 2024-01-22 5:26 UTC (permalink / raw)
To: Timothy
Cc: Ihor Radchenko, Karthik Chikmagalur, emacs-orgmode@gnu.org,
Ihor Radchenko
Timothy <orgmode@tec.tecosaur.net> writes:
> Hi Matt and Ihor,
> I must admit that with the new system, I don’t see much value in accepting a
> function: we now scale the previews based on a combination of the :scale
> parameter and their actual LaTeX display size.
Yep, we can close/cancel this patch. I had been using that feature to
permit rescaling latex fragments for font size changes, but that's
already handled by the current implementation.
Matt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Patch to allow adjusting latex fragment display scale factor
2024-01-22 5:26 ` Matt Huszagh
@ 2024-01-22 9:47 ` Ihor Radchenko
0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2024-01-22 9:47 UTC (permalink / raw)
To: Matt Huszagh
Cc: Timothy, Karthik Chikmagalur, emacs-orgmode@gnu.org,
Ihor Radchenko
Matt Huszagh <huszaghmatt@gmail.com> writes:
> Yep, we can close/cancel this patch. I had been using that feature to
> permit rescaling latex fragments for font size changes, but that's
> already handled by the current implementation.
Canceled.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-01-22 10:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-11 4:32 Patch to allow adjusting latex fragment display scale factor Matt Huszagh
2021-10-11 4:40 ` Matt Huszagh
2024-01-19 6:49 ` Matt Huszagh
2024-01-19 13:26 ` Ihor Radchenko
2024-01-22 5:11 ` Timothy
2024-01-22 5:26 ` Matt Huszagh
2024-01-22 9:47 ` Ihor Radchenko
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.