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.
This commit is contained in:
TEC 2024-01-07 10:46:05 +08:00
parent 1d9baf095a
commit 8cdd2c8273
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
7 changed files with 63 additions and 63 deletions

View File

@ -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 while exporting to HTML (see [[*LaTeX fragments]]), or for inline
previewing within Org mode. previewing within Org mode.
#+vindex: org-latex-preview-options #+vindex: org-latex-preview-appearance-options
#+vindex: org-latex-preview-header #+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. ~org-latex-preview-header~ to influence some aspects of the preview.
In particular, the ~:scale~ and ~:zoom~ properties of the former can In particular, the ~:scale~ and ~:zoom~ properties of the former can
be used to adjust the size of the preview images. be used to adjust the size of the preview images.

View File

@ -557,7 +557,7 @@ currently being processed.
When non-nil, previewed LaTeX environments in the buffer are When non-nil, previewed LaTeX environments in the buffer are
renumbered automatically as required. 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 This option controls the width of text in preview images. This is
relevant for displaymath-type LaTeX environments, and can be specified 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 ***** 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 same way, except that
- the preview image render size and display size can be independently - the preview image render size and display size can be independently
controlled with the =:scale= and =:zoom= plist keys, and controlled with the =:scale= and =:zoom= plist keys, and
- the HTML export-specific parameters =:html-scale=, - the HTML export-specific parameters =:html-scale=,
=:html-foreground= and =:html-background= have been =:html-foreground= and =:html-background= have been moved to
moved to ~org-html-latex-image-options~, which see. ~org-html-latex-image-options~, which see.
- the new option =:page-width= (mentioned earlier)
***** Mark ~org-format-latex-header~ obsolete ***** Mark ~org-format-latex-header~ obsolete

View File

