From 8cdd2c82731bed46cd4db1f7687bb9a2221e1cb0 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 7 Jan 2024 10:46:05 +0800 Subject: [PATCH] org-latex-preview: Put :page-width in opt plist * lisp/org-latex-preview.el (org-latex-preview-options, org-latex-preview-appearance-options): Rename `org-latex-preview-options' to `org-latex-preview-appearance-options', as it better reflects the purpose of the variable. (org-latex-preview--tex-styled, org-latex-preview--image-extract-async, org-latex-preview--create-tex-file, org-latex-preview--create-image-async, org-latex-preview--hash, org-latex-preview-place, org-latex-preview--update-overlay): Put the page width specification in `org-latex-preview-appearance-options', and adjust existing code to handle this new structuring. * lisp/ox-html.el (org-html-prepare-latex-images, org-html-latex-image-options): Adjust for the `org-latex-preview-appearance-options' rename, and put :page-width in the options plist, just with a raised value of 1.0 as the HTML default. * lisp/org.el (org-do-latex-and-related, org-latex-preview-options), org-compute-latex-and-related-regexp): Adjust for the `org-latex-preview-appearance-options' rename. * lisp/org-compat.el: Adjust for the `org-latex-preview-appearance-options' rename. * lisp/ob-latex.el (org-babel-execute:latex, org-latex-preview-header)): Adjust for the `org-latex-preview-appearance-options' rename. * etc/ORG-NEWS: Adjust for the `org-latex-preview-appearance-options' rename. * doc/org-manual.org (Previewing LaTeX fragments): Adjust for the `org-latex-preview-appearance-options' rename. --- doc/org-manual.org | 4 +- etc/ORG-NEWS | 9 ++-- lisp/ob-latex.el | 10 ++--- lisp/org-compat.el | 2 +- lisp/org-latex-preview.el | 87 +++++++++++++++++++-------------------- lisp/org.el | 6 +-- lisp/ox-html.el | 8 ++-- 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 8a658d9d4..852b1f740 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -11428,9 +11428,9 @@ produce images of the typeset expressions to be used for inclusion while exporting to HTML (see [[*LaTeX fragments]]), or for inline previewing within Org mode. -#+vindex: org-latex-preview-options +#+vindex: org-latex-preview-appearance-options #+vindex: org-latex-preview-header -You can customize the variables ~org-latex-preview-options~ and +You can customize the variables ~org-latex-preview-appearance-options~ and ~org-latex-preview-header~ to influence some aspects of the preview. In particular, the ~:scale~ and ~:zoom~ properties of the former can be used to adjust the size of the preview images. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index f7bcde5a7..c1a637f4a 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -557,7 +557,7 @@ currently being processed. When non-nil, previewed LaTeX environments in the buffer are renumbered automatically as required. -***** New option ~org-latex-preview-width~ to control the text width for LaTeX fragment previews +***** New option =:page-width= in ~org-latex-preview-appearance-options~ to control the text width for LaTeX fragment previews This option controls the width of text in preview images. This is relevant for displaymath-type LaTeX environments, and can be specified @@ -578,13 +578,14 @@ When using ~org-latex-preview-auto-mode~ (which see), setting this option to a n ***** Mark ~org-format-latex-options~ obsolete -Use ~org-latex-preview-options~ instead. The replacement acts in the +Use ~org-latex-preview-appearance-options~ instead. The replacement acts in the same way, except that - the preview image render size and display size can be independently controlled with the =:scale= and =:zoom= plist keys, and - the HTML export-specific parameters =:html-scale=, - =:html-foreground= and =:html-background= have been -moved to ~org-html-latex-image-options~, which see. + =:html-foreground= and =:html-background= have been moved to + ~org-html-latex-image-options~, which see. +- the new option =:page-width= (mentioned earlier) ***** Mark ~org-format-latex-header~ obsolete diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index b8e634772..7ce1f564d 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -48,10 +48,10 @@ (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex")) -(defvar org-latex-preview-header) ; From org-latex-preview.el -(defvar org-latex-preview-options) ; From org-latex-preview.el -(defvar org-latex-default-packages-alist) ; From org-latex-preview.el -(defvar org-latex-packages-alist) ; From org-latex-preview.el +(defvar org-latex-preview-header) ; From org-latex-preview.el +(defvar org-latex-preview-appearance-options) ; From org-latex-preview.el +(defvar org-latex-default-packages-alist) ; From org-latex-preview.el +(defvar org-latex-packages-alist) ; From org-latex-preview.el (defvar org-babel-default-header-args:latex '((:results . "latex") (:exports . "results")) @@ -171,7 +171,7 @@ This function is called by `org-babel-execute-src-block'." (concat org-latex-preview-header "\n" (mapconcat #'identity headers "\n")))) (org-latex-preview-create-image - body out-file org-latex-preview-options in-buffer))) + body out-file org-latex-preview-appearance-options in-buffer))) ((string= "svg" extension) (with-temp-file tex-file (insert (concat (funcall org-babel-latex-preamble params) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 0e0c70077..d2e58b597 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -668,7 +668,7 @@ This constant, for example, makes the below code not err: "9.0") (define-obsolete-variable-alias - 'org-format-latex-options 'org-latex-preview-options "9.7") + 'org-format-latex-options 'org-latex-preview-appearance-options "9.7") (make-obsolete-variable 'org-format-latex-signal-error "no longer used" "9.7") (define-obsolete-variable-alias diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 24582f490..4a7ae3bd7 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -41,29 +41,35 @@ :group 'org) ;;;###autoload -(defcustom org-latex-preview-options - '(:foreground auto :background "Transparent" :scale 1.0 - :matchers ("begin" "$1" "$" "$$" "\\(" "\\[") - :zoom 1.0) +(defcustom org-latex-preview-appearance-options + '(:foreground auto :background "Transparent" + :scale 1.0 :zoom 1.0 :page-width 0.6 + :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")) "Options for creating images from LaTeX fragments. This is a property list with the following properties: -:foreground the foreground color for images embedded in Emacs, e.g. \"Black\". +:foreground The foreground color for images embedded in Emacs, e.g. \"Black\". `default' means use the foreground of the default face. `auto' means use the foreground from the text face. -:background the background color, or \"Transparent\". +:background The background color, or \"Transparent\". `default' means use the background of the default face. `auto' means use the background from the text face. -:scale a scaling factor for the size of the images, to get more pixels -:matchers a list indicating which matchers should be used to +:scale A scaling factor for the size of the images, to get more pixels +:zoom when the image has associated font-relative height information, + the display size is scaled by this factor. +:page-width The width of the LaTeX document fragments are compiled in. + Either: + - A string giving a LaTeX dimension (e.g. \"12cm\"). + - A floating point value between 0.0 and 1.0, + this sets the text width to this ratio of the page width. + - nil, in which case the default text width is unmodified. +:matchers A list indicating which matchers should be used to find LaTeX fragments. Valid members of this list are: \"begin\" find environments \"$1\" find single characters surrounded by $.$ \"$\" find math expressions surrounded by $...$ \"$$\" find math expressions surrounded by $$....$$ \"\\(\" find math expressions surrounded by \\(...\\) - \"\\=\\[\" find math expressions surrounded by \\=\\[...\\] -:zoom when the image has associated font-relative height information, - the display size is scaled by this factor." + \"\\=\\[\" find math expressions surrounded by \\=\\[...\\]" :group 'org-latex-preview :package-version '(Org . "9.7") :type 'plist) @@ -329,20 +335,6 @@ header, or they will be appended." :group 'org-latex-preview :type 'string) -(defcustom org-latex-preview-width 0.6 - "The text width when compiling LaTeX fragments. -This can take a few forms, namely: -- A string giving a LaTeX dimension (e.g. \"12cm\"). -- A floating point value between 0.0 and 1.0, - this sets the text width to this ratio of the page width. -- nil, in which case the default text width is unmodified." - :group 'org-latex-preview - :package-version '(Org . "9.7") - :type '(choice - (string :tag "LaTeX width") - (float :tag "Proportional width") - (const :tag "Unset" nil))) - (defcustom org-latex-preview-precompile t "Use LaTeX header precompilation when previewing fragments. This causes a slight delay the first time `org-latex-pdf-process' @@ -454,7 +446,7 @@ overlay face is set to `org-latex-preview-processing-face'." (defun org-latex-preview--update-overlay (ov path-info) "Update the overlay OV to show the image specified by PATH-INFO." - (let* ((zoom (or (plist-get org-latex-preview-options :zoom) 1.0)) + (let* ((zoom (or (plist-get org-latex-preview-appearance-options :zoom) 1.0)) (height (plist-get (cdr path-info) :height)) (depth (plist-get (cdr path-info) :depth)) (errors (plist-get (cdr path-info) :errors)) @@ -1082,7 +1074,7 @@ is either the substring between BEG and END or (when provided) VALUE." (hash (org-latex-preview--hash processing-type latex-preamble value imagetype fg bg number)) (options (org-combine-plists - org-latex-preview-options + org-latex-preview-appearance-options (list :foreground fg :background bg :number number @@ -1107,17 +1099,18 @@ is either the substring between BEG and END or (when provided) VALUE." processing-type (nreverse fragment-info) :latex-preamble latex-preamble + :appearance-options org-latex-preview-appearance-options :place-preview-p t)))) (defun org-latex-preview--colors-around (start end) "Find colors for LaTeX previews occuping the region START to END." (let* ((face (org-latex-preview--face-around start end)) - (fg (pcase (plist-get org-latex-preview-options :foreground) + (fg (pcase (plist-get org-latex-preview-appearance-options :foreground) ('auto (org-latex-preview--resolved-faces-attr face :foreground)) ('default (face-attribute 'default :foreground nil)) (color color))) - (bg (pcase (plist-get org-latex-preview-options :background) + (bg (pcase (plist-get org-latex-preview-appearance-options :background) ('auto (org-latex-preview--resolved-faces-attr face :background)) ('default (face-attribute 'default :background nil)) @@ -1174,7 +1167,7 @@ NUMBER is the equation number that should be used, if applicable." (if (equal imagetype "svg") 'svg (list (plist-get - org-latex-preview-options :scale) + org-latex-preview-appearance-options :scale) fg)) bg number)))) @@ -1344,7 +1337,7 @@ If PARSE-TREE is provided, it will be used insead of (goto-char (org-element-property :begin datum)) (org-element-context)))))))))) -(cl-defun org-latex-preview--create-image-async (processing-type fragments-info &key latex-processor latex-preamble place-preview-p) +(cl-defun org-latex-preview--create-image-async (processing-type fragments-info &key latex-processor latex-preamble appearance-options place-preview-p) "Preview PREVIEW-STRINGS asynchronously with method PROCESSING-TYPE. FRAGMENTS-INFO is a list of plists, each of which provides @@ -1454,7 +1447,8 @@ Returns a list of async tasks started." :fragments fragments-info :org-buffer (current-buffer) :texfile (org-latex-preview--create-tex-file - processing-info fragments-info) + processing-info fragments-info appearance-options) + :appearance-options appearance-options :place-preview-p place-preview-p))) (tex-compile-async (org-latex-preview--tex-compile-async extended-info)) @@ -1607,7 +1601,7 @@ The options passed to preview.sty are: This is an abridged summary. See the documentation of preview.sty for more details.") -(defun org-latex-preview--create-tex-file (processing-info fragments) +(defun org-latex-preview--create-tex-file (processing-info fragments appearance-options) "Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS. More specifically, a preamble will be generated based on @@ -1625,7 +1619,10 @@ The path of the created LaTeX file is returned." (plist-get processing-info :latex-header) org-latex-preview--include-preview-string)) (textwidth - (let ((w org-latex-preview-width)) + ;; We can fetch width info from APPEARANCE-OPTIONS, but it's + ;; possible that an old config using `org-format-latex-options' + ;; won't have :page-width set, and so we need a default too. + (let ((w (or (plist-get appearance-options :page-width) 0.6))) (cond ((stringp w) (format "\n\\setlength{\\textwidth}{%s}\n" w)) @@ -1741,9 +1738,10 @@ The path of the created LaTeX file is returned." (get-buffer-create org-latex-preview--image-log) (erase-buffer) (current-buffer))) + (appearance-options (plist-get extended-info :appearance-options)) (img-extract-command (pcase - (or (and (string= (plist-get org-latex-preview-options :background) + (or (and (string= (plist-get appearance-options :background) "Transparent") (plist-get extended-info :transparent-image-converter)) (plist-get extended-info :image-converter)) @@ -1755,7 +1753,7 @@ The path of the created LaTeX file is returned." (car cmds)))) (dpi (* 1.4 ; This factor makes it so generated PNGs are not blury ; at the displayed resulution. - (or (plist-get org-latex-preview-options :scale) 1.0) + (or (plist-get appearance-options :scale) 1.0) (if (display-graphic-p) (org-latex-preview--get-display-dpi) 140.0))) @@ -2374,28 +2372,29 @@ process." preamble tempfile-p)) -(defun org-latex-preview--tex-styled (processing-type value options) - "Apply LaTeX style commands to VALUE based on OPTIONS. +(defun org-latex-preview--tex-styled (processing-type value appearance-options) + "Apply LaTeX style commands to VALUE based on APPEARANCE-OPTIONS. If PROCESSING-TYPE is dvipng, the colours are set with DVI \"\\special\" commands instead of \"\\color\" and \"\\pagecolor\". VALUE is the math fragment text to be previewed. -OPTIONS is the plist `org-latex-preview-options' with customized -color information for this run." - (let* ((fg (pcase (plist-get options :foreground) +APPEARANCE-OPTIONS is the plist in the form of +`org-latex-preview-appearance-options' with customized color +information for this run." + (let* ((fg (pcase (plist-get appearance-options :foreground) ('default (org-latex-preview--format-color (org-latex-preview--attr-color :foreground))) ((pred null) (org-latex-preview--format-color "Black")) (color (org-latex-preview--format-color color)))) - (bg (pcase (plist-get options :background) + (bg (pcase (plist-get appearance-options :background) ('default (org-latex-preview--attr-color :background)) ("Transparent" nil) (bg (org-latex-preview--format-color bg)))) - (num (or (plist-get options :number) + (num (or (plist-get appearance-options :number) (and (not (eq org-latex-preview-numbered 'preview)) 1)))) - (concat (and (not (plist-get options :continue-color)) + (concat (and (not (plist-get appearance-options :continue-color)) (if (eq processing-type 'dvipng) (concat (and fg (format "\\special{color rgb %s}" (subst-char-in-string diff --git a/lisp/org.el b/lisp/org.el index 3f3ab5595..5c2939190 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5482,7 +5482,7 @@ Result depends on variable `org-highlight-latex-and-related'." (re-latex (when (or (memq 'latex org-highlight-latex-and-related) (memq 'native org-highlight-latex-and-related)) - (let ((matchers (plist-get org-latex-preview-options :matchers))) + (let ((matchers (plist-get org-latex-preview-appearance-options :matchers))) (delq nil (mapcar (lambda (x) (and (member (car x) matchers) (nth 1 x))) @@ -5496,7 +5496,7 @@ Result depends on variable `org-highlight-latex-and-related'." (append re-latex re-entities re-sub) "\\|")))) -(defvar org-latex-preview-options) ; Defined in org-latex-preview.el. +(defvar org-latex-preview-appearance-options) ; Defined in org-latex-preview.el. (declare-function org-latex-preview--face-around "org-latex-preview" (start end)) (defun org-do-latex-and-related (limit) @@ -5540,7 +5540,7 @@ highlighting was done, nil otherwise." (add-text-properties (+ offset (match-beginning 0)) (match-end 0) '(font-lock-multiline t)) ;; Refresh the face of LaTeX previews (when applicable). - (when (eq (plist-get org-latex-preview-options :foreground) + (when (eq (plist-get org-latex-preview-appearance-options :foreground) 'auto) (dolist (ov (overlays-at start)) (when (and (eq (overlay-get ov 'org-overlay-type) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 12b4c903c..e791f7224 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1174,9 +1174,9 @@ See `format-time-string' for more information on its components." (defcustom org-html-latex-image-options '(:foreground "Black" :background "Transparent" - :scale 1.0 :inline nil) + :page-width 1.0 :scale 1.0 :inline nil) "LaTeX preview options that apply to generated images. -This is a HTML-specific counterpart to `org-latex-preview-options', which see. +This is a HTML-specific counterpart to `org-latex-preview-appearance-options', which see. This also supports the extra property \":inline\", which controls the inlining of images, it can be: @@ -3076,7 +3076,7 @@ TODO." (hash (org-latex-preview--hash processing-type latex-preamble value imagetype fg bg number)) (options (org-combine-plists - org-latex-preview-options + org-latex-preview-appearance-options html-options (list :number number :continue-color @@ -3090,7 +3090,7 @@ TODO." :key hash) fragment-info)) (setq prev-fg fg prev-bg bg))) - (let ((org-latex-preview-options + (let ((org-latex-preview-appearance-options (list (plist-member html-options :scale)))) (when fragment-info (apply #'org-async-wait-for