@ -48,10 +48,10 @@
(defvar org-babel-tangle-lang-exts) (defvar org-babel-tangle-lang-exts)
(add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex")) (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
(defvar org-latex-preview-header) ; From org-latex-preview.el (defvar org-latex-preview-header) ; From org-latex-preview.el
(defvar org-latex-preview-options) ; 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-default-packages-alist) ; From org-latex-preview.el
(defvar org-latex-packages-alist) ; From org-latex-preview.el (defvar org-latex-packages-alist) ; From org-latex-preview.el
(defvar org-babel-default-header-args:latex (defvar org-babel-default-header-args:latex
'((:results . "latex") (:exports . "results")) '((:results . "latex") (:exports . "results"))
@ -171,7 +171,7 @@ This function is called by `org-babel-execute-src-block'."
(concat org-latex-preview-header "\n" (concat org-latex-preview-header "\n"
(mapconcat #'identity headers "\n")))) (mapconcat #'identity headers "\n"))))
(org-latex-preview-create-image (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) ((string= "svg" extension)
(with-temp-file tex-file (with-temp-file tex-file
(insert (concat (funcall org-babel-latex-preamble params) (insert (concat (funcall org-babel-latex-preamble params)

View File

@ -668,7 +668,7 @@ This constant, for example, makes the below code not err:
"9.0") "9.0")
(define-obsolete-variable-alias (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 (make-obsolete-variable
'org-format-latex-signal-error "no longer used" "9.7") 'org-format-latex-signal-error "no longer used" "9.7")
(define-obsolete-variable-alias (define-obsolete-variable-alias

View File

@ -41,29 +41,35 @@
:group 'org) :group 'org)
;;;###autoload ;;;###autoload
(defcustom org-latex-preview-options (defcustom org-latex-preview-appearance-options
'(:foreground auto :background "Transparent" :scale 1.0 '(:foreground auto :background "Transparent"
:matchers ("begin" "$1" "$" "$$" "\\(" "\\[") :scale 1.0 :zoom 1.0 :page-width 0.6
:zoom 1.0) :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))
"Options for creating images from LaTeX fragments. "Options for creating images from LaTeX fragments.
This is a property list with the following properties: 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. `default' means use the foreground of the default face.
`auto' means use the foreground from the text 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. `default' means use the background of the default face.
`auto' means use the background from the text face. `auto' means use the background from the text face.
:scale a scaling factor for the size of the images, to get more pixels :scale A scaling factor for the size of the images, to get more pixels
:matchers a list indicating which matchers should be used to :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: find LaTeX fragments. Valid members of this list are:
\"begin\" find environments \"begin\" find environments
\"$1\" find single characters surrounded by $.$ \"$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 $$....$$
\"\\(\" 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."
:group 'org-latex-preview :group 'org-latex-preview
:package-version '(Org . "9.7") :package-version '(Org . "9.7")
:type 'plist) :type 'plist)
@ -329,20 +335,6 @@ header, or they will be appended."
:group 'org-latex-preview :group 'org-latex-preview
:type 'string) :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 (defcustom org-latex-preview-precompile t
"Use LaTeX header precompilation when previewing fragments. "Use LaTeX header precompilation when previewing fragments.
This causes a slight delay the first time `org-latex-pdf-process' 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) (defun org-latex-preview--update-overlay (ov path-info)
"Update the overlay OV to show the image specified by 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)) (height (plist-get (cdr path-info) :height))
(depth (plist-get (cdr path-info) :depth)) (depth (plist-get (cdr path-info) :depth))
(errors (plist-get (cdr path-info) :errors)) (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 (hash (org-latex-preview--hash
processing-type latex-preamble value imagetype fg bg number)) processing-type latex-preamble value imagetype fg bg number))
(options (org-combine-plists (options (org-combine-plists
org-latex-preview-options org-latex-preview-appearance-options
(list :foreground fg (list :foreground fg
:background bg :background bg
:number number :number number
@ -1107,17 +1099,18 @@ is either the substring between BEG and END or (when provided) VALUE."
processing-type processing-type
(nreverse fragment-info) (nreverse fragment-info)
:latex-preamble latex-preamble :latex-preamble latex-preamble
:appearance-options org-latex-preview-appearance-options
:place-preview-p t)))) :place-preview-p t))))
(defun org-latex-preview--colors-around (start end) (defun org-latex-preview--colors-around (start end)
"Find colors for LaTeX previews occuping the region START to END." "Find colors for LaTeX previews occuping the region START to END."
(let* ((face (org-latex-preview--face-around start 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 ('auto
(org-latex-preview--resolved-faces-attr face :foreground)) (org-latex-preview--resolved-faces-attr face :foreground))
('default (face-attribute 'default :foreground nil)) ('default (face-attribute 'default :foreground nil))
(color color))) (color color)))
(bg (pcase (plist-get org-latex-preview-options :background) (bg (pcase (plist-get org-latex-preview-appearance-options :background)
('auto ('auto
(org-latex-preview--resolved-faces-attr face :background)) (org-latex-preview--resolved-faces-attr face :background))
('default (face-attribute 'default :background nil)) ('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") (if (equal imagetype "svg")
'svg 'svg
(list (plist-get (list (plist-get
org-latex-preview-options :scale) org-latex-preview-appearance-options :scale)
fg)) fg))
bg bg
number)))) number))))
@ -1344,7 +1337,7 @@ If PARSE-TREE is provided, it will be used insead of
(goto-char (org-element-property :begin datum)) (goto-char (org-element-property :begin datum))
(org-element-context)))))))))) (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. "Preview PREVIEW-STRINGS asynchronously with method PROCESSING-TYPE.
FRAGMENTS-INFO is a list of plists, each of which provides 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 :fragments fragments-info
:org-buffer (current-buffer) :org-buffer (current-buffer)
:texfile (org-latex-preview--create-tex-file :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))) :place-preview-p place-preview-p)))
(tex-compile-async (tex-compile-async
(org-latex-preview--tex-compile-async extended-info)) (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 This is an abridged summary. See the documentation of
preview.sty for more details.") 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. "Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS.
More specifically, a preamble will be generated based on 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) (plist-get processing-info :latex-header)
org-latex-preview--include-preview-string)) org-latex-preview--include-preview-string))
(textwidth (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 (cond
((stringp w) ((stringp w)
(format "\n\\setlength{\\textwidth}{%s}\n" 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) (get-buffer-create org-latex-preview--image-log)
(erase-buffer) (erase-buffer)
(current-buffer))) (current-buffer)))
(appearance-options (plist-get extended-info :appearance-options))
(img-extract-command (img-extract-command
(pcase (pcase
(or (and (string= (plist-get org-latex-preview-options :background) (or (and (string= (plist-get appearance-options :background)
"Transparent") "Transparent")
(plist-get extended-info :transparent-image-converter)) (plist-get extended-info :transparent-image-converter))
(plist-get extended-info :image-converter)) (plist-get extended-info :image-converter))
@ -1755,7 +1753,7 @@ The path of the created LaTeX file is returned."
(car cmds)))) (car cmds))))
(dpi (* 1.4 ; This factor makes it so generated PNGs are not blury (dpi (* 1.4 ; This factor makes it so generated PNGs are not blury
; at the displayed resulution. ; 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) (if (display-graphic-p)
(org-latex-preview--get-display-dpi) (org-latex-preview--get-display-dpi)
140.0))) 140.0)))
@ -2374,28 +2372,29 @@ process."
preamble preamble
tempfile-p)) tempfile-p))
(defun org-latex-preview--tex-styled (processing-type value options) (defun org-latex-preview--tex-styled (processing-type value appearance-options)
"Apply LaTeX style commands to VALUE based on OPTIONS. "Apply LaTeX style commands to VALUE based on APPEARANCE-OPTIONS.
If PROCESSING-TYPE is dvipng, the colours are set with DVI If PROCESSING-TYPE is dvipng, the colours are set with DVI
\"\\special\" commands instead of \"\\color\" and \"\\special\" commands instead of \"\\color\" and
\"\\pagecolor\". \"\\pagecolor\".
VALUE is the math fragment text to be previewed. VALUE is the math fragment text to be previewed.
OPTIONS is the plist `org-latex-preview-options' with customized APPEARANCE-OPTIONS is the plist in the form of
color information for this run." `org-latex-preview-appearance-options' with customized color
(let* ((fg (pcase (plist-get options :foreground) information for this run."
(let* ((fg (pcase (plist-get appearance-options :foreground)
('default (org-latex-preview--format-color (org-latex-preview--attr-color :foreground))) ('default (org-latex-preview--format-color (org-latex-preview--attr-color :foreground)))
((pred null) (org-latex-preview--format-color "Black")) ((pred null) (org-latex-preview--format-color "Black"))
(color (org-latex-preview--format-color color)))) (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)) ('default (org-latex-preview--attr-color :background))
("Transparent" nil) ("Transparent" nil)
(bg (org-latex-preview--format-color bg)))) (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)) (and (not (eq org-latex-preview-numbered 'preview))
1)))) 1))))
(concat (and (not (plist-get options :continue-color)) (concat (and (not (plist-get appearance-options :continue-color))
(if (eq processing-type 'dvipng) (if (eq processing-type 'dvipng)
(concat (and fg (format "\\special{color rgb %s}" (concat (and fg (format "\\special{color rgb %s}"
(subst-char-in-string (subst-char-in-string

View File

@ -5482,7 +5482,7 @@ Result depends on variable `org-highlight-latex-and-related'."
(re-latex (re-latex
(when (or (memq 'latex org-highlight-latex-and-related) (when (or (memq 'latex org-highlight-latex-and-related)
(memq 'native 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 (delq nil
(mapcar (lambda (x) (mapcar (lambda (x)
(and (member (car x) matchers) (nth 1 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) (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)) (declare-function org-latex-preview--face-around "org-latex-preview" (start end))
(defun org-do-latex-and-related (limit) (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) (add-text-properties (+ offset (match-beginning 0)) (match-end 0)
'(font-lock-multiline t)) '(font-lock-multiline t))
;; Refresh the face of LaTeX previews (when applicable). ;; 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) 'auto)
(dolist (ov (overlays-at start)) (dolist (ov (overlays-at start))
(when (and (eq (overlay-get ov 'org-overlay-type) (when (and (eq (overlay-get ov 'org-overlay-type)

View File

@ -1174,9 +1174,9 @@ See `format-time-string' for more information on its components."
(defcustom org-html-latex-image-options (defcustom org-html-latex-image-options
'(:foreground "Black" :background "Transparent" '(: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. "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 This also supports the extra property \":inline\", which controls the
inlining of images, it can be: inlining of images, it can be:
@ -3076,7 +3076,7 @@ TODO."
(hash (org-latex-preview--hash (hash (org-latex-preview--hash
processing-type latex-preamble value imagetype fg bg number)) processing-type latex-preamble value imagetype fg bg number))
(options (org-combine-plists (options (org-combine-plists
org-latex-preview-options org-latex-preview-appearance-options
html-options html-options
(list :number number (list :number number
:continue-color :continue-color
@ -3090,7 +3090,7 @@ TODO."
:key hash) :key hash)
fragment-info)) fragment-info))
(setq prev-fg fg prev-bg bg))) (setq prev-fg fg prev-bg bg)))
(let ((org-latex-preview-options (let ((org-latex-preview-appearance-options
(list (plist-member html-options :scale)))) (list (plist-member html-options :scale))))
(when fragment-info (when fragment-info
(apply #'org-async-wait-for (apply #'org-async-wait-for