org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
;;; org-latex-preview.el --- LaTeX previews for Org -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;; Copyright (C) 2022 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; Keywords: tex, extensions, tools
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; LaTeX previews for Org
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
(require 'org-macs)
|
|
|
|
(org-assert-version)
|
|
|
|
|
|
|
|
(require 'org-compat)
|
|
|
|
(require 'ox-latex)
|
|
|
|
|
|
|
|
(declare-function org-persist-read "org-persist")
|
|
|
|
(declare-function org-persist-register "org-persist")
|
|
|
|
(declare-function org-persist-unregister "org-persist")
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defgroup org-latex-preview nil
|
|
|
|
"Options for generation of LaTeX previews in Org mode."
|
|
|
|
:tag "Org LaTeX Preview"
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:group 'org)
|
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
;;;###autoload
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defcustom org-latex-preview-options
|
2022-12-27 02:08:24 +00:00
|
|
|
'(:foreground auto :background "Transparent" :scale 1.0
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:html-foreground "Black" :html-background "Transparent"
|
2022-12-30 18:00:22 +00:00
|
|
|
:html-scale 1.0 :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")
|
|
|
|
:zoom 1.0)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"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\".
|
|
|
|
`default' means use the foreground of the default face.
|
|
|
|
`auto' means use the foreground from the text face.
|
|
|
|
: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
|
|
|
|
:html-foreground, :html-background, :html-scale
|
|
|
|
the same numbers for HTML export.
|
|
|
|
: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 \\(...\\)
|
2022-12-30 18:00:22 +00:00
|
|
|
\"\\=\\[\" find math expressions surrounded by \\=\\[...\\]
|
|
|
|
:zoom when the image has associated font-relative height information,
|
|
|
|
the display size is scaled by this factor."
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
:group 'org-latex-preview
|
2022-12-27 02:08:24 +00:00
|
|
|
:package-version '(Org . "9.7")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:type 'plist)
|
|
|
|
|
|
|
|
(defcustom org-latex-to-mathml-jar-file nil
|
|
|
|
"Value of\"%j\" in `org-latex-to-mathml-convert-command'.
|
|
|
|
Use this to specify additional executable file say a jar file.
|
|
|
|
|
|
|
|
When using MathToWeb as the converter, specify the full-path to
|
|
|
|
your mathtoweb.jar file."
|
|
|
|
:group 'org-latex
|
|
|
|
:version "24.1"
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "None" nil)
|
|
|
|
(file :tag "JAR file" :must-match t)))
|
|
|
|
|
|
|
|
(defcustom org-latex-to-mathml-convert-command nil
|
|
|
|
"Command to convert LaTeX fragments to MathML.
|
|
|
|
Replace format-specifiers in the command as noted below and use
|
|
|
|
`shell-command' to convert LaTeX to MathML.
|
|
|
|
%j: Executable file in fully expanded form as specified by
|
|
|
|
`org-latex-to-mathml-jar-file'.
|
|
|
|
%I: Input LaTeX file in fully expanded form.
|
|
|
|
%i: Shell-escaped LaTeX fragment to be converted.
|
|
|
|
It must not be used inside a quoted argument, the result of %i
|
|
|
|
expansion inside a quoted argument is undefined.
|
|
|
|
%o: Output MathML file.
|
|
|
|
|
|
|
|
This command is used by `org-create-math-formula'.
|
|
|
|
|
|
|
|
When using MathToWeb as the converter, set this option to
|
|
|
|
\"java -jar %j -unicode -force -df %o %I\".
|
|
|
|
|
|
|
|
When using LaTeXML set this option to
|
|
|
|
\"latexmlmath %i --presentationmathml=%o\"."
|
|
|
|
:group 'org-latex
|
|
|
|
:version "24.1"
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "None" nil)
|
|
|
|
(string :tag "\nShell command")))
|
|
|
|
|
|
|
|
(defcustom org-latex-to-html-convert-command nil
|
|
|
|
"Shell command to convert LaTeX fragments to HTML.
|
|
|
|
This command is very open-ended: the output of the command will
|
|
|
|
directly replace the LaTeX fragment in the resulting HTML.
|
|
|
|
Replace format-specifiers in the command as noted below and use
|
|
|
|
`shell-command' to convert LaTeX to HTML.
|
|
|
|
%i: The LaTeX fragment to be converted (shell-escaped).
|
|
|
|
It must not be used inside a quoted argument, the result of %i
|
|
|
|
expansion inside a quoted argument is undefined.
|
|
|
|
|
|
|
|
For example, this could be used with LaTeXML as
|
|
|
|
\"latexmlc literal:%i --profile=math --preload=siunitx.sty 2>/dev/null\"."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.4")
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "None" nil)
|
|
|
|
(string :tag "Shell command")))
|
|
|
|
|
2022-12-27 02:08:24 +00:00
|
|
|
(defcustom org-latex-preview-default-process
|
|
|
|
(if (executable-find "dvisvgm") 'dvisvgm 'dvipng)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"The default process to convert LaTeX fragments to image files.
|
|
|
|
All available processes and theirs documents can be found in
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
`org-latex-preview-process-alist', which see."
|
|
|
|
:group 'org-latex-preview
|
2022-12-27 02:08:24 +00:00
|
|
|
:package-version '(Org . "9.7")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:type 'symbol)
|
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
;;;###autoload
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defcustom org-latex-preview-process-alist
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
'((dvipng
|
|
|
|
:programs ("latex" "dvipng")
|
|
|
|
:description "dvi > png"
|
|
|
|
:message "you need to install the programs: latex and dvipng."
|
|
|
|
:image-input-type "dvi"
|
|
|
|
:image-output-type "png"
|
2023-01-17 16:06:24 +00:00
|
|
|
:latex-compiler ("%l -interaction nonstopmode -output-directory %o %f")
|
|
|
|
:latex-precompiler ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
|
2023-01-03 08:39:06 +00:00
|
|
|
:image-converter ("dvipng --follow -D %D -T tight --depth --height -o %B-%%09d.png %f")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:transparent-image-converter
|
2023-01-03 08:39:06 +00:00
|
|
|
("dvipng --follow -D %D -T tight -bg Transparent --depth --height -o %B-%%09d.png %f"))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(dvisvgm
|
|
|
|
:programs ("latex" "dvisvgm")
|
|
|
|
:description "dvi > svg"
|
|
|
|
:message "you need to install the programs: latex and dvisvgm."
|
|
|
|
:image-input-type "dvi"
|
|
|
|
:image-output-type "svg"
|
2023-01-17 16:06:24 +00:00
|
|
|
:latex-compiler ("%l -interaction nonstopmode -output-directory %o %f")
|
|
|
|
:latex-precompiler ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
;; The --optimise, --clipjoin, and --relative flags cause dvisvgm to
|
|
|
|
;; do some extra work to tidy up the SVG output, but barely add to
|
2022-12-27 02:08:24 +00:00
|
|
|
;; the overall dvisvgm runtime (<1% increace, from testing).
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
:image-converter ("dvisvgm --page=1- --optimize --clipjoin --relative --no-fonts --bbox=preview -o %B-%%9p.svg %f"))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(imagemagick
|
2023-01-04 04:51:40 +00:00
|
|
|
:programs ("pdflatex" "convert")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:description "pdf > png"
|
|
|
|
:message "you need to install the programs: latex and imagemagick."
|
|
|
|
:image-input-type "pdf"
|
|
|
|
:image-output-type "png"
|
|
|
|
:latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o %f")
|
2023-01-09 02:49:01 +00:00
|
|
|
:latex-precompiler ("pdftex -output-directory %o -ini -jobname=%b \"&pdflatex\" mylatexformat.ltx %f")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:image-converter
|
2022-12-29 10:31:18 +00:00
|
|
|
("convert -density %D -trim -antialias %f -quality 100 %B-%%09d.png")))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Definitions of external processes for LaTeX previewing.
|
|
|
|
Org mode can use some external commands to generate TeX snippet's images for
|
|
|
|
previewing or inserting into HTML files, e.g., \"dvipng\". This variable tells
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
`org-latex-preview-create-image' how to call them.
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
|
|
|
The value is an alist with the pattern (NAME . PROPERTIES). NAME is a symbol.
|
|
|
|
PROPERTIES accepts the following attributes:
|
|
|
|
|
|
|
|
:programs list of strings, required programs.
|
|
|
|
:description string, describe the process.
|
|
|
|
:message string, message it when required programs cannot be found.
|
|
|
|
:image-input-type string, input file type of image converter (e.g., \"dvi\").
|
|
|
|
:image-output-type string, output file type of image converter (e.g., \"png\").
|
|
|
|
:post-clean list of strings, files matched are to be cleaned up once
|
|
|
|
the image is generated. When nil, the files with \".dvi\",
|
|
|
|
\".xdv\", \".pdf\", \".tex\", \".aux\", \".log\", \".svg\",
|
|
|
|
\".png\", \".jpg\", \".jpeg\" or \".out\" extension will
|
|
|
|
be cleaned up.
|
|
|
|
:latex-header list of strings, the LaTeX header of the snippet file.
|
|
|
|
When nil, the fallback value is used instead, which is
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
controlled by `org-latex-preview-preamble',
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
`org-latex-default-packages-alist' and
|
|
|
|
`org-latex-packages-alist', which see.
|
|
|
|
:latex-compiler list of LaTeX commands, as strings. Each of them is given
|
|
|
|
to the shell. Place-holders \"%t\", \"%b\" and \"%o\" are
|
|
|
|
replaced with values defined below.
|
|
|
|
:image-converter list of image converter commands strings. Each of them is
|
|
|
|
given to the shell and supports any of the following
|
|
|
|
place-holders defined below.
|
|
|
|
|
|
|
|
If set, :transparent-image-converter is used instead of :image-converter to
|
|
|
|
convert an image when the background color is nil or \"Transparent\".
|
|
|
|
|
2023-01-17 16:06:24 +00:00
|
|
|
Place-holders used by `:image-converter', `:latex-precompiler',
|
|
|
|
and `:latex-compiler':
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
|
|
|
%f input file name
|
|
|
|
%b base name of input file
|
|
|
|
%o base directory of input file
|
|
|
|
%O absolute output file name
|
|
|
|
|
2023-01-17 16:06:24 +00:00
|
|
|
Place-holders only used by `:latex-precompiler' and `:latex-compiler':
|
|
|
|
|
|
|
|
%l LaTeX compiler command string
|
|
|
|
%L LaTeX compiler command name
|
|
|
|
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
Place-holders only used by `:image-converter':
|
|
|
|
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
%D dpi, which is used to adjust image size by some processing commands."
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
:group 'org-latex-preview
|
2022-12-27 02:08:24 +00:00
|
|
|
:package-version '(Org . "9.7")
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:type '(alist :tag "LaTeX to image backends"
|
|
|
|
:value-type (plist)))
|
|
|
|
|
2023-01-17 16:06:24 +00:00
|
|
|
(defcustom org-latex-preview-compiler-command-map
|
|
|
|
'(("pdflatex" . "latex")
|
|
|
|
("xelatex" . "xelatex -no-pdf")
|
|
|
|
("lualatex" . "dvilualatex"))
|
|
|
|
"An alist mapping from each of `org-latex-compilers' to command strings.
|
|
|
|
Each key is a LaTeX compiler name, for each compiler in
|
|
|
|
`org-latex-compilers', and the value the command that should be used
|
|
|
|
when producing a preview (optionally including flags).
|
|
|
|
|
|
|
|
This should only ever be changed in the event that PDF, not DVI output
|
|
|
|
is required."
|
|
|
|
:group 'org-latex-preview
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type '(alist :tag "Compiler"
|
|
|
|
:value-type (string :type "command")))
|
|
|
|
|
2023-01-05 08:00:45 +00:00
|
|
|
(defcustom org-latex-preview-persist t
|
|
|
|
"Persist produced LaTeX previews across Emacs sessions.
|
|
|
|
|
|
|
|
When non-nil, org-persist is used to cache the fragments and
|
|
|
|
data. Otherwise, a temporary directory is used for images and
|
|
|
|
the data is stored in `org-latex-preview--table' for the duration
|
|
|
|
of the Emacs session."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type 'boolean)
|
|
|
|
|
2023-01-17 15:43:00 +00:00
|
|
|
(defcustom org-latex-preview-persist-expiry 7
|
|
|
|
"A homologue of `org-persist-default-expiry' for preview data.
|
|
|
|
This is only relevant when `org-latex-preview-persist' is non-nil."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type '(choice (const :tag "Never" never)
|
|
|
|
(const :tag "Always" nil)
|
|
|
|
(number :tag "Keep N days")
|
|
|
|
(function :tag "Function")))
|
|
|
|
|
2023-03-12 09:00:49 +00:00
|
|
|
(defcustom org-latex-preview-numbered nil
|
|
|
|
"Whether to calculate and apply correct equation numbering."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type 'boolean)
|
|
|
|
|
2023-01-09 05:12:52 +00:00
|
|
|
(defcustom org-latex-preview-processing-indicator 'fringe
|
|
|
|
"The style of visual indicator for LaTeX currently being processed.
|
|
|
|
This sets the method used to indicated that a LaTeX fragment is
|
|
|
|
currently being processed for display.
|
|
|
|
|
|
|
|
There are three recognised value symbols:
|
|
|
|
- nil, do not indicate fragment processing.
|
|
|
|
- face, apply a special face to fragments that are being processed.
|
|
|
|
You can customize the face `org-latex-preview-processing-face' to
|
|
|
|
change how it appears.
|
|
|
|
- fringe, apply a fringe marker to lines where fragments are being
|
|
|
|
processed."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "No indicator" nil)
|
|
|
|
(const :tag "Fringe marker" fringe)
|
|
|
|
(const :tag "Processing face" face)))
|
|
|
|
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(defface org-latex-preview-processing-face '((t :inherit shadow))
|
2023-01-09 05:12:52 +00:00
|
|
|
"Face applied to LaTeX fragments for which a preview is being generated.
|
|
|
|
|
|
|
|
See `org-latex-preview-processing-indicator'."
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
:group 'org-faces)
|
|
|
|
|
2023-01-04 04:27:22 +00:00
|
|
|
(defconst org-latex-preview--image-log "*Org Preview Convert Output*"
|
|
|
|
"Buffer name for Preview image conversion output.")
|
|
|
|
(defconst org-latex-preview--latex-log "*Org Preview LaTeX Output*"
|
|
|
|
"Buffer name for Preview LaTeX output.")
|
|
|
|
(defconst org-latex-preview--precompile-log "*Org Preview Preamble Precompilation*"
|
|
|
|
"Buffer name for Preview LaTeX output.")
|
|
|
|
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(defun org-format-latex-mathml-available-p ()
|
|
|
|
"Return t if `org-latex-to-mathml-convert-command' is usable."
|
|
|
|
(save-match-data
|
|
|
|
(when (and (boundp 'org-latex-to-mathml-convert-command)
|
|
|
|
org-latex-to-mathml-convert-command)
|
|
|
|
(let ((executable (car (split-string
|
|
|
|
org-latex-to-mathml-convert-command))))
|
|
|
|
(when (executable-find executable)
|
|
|
|
(if (string-match
|
|
|
|
"%j" org-latex-to-mathml-convert-command)
|
|
|
|
(file-readable-p org-latex-to-mathml-jar-file)
|
|
|
|
t))))))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defcustom org-latex-preview-preamble "\\documentclass{article}
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
\[DEFAULT-PACKAGES]
|
|
|
|
\[PACKAGES]
|
2023-01-17 01:45:31 +00:00
|
|
|
\\usepackage{xcolor}"
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"The document header used for processing LaTeX fragments.
|
|
|
|
It is imperative that this header make sure that no page number
|
|
|
|
appears on the page. The package defined in the variables
|
|
|
|
`org-latex-default-packages-alist' and `org-latex-packages-alist'
|
|
|
|
will either replace the placeholder \"[PACKAGES]\" in this
|
|
|
|
header, or they will be appended."
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
:group 'org-latex-preview
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
:type 'string)
|
|
|
|
|
2023-01-17 01:45:31 +00:00
|
|
|
(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)))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defcustom org-latex-preview-use-precompilation t
|
2022-12-26 20:15:07 +00:00
|
|
|
"Use LaTeX header precompilation when previewing fragments.
|
|
|
|
This causes a slight delay the first time `org-latex-pdf-process'
|
|
|
|
is called in a buffer, but subsequent calls will be faster.
|
|
|
|
|
|
|
|
This requires the LaTeX package \"mylatexformat\" to be installed."
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
:group 'org-latex-preview
|
2022-12-26 20:15:07 +00:00
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type 'boolean)
|
|
|
|
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(defcustom org-latex-preview-auto-generate t
|
|
|
|
"Whether `org-latex-preview-auto-mode' should apply to new fragments.
|
|
|
|
|
|
|
|
When non-nil, newly inserted/typed LaTeX fragments and
|
|
|
|
environments will be automatically previewed. Otherwise, only
|
|
|
|
existing LaTeX previews will be automatically hidden/shown on
|
|
|
|
cursor movement and regenerated after edits."
|
|
|
|
:group 'org-latex
|
|
|
|
:package-version '(Org . "9.7")
|
|
|
|
:type 'boolean)
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defconst org-latex-preview--tentative-math-re
|
2022-12-26 09:50:22 +00:00
|
|
|
"\\$\\|\\\\[([]\\|^[ \t]*\\\\begin{[A-Za-z0-9*]+}"
|
|
|
|
"Regexp whith will match all instances of LaTeX math.
|
|
|
|
Note that this will also produce false postives, and
|
|
|
|
`org-element-context' should be used to verify that matches are
|
|
|
|
indeed LaTeX fragments/environments.")
|
|
|
|
|
2023-01-07 03:49:20 +00:00
|
|
|
(defconst org-latex-preview--ignored-faces
|
|
|
|
'(org-indent)
|
|
|
|
"Faces that should not affect the color of preview overlays.")
|
|
|
|
|
2023-01-05 18:27:02 +00:00
|
|
|
(defun org-latex-preview--ensure-overlay (beg end)
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
"Build an overlay between BEG and END."
|
2023-01-05 18:27:02 +00:00
|
|
|
(let (ov)
|
|
|
|
(dolist (o (overlays-in beg end))
|
|
|
|
(when (eq (overlay-get o 'org-overlay-type)
|
|
|
|
'org-latex-overlay)
|
|
|
|
(if (or ov (not (and (= beg (overlay-start o))
|
|
|
|
(= end (overlay-end o)))))
|
|
|
|
(delete-overlay o)
|
|
|
|
(setq ov o)
|
|
|
|
;; Reset all potentially modified properties.
|
|
|
|
(overlay-put ov 'face nil)
|
2023-01-07 23:02:41 +00:00
|
|
|
(overlay-put ov 'help-echo nil) ;tooltip error display
|
|
|
|
(overlay-put ov 'before-string nil) ;error fringe marker
|
|
|
|
(overlay-put ov 'hidden-face nil) ;(re)store svg face
|
2023-01-05 18:27:02 +00:00
|
|
|
;; Do not set the display property of preview image
|
|
|
|
;; overlays to nil when ensuring that an overlay exists.
|
|
|
|
;; This causes flicker during regeneration as the the
|
|
|
|
;; underlying text is shown and then replaced with the new
|
|
|
|
;; image.
|
2023-01-07 23:02:41 +00:00
|
|
|
(overlay-put ov 'preview-image nil) ;(re)store image spec
|
|
|
|
(overlay-put ov 'preview-state nil) ;is fragment modified?
|
2023-01-05 18:27:02 +00:00
|
|
|
(overlay-put ov 'view-text nil))))
|
|
|
|
(unless ov
|
|
|
|
(setq ov (make-overlay beg end nil 'front-advance))
|
|
|
|
(overlay-put ov 'org-overlay-type 'org-latex-overlay)
|
|
|
|
(overlay-put ov 'evaporate t)
|
|
|
|
(overlay-put ov 'modification-hooks
|
|
|
|
(list #'org-latex-preview-auto--mark-overlay-modified))
|
|
|
|
(overlay-put ov 'insert-in-front-hooks
|
|
|
|
(list #'org-latex-preview-auto--insert-front-handler))
|
|
|
|
(overlay-put ov 'insert-behind-hooks
|
|
|
|
(list #'org-latex-preview-auto--insert-behind-handler)))
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
ov))
|
|
|
|
|
2023-01-09 05:12:52 +00:00
|
|
|
(defun org-latex-preview--indicate-processing (ov &optional on)
|
|
|
|
"Modify OV to provide visual indication of LaTeX fragment preview generation.
|
|
|
|
|
|
|
|
When `org-latex-preview-processing-indicator' is set to fringe, a
|
|
|
|
triangle in the left fringe will be shown or hidden depending on ON.
|
|
|
|
|
|
|
|
When `org-latex-preview-processing-indicator' is set to face, the
|
|
|
|
overlay face is set to `org-latex-preview-processing-face'."
|
|
|
|
(pcase org-latex-preview-processing-indicator
|
|
|
|
('fringe
|
|
|
|
(overlay-put
|
|
|
|
ov 'before-string
|
|
|
|
(and on (propertize "!" 'display
|
|
|
|
`(left-fringe right-triangle
|
|
|
|
fringe)))))
|
|
|
|
('face
|
|
|
|
(overlay-put ov 'face (and on 'org-latex-preview-processing-face)))))
|
|
|
|
|
2023-01-05 18:27:02 +00:00
|
|
|
(defun org-latex-preview-auto--mark-overlay-modified (ov after-p _beg _end &optional _l)
|
|
|
|
"When AFTER-P mark OV as modified and display nothing."
|
|
|
|
(when after-p
|
|
|
|
(overlay-put ov 'preview-state 'modified)
|
|
|
|
(overlay-put ov 'display nil)))
|
|
|
|
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(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))
|
|
|
|
(height (plist-get (cdr path-info) :height))
|
|
|
|
(depth (plist-get (cdr path-info) :depth))
|
2023-01-07 09:24:05 +00:00
|
|
|
(errors (plist-get (cdr path-info) :errors))
|
2023-01-07 23:02:41 +00:00
|
|
|
(image-type (plist-get (cdr path-info) :image-type))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(image-display
|
2023-01-03 17:18:34 +00:00
|
|
|
(and (car path-info)
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(list 'image
|
2023-01-07 23:02:41 +00:00
|
|
|
:type image-type
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
:file (car path-info)
|
|
|
|
:height (and height (cons (* height zoom) 'em))
|
|
|
|
:ascent (if (and depth height)
|
2023-01-03 08:39:51 +00:00
|
|
|
;; The baseline seems to tend to sit slightly
|
|
|
|
;; lower than it should be, and a very mild
|
|
|
|
;; bias seems to improve the visual result.
|
|
|
|
;; From testing with a collecting of LaTeX
|
|
|
|
;; maths fonts (cm, cmbright, arev, pxfonts,
|
|
|
|
;; notomath, nextxsf, eulervm) decreacing the
|
|
|
|
;; depth measurement by 0.02pt in the baseline
|
|
|
|
;; calculation seems to work well.
|
|
|
|
;; I have yet to come across any situation
|
|
|
|
;; where this results in a negative depth,
|
|
|
|
;; however we may as well ensure that never
|
|
|
|
;; occurs.
|
|
|
|
(round (* 100 (- 1 (/ (max 0.0 (- depth 0.02))
|
|
|
|
height))))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
'center)))))
|
2023-01-09 05:12:52 +00:00
|
|
|
(when org-latex-preview-processing-indicator
|
|
|
|
(org-latex-preview--indicate-processing ov))
|
2023-01-07 09:24:05 +00:00
|
|
|
;; This is a temporary measure until a more sophisticated
|
|
|
|
;; interface for errors is available in Org.
|
|
|
|
(when (and errors tooltip-mode)
|
|
|
|
(overlay-put ov 'help-echo errors))
|
2023-01-03 17:18:34 +00:00
|
|
|
(when image-display
|
|
|
|
(overlay-put ov 'display image-display)
|
|
|
|
(overlay-put ov 'preview-image image-display))
|
2023-01-07 23:02:41 +00:00
|
|
|
(cond
|
|
|
|
((eq image-type 'svg)
|
|
|
|
(overlay-put
|
|
|
|
ov 'face
|
|
|
|
(or (and errors 'error)
|
|
|
|
(and (> (overlay-start ov) (point-min))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(not (eq (char-before (overlay-start ov)) ?\n))
|
2023-01-07 03:49:20 +00:00
|
|
|
(let ((face (get-text-property (1- (overlay-start ov)) 'face)))
|
|
|
|
(cond
|
|
|
|
((consp face)
|
|
|
|
(cl-set-difference face org-latex-preview--ignored-faces))
|
|
|
|
((not (memq face org-latex-preview--ignored-faces))
|
|
|
|
face))))
|
2023-01-07 23:02:41 +00:00
|
|
|
'default)))
|
|
|
|
(errors
|
|
|
|
(overlay-put
|
|
|
|
ov 'before-string
|
|
|
|
(propertize "!" 'display
|
2023-01-09 05:12:52 +00:00
|
|
|
`(left-fringe exclamation-mark error)))))))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
;; Code for `org-latex-preview-auto-mode':
|
|
|
|
;;
|
|
|
|
;; The boundaries of latex preview image overlays are automatically
|
|
|
|
;; extended to track changes in the underlying text by the functions
|
|
|
|
;; `org-latex-preview-auto--insert-front-handler' and
|
2023-01-05 18:27:02 +00:00
|
|
|
;; `org-latex-preview-auto--insert-behind-handler'. These are placed in
|
|
|
|
;; the `insert-in-front-hooks' and `insert-behind-hooks' properties of
|
|
|
|
;; the iamge overlays. See (info "(elisp) Overlay Properties").
|
|
|
|
;; Additionally, when an overlay's text is modified,
|
|
|
|
;; `org-latex-preview-auto--mark-overlay-modified', placed in the overlay's
|
|
|
|
;; modification hook, notes this in the overlay's `preview-state'
|
|
|
|
;; property.
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
;;
|
|
|
|
;; This code examines the previous and current cursor
|
|
|
|
;; positions after each command. It uses the variables
|
|
|
|
;; `org-latex-preview-auto--from-overlay' and `org-latex-preview-auto--marker' to track
|
|
|
|
;; this.
|
|
|
|
;;
|
|
|
|
;; If the cursor has moved out of or into a latex preview overlay,
|
|
|
|
;; the overlay is changed to display or hide its image respectively.
|
|
|
|
;; The functions `org-latex-preview-auto--handle-pre-cursor' and
|
|
|
|
;; `org-latex-preview-auto--handle-post-cursor' do this. These are palced in
|
|
|
|
;; `pre-command-hook' and `post-command-hook' respectively.
|
|
|
|
;;
|
|
|
|
;; When the cursor positions pre- and post-command are inside an
|
|
|
|
;; overlay, it uses the overlay property `view-text' to check if the
|
|
|
|
;; source and destination overlays are distinct. If they are it shows
|
|
|
|
;; and hides images as appropriate.
|
|
|
|
;;
|
|
|
|
;; If the latex fragment text for an existing overlay is modified, a
|
|
|
|
;; new preview image will be generated automatically. The
|
|
|
|
;; modification state of the overlay is stored in the overlay property
|
|
|
|
;; `preview-state', and the function
|
|
|
|
;; `org-latex-preview-auto--close-previous-overlay' handles the recompilation.
|
|
|
|
;;
|
|
|
|
;; When the user option `org-latex-preview-auto-generate' is
|
2023-01-05 11:29:10 +00:00
|
|
|
;; non-nil, previews are auto-generated for latex fragments as they
|
|
|
|
;; are inserted into the buffer. This work is handled by
|
|
|
|
;; `org-latex-preview-auto--detect-fragments-in-change', which is added to
|
|
|
|
;; `after-change-functions'. It does this by placing dummy overlays
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
;; that don't display images, but are marked as having been modified.
|
|
|
|
|
|
|
|
(defvar-local org-latex-preview-auto--from-overlay nil
|
|
|
|
"Whether the cursor if starting from within a preview overlay.")
|
|
|
|
(defvar-local org-latex-preview-auto--marker (make-marker)
|
|
|
|
"Marker to keep track of the previous cursor position.
|
|
|
|
This helps with tracking cursor movement into and out of preview overlays.")
|
|
|
|
(defvar-local org-latex-preview-auto--inhibit nil
|
|
|
|
"Delay the state machine that decides to auto-generate preview fragments.")
|
|
|
|
|
|
|
|
(defsubst org-latex-preview-auto--move-into (ov)
|
|
|
|
"Adjust column when moving into the overlay OV from below."
|
|
|
|
(when (> (marker-position org-latex-preview-auto--marker)
|
|
|
|
(line-end-position))
|
|
|
|
(goto-char (overlay-end ov))
|
|
|
|
(goto-char (max (line-beginning-position)
|
|
|
|
(overlay-start ov)))))
|
|
|
|
|
|
|
|
(defun org-latex-preview-auto--handle-pre-cursor ()
|
|
|
|
"Record the previous state of the cursor position.
|
|
|
|
|
|
|
|
This keeps track of the cursor relative to the positions of
|
|
|
|
Org latex preview overlays.
|
|
|
|
|
|
|
|
This is intended to be placed in `pre-command-hook'."
|
|
|
|
(if org-latex-preview-auto--inhibit
|
|
|
|
(setq org-latex-preview-auto--inhibit nil)
|
|
|
|
(setq org-latex-preview-auto--from-overlay
|
|
|
|
(eq (get-char-property (point) 'org-overlay-type)
|
|
|
|
'org-latex-overlay))
|
|
|
|
(set-marker org-latex-preview-auto--marker (point))))
|
|
|
|
|
|
|
|
(defun org-latex-preview-auto--handle-post-cursor ()
|
|
|
|
"Toggle or generate LaTeX previews based on cursor movement.
|
|
|
|
|
|
|
|
If the cursor is moving into a preview overlay, \"open\" it to
|
|
|
|
display the underlying latex fragment. If the cursor is moving
|
|
|
|
out of a preview overlay, show the image again or generate a new
|
|
|
|
one as appropriate.
|
|
|
|
|
|
|
|
See `org-latex-preview-auto-generate' to customize this behavior.
|
|
|
|
|
|
|
|
This is intended to be placed in `post-command-hook'."
|
|
|
|
(let ((into-overlay-p (eq (get-char-property (point) 'org-overlay-type)
|
|
|
|
'org-latex-overlay)))
|
|
|
|
(cond
|
|
|
|
((and into-overlay-p org-latex-preview-auto--from-overlay)
|
|
|
|
(unless (get-char-property (point) 'view-text)
|
|
|
|
;; Jumped from overlay to overlay
|
|
|
|
(org-latex-preview-auto--close-previous-overlay)
|
|
|
|
(org-latex-preview-auto--open-this-overlay)))
|
|
|
|
((and into-overlay-p (not org-latex-preview-auto--from-overlay))
|
|
|
|
;; Moved into overlay
|
|
|
|
(org-latex-preview-auto--open-this-overlay))
|
|
|
|
(org-latex-preview-auto--from-overlay
|
|
|
|
;; Moved out of overlay
|
|
|
|
(org-latex-preview-auto--close-previous-overlay)))
|
|
|
|
(set-marker org-latex-preview-auto--marker (point))))
|
|
|
|
|
2023-01-05 11:29:10 +00:00
|
|
|
(defun org-latex-preview-auto--detect-fragments-in-change (beg end _)
|
|
|
|
"Examine the content between BEG and END, and preview LaTeX fragments found."
|
2023-01-21 20:59:51 +00:00
|
|
|
(when org-latex-preview-auto-generate
|
|
|
|
(let ((initial-point (point))
|
|
|
|
fragments)
|
|
|
|
(save-excursion
|
|
|
|
;; Find every location in the changed region where a backslash
|
|
|
|
;; is succeeded by a parenthesis or square bracket, and check
|
|
|
|
;; for a LaTeX fragment.
|
|
|
|
(goto-char beg)
|
|
|
|
(unless (eobp)
|
|
|
|
(while (search-forward "\\" end t)
|
|
|
|
(and (memq (char-after) '(?\( ?\) ?\[ ?\]))
|
2023-01-05 11:29:10 +00:00
|
|
|
(push (org-latex-preview-auto--maybe-track-element-here
|
2023-01-21 20:59:51 +00:00
|
|
|
'latex-fragment initial-point)
|
|
|
|
fragments))))
|
|
|
|
;; Find every location in the changed region where a parenthesis
|
|
|
|
;; or square bracket is preceeded by a backslash, and check for
|
|
|
|
;; a LaTeX fragment.
|
|
|
|
(goto-char beg)
|
|
|
|
(unless (bobp)
|
|
|
|
(while (re-search-forward "[][()]" end t)
|
|
|
|
(and (eq (char-before (1- (point))) ?\\)
|
|
|
|
(push (org-latex-preview-auto--maybe-track-element-here
|
|
|
|
'latex-fragment initial-point)
|
|
|
|
fragments))))
|
|
|
|
;; Check for LaTeX environments on lines affected by the change.
|
|
|
|
;; Start by finding all affected lines with at least four
|
|
|
|
;; characters of content. Then we can check if the line starts
|
|
|
|
;; with "\beg" or "\end", and if so check for a LaTeX environment.
|
|
|
|
(goto-char beg)
|
|
|
|
(beginning-of-line)
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(when (< (point) end)
|
|
|
|
(let ((line-start-positions
|
|
|
|
(and (> (point-max) (+ 4 (point)))
|
|
|
|
(list (point)))))
|
|
|
|
(while (and (< (point) end)
|
|
|
|
(search-forward "\n" end t))
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(when (> (point-max) (+ 4 (point)))
|
|
|
|
(push (point) line-start-positions)))
|
|
|
|
(dolist (line-start line-start-positions)
|
|
|
|
(goto-char line-start)
|
|
|
|
(and (eq (char-after) ?\\)
|
|
|
|
(member (buffer-substring (point) (+ (point) 4))
|
|
|
|
'("\\beg" "\\end"))
|
|
|
|
(push (org-latex-preview-auto--maybe-track-element-here
|
|
|
|
'latex-environment initial-point)
|
|
|
|
fragments))))))
|
|
|
|
(when (setq fragments (delq nil fragments))
|
|
|
|
(when (and org-latex-preview-numbered
|
|
|
|
(cl-find 'latex-environment fragments
|
2023-03-12 09:00:49 +00:00
|
|
|
:key #'org-element-type :test #'eq))
|
2023-01-21 20:59:51 +00:00
|
|
|
(setq fragments
|
|
|
|
(append fragments
|
|
|
|
(org-latex-preview--get-numbered-environments
|
|
|
|
end nil))))
|
2023-01-22 07:06:36 +00:00
|
|
|
(org-latex-preview--place-from-elements
|
2023-01-21 20:59:51 +00:00
|
|
|
org-latex-preview-default-process
|
|
|
|
fragments)))))
|
2023-01-05 11:29:10 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview-auto--maybe-track-element-here (type pos)
|
|
|
|
"Check for an org element of TYPE at `point' and ensure an overlay exists.
|
|
|
|
If POS lies within the element, nil is returned. Otherwise the
|
|
|
|
element is returned to be used to generate a preview.
|
|
|
|
|
|
|
|
If an org-latex-overlay is already present, nothing is done."
|
|
|
|
(and (not (eq (get-char-property (point) 'org-overlay-type)
|
|
|
|
'org-latex-overlay))
|
|
|
|
(when-let* ((element (org-element-context))
|
|
|
|
((eq (org-element-type element) type))
|
2023-01-30 03:20:36 +00:00
|
|
|
(elem-beg (or (org-element-property :post-affiliated element)
|
|
|
|
(org-element-property :begin element)))
|
2023-01-05 11:29:10 +00:00
|
|
|
(elem-end (- (org-element-property :end element)
|
|
|
|
(or (org-element-property :post-blank element) 0)
|
|
|
|
(if (eq (char-before (org-element-property :end element))
|
|
|
|
?\n)
|
|
|
|
1 0)))
|
2023-01-05 18:27:02 +00:00
|
|
|
(ov (org-latex-preview--ensure-overlay elem-beg elem-end)))
|
2023-01-05 11:29:10 +00:00
|
|
|
(overlay-put ov 'preview-state 'modified)
|
|
|
|
(if (<= elem-beg pos elem-end)
|
|
|
|
(progn
|
|
|
|
(overlay-put ov 'view-text t)
|
2023-01-21 21:03:10 +00:00
|
|
|
;; Record a position safely inside the created overlay
|
|
|
|
(set-marker org-latex-preview-auto--marker
|
|
|
|
(min pos (1- elem-end)))
|
2023-01-05 11:29:10 +00:00
|
|
|
(setq org-latex-preview-auto--from-overlay t)
|
|
|
|
nil)
|
|
|
|
(setq org-latex-preview-auto--inhibit t)
|
|
|
|
element))))
|
|
|
|
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(defun org-latex-preview-auto--open-this-overlay ()
|
|
|
|
"Open Org latex preview image overlays.
|
|
|
|
|
|
|
|
If there is a latex preview image overlay at point, hide the
|
|
|
|
image and display its text."
|
|
|
|
(dolist (ov (overlays-at (point)))
|
|
|
|
(when (eq (overlay-get ov 'org-overlay-type)
|
|
|
|
'org-latex-overlay)
|
|
|
|
(overlay-put ov 'display nil)
|
|
|
|
(overlay-put ov 'view-text t)
|
|
|
|
(when-let ((f (overlay-get ov 'face)))
|
|
|
|
(overlay-put ov 'hidden-face f)
|
|
|
|
(overlay-put ov 'face nil))
|
|
|
|
(org-latex-preview-auto--move-into ov)
|
|
|
|
(setq org-latex-preview-auto--from-overlay nil))))
|
|
|
|
|
|
|
|
(defun org-latex-preview-auto--close-previous-overlay ()
|
|
|
|
"Close Org latex preview image overlays.
|
|
|
|
|
|
|
|
If there is a latex preview image overlay at the previously
|
|
|
|
recorded cursor position, hide its text and display the
|
|
|
|
image. The preview image is regenerated if necessary."
|
|
|
|
(dolist (ov (overlays-at (marker-position org-latex-preview-auto--marker)))
|
|
|
|
(when (eq (overlay-get ov 'org-overlay-type) 'org-latex-overlay)
|
|
|
|
(overlay-put ov 'view-text nil)
|
|
|
|
(if (eq (overlay-get ov 'preview-state) 'modified)
|
|
|
|
;; It may seem odd to use an timer for this action, but by
|
|
|
|
;; introducing a brief window for Emacs to deal with input
|
|
|
|
;; events triggered during prior processing the perceptible
|
|
|
|
;; delay is reduced. Setting an 0.05s timer isn't
|
|
|
|
;; necesarily the optimal duration, but from a little
|
|
|
|
;; testing it appears to be fairly reasonable.
|
2023-01-05 23:02:48 +00:00
|
|
|
(run-at-time 0.05 nil #'org-latex-preview-auto--regenerate-overlay ov)
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(when-let (f (overlay-get ov 'hidden-face))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(unless (eq f 'org-latex-preview-processing-face)
|
|
|
|
(overlay-put ov 'face f))
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(overlay-put ov 'hidden-face nil))
|
|
|
|
(overlay-put ov 'display (overlay-get ov 'preview-image))))))
|
|
|
|
|
2023-01-05 23:02:48 +00:00
|
|
|
(defun org-latex-preview-auto--regenerate-overlay (ov)
|
|
|
|
"Regenerate the LaTeX fragment under overlay OV."
|
|
|
|
(with-current-buffer (overlay-buffer ov)
|
|
|
|
(let* ((fragment (save-excursion
|
|
|
|
(goto-char (overlay-start ov))
|
|
|
|
(org-element-context)))
|
|
|
|
(others (and org-latex-preview-numbered
|
|
|
|
(eq (org-element-type fragment) 'latex-environment)
|
|
|
|
(org-latex-preview--get-numbered-environments
|
|
|
|
(overlay-end ov) nil))))
|
2023-01-22 07:06:36 +00:00
|
|
|
(org-latex-preview--place-from-elements
|
2023-01-05 23:02:48 +00:00
|
|
|
org-latex-preview-default-process
|
|
|
|
(append (list fragment) others)))))
|
|
|
|
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(defun org-latex-preview-auto--insert-front-handler
|
|
|
|
(ov after-p _beg end &optional _length)
|
|
|
|
"Extend Org LaTeX preview text boundaries when editing previews.
|
|
|
|
|
|
|
|
OV is the overlay displaying the preview. For the meaning of
|
|
|
|
AFTER-P, END and the other arguments, see the
|
|
|
|
`modification-hooks' property of overlays in the Elisp
|
|
|
|
manual: (elisp) Overlay Properties."
|
|
|
|
(when after-p
|
|
|
|
(unless undo-in-progress
|
|
|
|
(if (eq (overlay-get ov 'preview-state) 'active)
|
|
|
|
(move-overlay ov end (overlay-end ov))))))
|
|
|
|
|
|
|
|
(defun org-latex-preview-auto--insert-behind-handler
|
|
|
|
(ov after-p beg _end &optional _length)
|
|
|
|
"Extend Org LaTeX preview text boundaries when editing previews.
|
|
|
|
|
|
|
|
OV is the overlay displaying the preview. For the meaning of
|
|
|
|
AFTER-P, BEG and the other arguments, see the
|
|
|
|
`modification-hooks' property of overlays in the Elisp
|
|
|
|
manual: (elisp) Overlay Properties."
|
|
|
|
(when after-p
|
|
|
|
(unless undo-in-progress
|
|
|
|
(if (eq (overlay-get ov 'preview-state) 'active)
|
|
|
|
(move-overlay ov (overlay-end ov) beg)))))
|
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
;;;###autoload
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(define-minor-mode org-latex-preview-auto-mode
|
|
|
|
"Minor mode to automatically preview LaTeX fragments.
|
|
|
|
|
|
|
|
When LaTeX preview auto mode is on, LaTeX fragments in Org buffers are
|
|
|
|
automatically previewed after being inserted, and hidden when the
|
|
|
|
cursor moves into them. This allows one to seamlessly edit and
|
|
|
|
preview LaTeX in Org buffers.
|
|
|
|
|
|
|
|
To enable auto-toggling of the preview images without auto-generating
|
|
|
|
them or vice-versa, customize the variable `org-latex-preview-auto-generate'."
|
|
|
|
:global nil
|
|
|
|
(if org-latex-preview-auto-mode
|
|
|
|
(progn
|
|
|
|
(add-hook 'pre-command-hook #'org-latex-preview-auto--handle-pre-cursor nil 'local)
|
|
|
|
(org-latex-preview-auto--handle-pre-cursor) ; Invoke setup before the hook even fires.
|
|
|
|
(add-hook 'post-command-hook #'org-latex-preview-auto--handle-post-cursor nil 'local)
|
2023-01-05 11:29:10 +00:00
|
|
|
(add-hook 'after-change-functions #'org-latex-preview-auto--detect-fragments-in-change nil 'local))
|
org-latex-preview: Add org-preview-latex-auto-mode
* lisp/org-latex-preview.el (org-latex-preview--make-overlay): Add
overlay hooks that correct for any edits made inside the overlay, and
store a copy of the image specification in the "preview-image" slot.
Also return the created overlay, so it can be used in other functions.
(org-latex-preview--from-overlay-p, org-latex-preview--marker,
org-latex-preview--inhibit): New variables to keep track of overlay
state when using auto-mode.
(org-latex-preview--handle-pre-cursor,
org-latex-preview--handle-post-cursor, org-latex-preview--move-into):
Detect when the cursor is entering or leaving a preview overlay, and
trigger the appropriate action.
(org-latex-preview--open-this-overlay,
org-latex-preview--close-previous-overlay): When cursor has entered/left
a preview overlay, show the text/image as appropriate.
(org-latex-preview--handle-insert): Create a dummy preview overlay when
a new LaTeX fragment is created.
(org-latex-preview--insert-front-handler,
org-preview--insert-behind-handler): Extend preview overlay boundaries
when their content changes.
(org-latex-preview-auto-mode): A new minor mode for automatic
opening/closing of preview overlays, and regeneration.
(org-latex-preview-auto-generate-p): Variable which affects the
regeneration behaviour of `org-latex-preview-auto-mode'.
2022-12-27 09:17:24 +00:00
|
|
|
(remove-hook 'pre-command-hook #'org-latex-preview-auto--handle-pre-cursor 'local)
|
|
|
|
(remove-hook 'post-command-hook #'org-latex-preview-auto--handle-post-cursor 'local)
|
2023-01-05 11:29:10 +00:00
|
|
|
(remove-hook 'after-change-functions #'org-latex-preview-auto--detect-fragments-in-change 'local)))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview-clear-overlays (&optional beg end)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Remove all overlays with LaTeX fragment images in current buffer.
|
|
|
|
When optional arguments BEG and END are non-nil, remove all
|
|
|
|
overlays between them instead. Return a non-nil value when some
|
|
|
|
overlays were removed, nil otherwise."
|
|
|
|
(let ((overlays
|
|
|
|
(cl-remove-if-not
|
|
|
|
(lambda (o) (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay))
|
|
|
|
(overlays-in (or beg (point-min)) (or end (point-max))))))
|
|
|
|
(mapc #'delete-overlay overlays)
|
|
|
|
overlays))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview--preview-region (beg end)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Preview LaTeX fragments between BEG and END.
|
|
|
|
BEG and END are buffer positions."
|
2022-12-26 09:50:22 +00:00
|
|
|
(org-latex-preview-fragments
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
org-latex-preview-default-process
|
2022-12-26 09:50:22 +00:00
|
|
|
beg end))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
;;;###autoload
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(defun org-latex-preview (&optional arg)
|
|
|
|
"Toggle preview of the LaTeX fragment at point.
|
|
|
|
|
|
|
|
If the cursor is on a LaTeX fragment, create the image and
|
|
|
|
overlay it over the source code, if there is none. Remove it
|
|
|
|
otherwise. If there is no fragment at point, display images for
|
|
|
|
all fragments in the current section. With an active region,
|
|
|
|
display images for all fragments in the region.
|
|
|
|
|
|
|
|
With a `\\[universal-argument]' prefix argument ARG, clear images \
|
|
|
|
for all fragments
|
|
|
|
in the current section.
|
|
|
|
|
|
|
|
With a `\\[universal-argument] \\[universal-argument]' prefix \
|
|
|
|
argument ARG, display image for all
|
|
|
|
fragments in the buffer.
|
|
|
|
|
|
|
|
With a `\\[universal-argument] \\[universal-argument] \
|
|
|
|
\\[universal-argument]' prefix argument ARG, clear image for all
|
|
|
|
fragments in the buffer."
|
|
|
|
(interactive "P")
|
|
|
|
(cond
|
|
|
|
((not (display-graphic-p)) nil)
|
|
|
|
;; Clear whole buffer.
|
|
|
|
((equal arg '(64))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(org-latex-preview-clear-overlays (point-min) (point-max))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(message "LaTeX previews removed from buffer"))
|
|
|
|
;; Preview whole buffer.
|
|
|
|
((equal arg '(16))
|
2023-01-04 04:27:22 +00:00
|
|
|
(org-latex-preview--preview-region (point-min) (point-max)))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
;; Clear current section.
|
|
|
|
((equal arg '(4))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(org-latex-preview-clear-overlays
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
(if (use-region-p)
|
|
|
|
(region-beginning)
|
|
|
|
(if (org-before-first-heading-p) (point-min)
|
|
|
|
(save-excursion
|
|
|
|
(org-with-limited-levels (org-back-to-heading t) (point)))))
|
|
|
|
(if (use-region-p)
|
|
|
|
(region-end)
|
|
|
|
(org-with-limited-levels (org-entry-end-position)))))
|
|
|
|
((use-region-p)
|
2023-01-04 04:27:22 +00:00
|
|
|
(org-latex-preview--preview-region (region-beginning) (region-end)))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
;; Toggle preview on LaTeX code at point.
|
|
|
|
((let ((datum (org-element-context)))
|
|
|
|
(and (memq (org-element-type datum) '(latex-environment latex-fragment))
|
2023-01-07 13:53:38 +00:00
|
|
|
(org-latex-preview--auto-aware-toggle datum))))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
;; Preview current section.
|
|
|
|
(t
|
|
|
|
(let ((beg (if (org-before-first-heading-p) (point-min)
|
|
|
|
(save-excursion
|
|
|
|
(org-with-limited-levels (org-back-to-heading t) (point)))))
|
|
|
|
(end (org-with-limited-levels (org-entry-end-position))))
|
2023-01-04 04:27:22 +00:00
|
|
|
(org-latex-preview--preview-region beg end)))))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
2023-01-07 13:53:38 +00:00
|
|
|
(defun org-latex-preview--auto-aware-toggle (datum)
|
|
|
|
"Toggle the preview of the LaTeX fragment/environment DATUM.
|
|
|
|
This is done with care to work nicely with `org-latex-preview-auto-mode',
|
|
|
|
should it be enabled."
|
2023-02-06 18:42:04 +00:00
|
|
|
(let* ((beg (org-element-property :begin datum))
|
|
|
|
(end (org-element-property :end datum))
|
|
|
|
(ov (cl-some
|
|
|
|
(lambda (o)
|
|
|
|
(and (eq (overlay-get o 'org-overlay-type)
|
|
|
|
'org-latex-overlay)
|
|
|
|
o))
|
|
|
|
(overlays-at beg))))
|
2023-01-07 13:53:38 +00:00
|
|
|
;; If using auto-mode, an overlay will already exist but
|
|
|
|
;; not be showing an image. We can detect this
|
|
|
|
;; situtation via the preview-state overlay property, and
|
|
|
|
;; in such cases the most reasonable action is to just
|
|
|
|
;; (re)generate the preview image.
|
2023-02-06 18:42:04 +00:00
|
|
|
(cond
|
|
|
|
;; When not using auto-mode.
|
|
|
|
((not org-latex-preview-auto-mode)
|
|
|
|
(if (org-latex-preview-clear-overlays beg end)
|
|
|
|
(message "LaTeX preview removed")
|
|
|
|
(org-latex-preview--place-from-elements
|
|
|
|
org-latex-preview-default-process (list datum))))
|
|
|
|
;; When using auto-mode, but no current preview.
|
|
|
|
((not ov)
|
|
|
|
(org-latex-preview--place-from-elements
|
|
|
|
org-latex-preview-default-process (list datum))
|
|
|
|
(message "Creating LaTeX preview"))
|
|
|
|
;; When on a just written/edited fragment that should be previewed.
|
|
|
|
((eq (overlay-get ov 'preview-state) 'modified)
|
|
|
|
(org-latex-preview-auto--regenerate-overlay ov)
|
|
|
|
(overlay-put ov 'view-text t))
|
|
|
|
;; When on an unmodified fragment that is currently showing an image,
|
|
|
|
;; clear the image.
|
|
|
|
((overlay-get ov 'display)
|
|
|
|
(org-latex-preview-clear-overlays beg end)
|
|
|
|
(message "LaTeX preview removed"))
|
|
|
|
;; Since we're on an unmodified fragment but not showing an image,
|
|
|
|
;; let's try to show the image if possible.
|
|
|
|
(ov
|
|
|
|
(overlay-put ov 'view-text t)
|
|
|
|
(overlay-put ov 'face (overlay-get ov 'hidden-face))
|
|
|
|
(overlay-put ov 'display (overlay-get ov 'preview-image))))))
|
2023-01-07 13:53:38 +00:00
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview-collect-fragments (&optional beg end)
|
2022-12-26 12:02:22 +00:00
|
|
|
"Collect all LaTeX maths fragments/environments between BEG and END."
|
|
|
|
(let (fragments)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (or beg (point-min)))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(while (re-search-forward org-latex-preview--tentative-math-re end t)
|
2022-12-26 12:02:22 +00:00
|
|
|
(let ((obj (org-element-context)))
|
2023-01-02 00:42:18 +00:00
|
|
|
(when (and (memq (org-element-type obj)
|
|
|
|
'(latex-fragment latex-environment))
|
|
|
|
;; Avoid duplicating nested latex environments
|
|
|
|
(not (and fragments
|
|
|
|
(= (org-element-property :begin obj)
|
|
|
|
(org-element-property :begin (car fragments))))))
|
2022-12-26 12:02:22 +00:00
|
|
|
(push obj fragments)))))
|
|
|
|
(nreverse fragments)))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview-replace-fragments (prefix processing-type &optional dir msg)
|
2022-12-26 09:50:22 +00:00
|
|
|
"Replace all LaTeX fragments in the buffer with export appropriate forms.
|
|
|
|
The way this is done is set by PROCESSING-TYPE, which can be either:
|
|
|
|
- verabtim, in which case nothing is done
|
|
|
|
- mathjax, in which case the TeX-style delimeters are replaced with
|
|
|
|
LaTeX-style delimeters.
|
|
|
|
- html, in which case the math fragment is replaced by the result of
|
|
|
|
`org-format-latex-as-html'.
|
|
|
|
- mathml, in which case the math fragment is replace by the result of
|
|
|
|
`org-format-latex-as-mathml'.
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
- an entry in `org-latex-preview-process-alist', in which case the
|
2022-12-26 10:49:33 +00:00
|
|
|
math fragment is replaced with `org-create-latex-export'.
|
2022-12-26 09:50:22 +00:00
|
|
|
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
Generated image files are placed in DIR with the prefix PREFIX.
|
|
|
|
Note that PREFIX may itself contain a directory path component.
|
2022-12-26 09:50:22 +00:00
|
|
|
|
|
|
|
When generating output files, MSG will be `message'd if given."
|
|
|
|
(let* ((cnt 0))
|
|
|
|
(save-excursion
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(dolist (element (org-latex-preview-collect-fragments))
|
2022-12-26 12:02:22 +00:00
|
|
|
(let ((block-type (eq (org-element-type element)
|
|
|
|
'latex-environment))
|
|
|
|
(value (org-element-property :value element))
|
|
|
|
(beg (org-element-property :begin element))
|
|
|
|
(end (save-excursion
|
|
|
|
(goto-char (org-element-property :end element))
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
(point))))
|
|
|
|
(cond
|
|
|
|
((eq processing-type 'verbatim)) ; Do nothing.
|
|
|
|
((eq processing-type 'mathjax)
|
|
|
|
;; Prepare for MathJax processing.
|
|
|
|
(if (not (string-match "\\`\\$\\$?" value))
|
|
|
|
(goto-char end)
|
|
|
|
(delete-region beg end)
|
|
|
|
(if (string= (match-string 0 value) "$$")
|
|
|
|
(insert "\\[" (substring value 2 -2) "\\]")
|
|
|
|
(insert "\\(" (substring value 1 -1) "\\)"))))
|
|
|
|
((eq processing-type 'html)
|
|
|
|
(goto-char beg)
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert (org-format-latex-as-html value)))
|
|
|
|
((eq processing-type 'mathml)
|
|
|
|
;; Process to MathML.
|
|
|
|
(unless (org-format-latex-mathml-available-p)
|
|
|
|
(user-error "LaTeX to MathML converter not configured"))
|
|
|
|
(cl-incf cnt)
|
|
|
|
(when msg (message msg cnt))
|
|
|
|
(goto-char beg)
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert (org-format-latex-as-mathml
|
|
|
|
value block-type prefix dir)))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
((assq processing-type org-latex-preview-process-alist)
|
2022-12-26 12:02:22 +00:00
|
|
|
(let ((image-dir (expand-file-name prefix dir)))
|
|
|
|
(unless (file-exists-p image-dir)
|
|
|
|
(make-directory image-dir t)))
|
|
|
|
(org-create-latex-export
|
|
|
|
processing-type element prefix dir block-type))
|
|
|
|
(t (error "Unknown conversion process %s for LaTeX fragments"
|
|
|
|
processing-type))))))))
|
2022-12-26 09:50:22 +00:00
|
|
|
|
2022-12-26 15:35:21 +00:00
|
|
|
(defun org-latex-preview-fragments (processing-type &optional beg end)
|
2022-12-26 09:50:22 +00:00
|
|
|
"Produce image overlays of LaTeX math fragments between BEG and END.
|
|
|
|
|
|
|
|
The LaTeX fragments are processed using PROCESSING-TYPE, a key of
|
|
|
|
`org-latex-preview-process-alist'.
|
|
|
|
|
|
|
|
If `point' is currently on an LaTeX overlay, then no overlays
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
will be generated. Since in practice `org-latex-preview-clear-overlays'
|
2022-12-26 09:50:22 +00:00
|
|
|
should have been called immediately prior to this function, this
|
|
|
|
situation should not occur in practice and mainly acts as
|
2022-12-26 15:35:21 +00:00
|
|
|
protection against placing doubled up overlays."
|
2022-12-26 09:50:22 +00:00
|
|
|
(when (fboundp 'clear-image-cache)
|
|
|
|
(clear-image-cache))
|
|
|
|
;; Optimize overlay creation: (info "(elisp) Managing Overlays").
|
|
|
|
(when (memq processing-type '(dvipng dvisvgm imagemagick))
|
|
|
|
(overlay-recenter (or end (point-max))))
|
|
|
|
(unless (eq (get-char-property (point) 'org-overlay-type)
|
|
|
|
'org-latex-overlay)
|
2023-01-02 09:58:17 +00:00
|
|
|
(let ((ws (window-start)))
|
|
|
|
(if (assq processing-type org-latex-preview-process-alist)
|
2023-01-22 07:06:36 +00:00
|
|
|
(org-latex-preview--place-from-elements
|
2023-01-02 09:58:17 +00:00
|
|
|
processing-type
|
|
|
|
(nconc (org-latex-preview-collect-fragments (max ws beg) end)
|
|
|
|
(when (< beg ws)
|
|
|
|
(org-latex-preview-collect-fragments beg (1- ws)))))
|
|
|
|
(error "Unknown conversion process %s for previewing LaTeX fragments"
|
|
|
|
processing-type)))))
|
2022-12-26 09:50:22 +00:00
|
|
|
|
2023-01-22 07:06:36 +00:00
|
|
|
(defun org-latex-preview--place-from-elements (processing-type elements)
|
2022-12-26 15:35:21 +00:00
|
|
|
"Preview LaTeX math fragments ELEMENTS using PROCESSING-TYPE."
|
2023-01-22 07:06:36 +00:00
|
|
|
(let* ((numbering-table (and org-latex-preview-numbered
|
2023-03-12 09:00:49 +00:00
|
|
|
(cl-find 'latex-environment elements
|
|
|
|
:key #'org-element-type :test #'eq)
|
|
|
|
(org-latex-preview--environment-numbering-table)))
|
2023-01-22 07:06:36 +00:00
|
|
|
(numbering-offsets
|
|
|
|
(and numbering-table
|
|
|
|
(mapcar
|
|
|
|
(lambda (element)
|
|
|
|
(and numbering-table
|
|
|
|
(eq (org-element-type element) 'latex-environment)
|
|
|
|
(gethash element numbering-table)))
|
|
|
|
elements)))
|
|
|
|
(entries
|
|
|
|
(mapcar
|
|
|
|
(lambda (element)
|
2023-01-30 03:20:36 +00:00
|
|
|
(list (or (org-element-property :post-affiliated element)
|
|
|
|
(org-element-property :begin element))
|
2023-01-22 07:06:36 +00:00
|
|
|
(- (org-element-property :end element)
|
|
|
|
(or (org-element-property :post-blank element) 0)
|
|
|
|
(if (eq (char-before (org-element-property :end element))
|
|
|
|
?\n)
|
|
|
|
1 0))
|
|
|
|
(org-element-property :value element)))
|
|
|
|
elements)))
|
|
|
|
(org-latex-preview-place processing-type entries numbering-offsets)))
|
|
|
|
|
2023-02-05 14:25:43 +00:00
|
|
|
;;;###autoload
|
2023-01-22 07:06:36 +00:00
|
|
|
(defun org-latex-preview-place (processing-type entries &optional numbering-offsets latex-preamble)
|
|
|
|
"Preview LaTeX math fragments ENTRIES using PROCESSING-TYPE.
|
|
|
|
Each entry of ENTRIES should be a list of 2-3 items, either
|
|
|
|
(BEG END), or
|
|
|
|
(BEG END VALUE)
|
|
|
|
Where BEG and END are the positions in the buffer, and the LaTeX previewed
|
|
|
|
is either the substring between BEG and END or (when provided) VALUE."
|
|
|
|
(let* ((processing-info
|
|
|
|
(cdr (assq processing-type org-latex-preview-process-alist)))
|
|
|
|
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
|
|
|
(numbering-offsets (cons nil numbering-offsets))
|
2023-01-03 17:35:22 +00:00
|
|
|
fragment-info prev-fg prev-bg)
|
2022-12-26 15:35:21 +00:00
|
|
|
(save-excursion
|
2023-01-22 07:06:36 +00:00
|
|
|
(dolist (entry entries)
|
|
|
|
(pcase-let* ((`(,beg ,end ,provided-value) entry)
|
|
|
|
(value (or provided-value
|
|
|
|
(buffer-substring-no-properties beg end)))
|
2023-01-04 02:57:05 +00:00
|
|
|
(`(,fg ,bg) (org-latex-preview--colors-at beg))
|
2023-01-22 07:06:36 +00:00
|
|
|
(number (car (setq numbering-offsets (cdr numbering-offsets))))
|
2023-01-04 02:57:05 +00:00
|
|
|
(hash (org-latex-preview--hash
|
2023-03-12 09:00:49 +00:00
|
|
|
processing-type value imagetype fg bg number))
|
2023-01-04 02:57:05 +00:00
|
|
|
(options (org-combine-plists
|
|
|
|
org-latex-preview-options
|
|
|
|
(list :foreground fg
|
|
|
|
:background bg
|
2023-03-12 09:00:49 +00:00
|
|
|
:number number
|
2023-01-04 02:57:05 +00:00
|
|
|
:continue-color
|
|
|
|
(and (equal prev-bg bg)
|
|
|
|
(equal prev-fg fg))))))
|
2022-12-30 07:52:48 +00:00
|
|
|
(if-let ((path-info (org-latex-preview--get-cached hash)))
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(org-latex-preview--update-overlay
|
2023-01-05 18:27:02 +00:00
|
|
|
(org-latex-preview--ensure-overlay beg end)
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
path-info)
|
2023-01-03 17:35:22 +00:00
|
|
|
(push (list :string (org-latex-preview--tex-styled
|
|
|
|
processing-type value options)
|
2023-01-05 18:27:02 +00:00
|
|
|
:overlay (org-latex-preview--ensure-overlay beg end)
|
2022-12-30 11:10:52 +00:00
|
|
|
:key hash)
|
2023-01-03 17:35:22 +00:00
|
|
|
fragment-info))
|
|
|
|
(setq prev-fg fg prev-bg bg))))
|
2023-02-06 09:40:16 +00:00
|
|
|
(when fragment-info
|
|
|
|
(org-latex-preview--create-image-async
|
|
|
|
processing-type
|
|
|
|
(nreverse fragment-info)
|
2023-02-25 05:28:36 +00:00
|
|
|
:latex-preamble latex-preamble
|
|
|
|
:place-preview-p t))))
|
2022-12-26 15:35:21 +00:00
|
|
|
|
2023-01-04 02:57:05 +00:00
|
|
|
(defun org-latex-preview--colors-at (pos)
|
|
|
|
"Find colors for LaTeX previews to be inserted at POS."
|
|
|
|
(let* ((face (or (and (> pos 1)
|
|
|
|
(get-text-property (1- pos) 'face))
|
|
|
|
'default))
|
|
|
|
(fg (pcase (plist-get org-latex-preview-options :foreground)
|
2023-01-06 15:56:04 +00:00
|
|
|
('auto
|
|
|
|
(org-latex-preview--resolved-faces-attr face :foreground))
|
2023-01-04 02:57:05 +00:00
|
|
|
('default (face-attribute 'default :foreground nil))
|
|
|
|
(color color)))
|
|
|
|
(bg (pcase (plist-get org-latex-preview-options :background)
|
2023-01-06 15:56:04 +00:00
|
|
|
('auto
|
|
|
|
(org-latex-preview--resolved-faces-attr face :background))
|
2023-01-04 02:57:05 +00:00
|
|
|
('default (face-attribute 'default :background nil))
|
|
|
|
(color color))))
|
|
|
|
(list fg bg)))
|
|
|
|
|
2023-01-06 15:56:04 +00:00
|
|
|
(defun org-latex-preview--resolved-faces-attr (face attr)
|
|
|
|
"Find ATTR of the FACE text property.
|
|
|
|
This is surprisingly complicated given the various forms of output
|
2023-01-07 03:49:20 +00:00
|
|
|
\\=(get-text-property pos \\='face) can produce.
|
|
|
|
|
|
|
|
Faces in `org-latex-preview--ignored-faces' are ignored."
|
|
|
|
(when (consp face)
|
|
|
|
(setq face (cl-set-difference face org-latex-preview--ignored-faces))
|
|
|
|
(when (= (length face) 1)
|
|
|
|
(setq face (car face))))
|
|
|
|
(cond
|
|
|
|
((not face)
|
|
|
|
(face-attribute 'default attr))
|
|
|
|
((not (consp face)) ; Spec like org-level-1.
|
|
|
|
(face-attribute face attr nil 'default))
|
|
|
|
((keywordp (car face)) ; Spec like (:inherit org-block :extend t).
|
|
|
|
(or (plist-get face attr)
|
|
|
|
(face-attribute 'default attr)))
|
|
|
|
((consp (car face)) ; Spec like ((:inherit default :extend t) org-block).
|
|
|
|
(or (plist-get (car face) attr)
|
|
|
|
(face-attribute (cadr face) attr nil
|
|
|
|
(append (cddr face) '(default)))))
|
|
|
|
((symbolp (car face)) ; Spec like (org-level-1 default).
|
|
|
|
(face-attribute (car face) attr nil (append (cdr face) '(default))))))
|
2023-01-06 15:56:04 +00:00
|
|
|
|
2023-03-12 09:00:49 +00:00
|
|
|
(defun org-latex-preview--hash (processing-type string imagetype fg bg &optional number)
|
2023-01-04 02:57:05 +00:00
|
|
|
"Return a SHA1 hash for referencing LaTeX fragments when previewing them.
|
|
|
|
|
|
|
|
PROCESSING-TYPE is the type of process used to create the
|
|
|
|
preview, see `org-latex-preview-default-process'.
|
|
|
|
|
|
|
|
PREAMBLE is the LaTeX preamble used in the generated LaTeX document.
|
|
|
|
|
|
|
|
STRING is the string to be hashed, typically the contents of a
|
|
|
|
LaTeX fragment.
|
|
|
|
|
|
|
|
IMAGETYPE is the type of image to be created, see
|
|
|
|
`org-latex-preview-process-alist'.
|
|
|
|
|
|
|
|
FG and BG are the foreground and background colors for the
|
2023-03-12 09:00:49 +00:00
|
|
|
image.
|
|
|
|
|
|
|
|
NUMBER is the equation number that should be used, if applicable."
|
2023-01-04 02:57:05 +00:00
|
|
|
(sha1 (prin1-to-string
|
|
|
|
(list processing-type
|
|
|
|
org-latex-preview-preamble
|
|
|
|
org-latex-default-packages-alist
|
|
|
|
org-latex-packages-alist
|
|
|
|
org-latex-preview-options
|
|
|
|
string
|
|
|
|
(if (equal imagetype "svg")
|
|
|
|
'svg fg)
|
2023-03-12 09:00:49 +00:00
|
|
|
bg
|
|
|
|
number))))
|
|
|
|
|
|
|
|
(defconst org-latex-preview--numbered-environments
|
|
|
|
'("equation" "eqnarray" "math" "displaymath" ; latex.ltx
|
|
|
|
"align" "gather" "multiline" "flalign" "alignat" ; amsmath.sty
|
|
|
|
"xalignat" "xxalignat" "subequations" ; amsmath.sty
|
|
|
|
"dmath" "dseries" "dgroup" "darray" ; breqn.sty
|
|
|
|
"empheq") ; empheq.sty
|
|
|
|
"List of LaTeX environments which produce numbered equations.")
|
|
|
|
|
2023-02-26 12:27:47 +00:00
|
|
|
(defun org-latex-preview--environment-numbering-table (&optional parse-tree)
|
|
|
|
"Creat a hash table from numbered equations to their initial index.
|
|
|
|
If the org-element cache is active or PARSE-TREE is provided, the
|
|
|
|
hash table will use `eq' equality, otherwise `equal' will be
|
|
|
|
used. When PARSE-TREE is provided, it is passed onto
|
|
|
|
`org-latex-preview--get-numbered-environments'."
|
|
|
|
(let ((table (make-hash-table :test (if (or parse-tree (org-element--cache-active-p))
|
2023-03-12 09:00:49 +00:00
|
|
|
#'eq #'equal)))
|
|
|
|
(counter 1))
|
|
|
|
(save-match-data
|
2023-02-26 12:27:47 +00:00
|
|
|
(dolist (element (org-latex-preview--get-numbered-environments
|
|
|
|
nil nil parse-tree))
|
2023-03-12 09:00:49 +00:00
|
|
|
(let ((content (org-element-property :value element)))
|
|
|
|
(puthash element counter table)
|
|
|
|
(if (string-match-p "\\`\\\\begin{[^}]*align" content)
|
|
|
|
(let ((beg (org-element-property :begin element))
|
|
|
|
(end (org-element-property :end element)))
|
|
|
|
(cl-incf counter (1+ (how-many "\\\\$" beg end)))
|
|
|
|
(cl-decf counter (how-many "\\nonumber" beg end))
|
|
|
|
(cl-decf counter (how-many "\\tag{" beg end)))
|
|
|
|
(unless (or (string-match-p "\\nonumber" content)
|
|
|
|
(string-match-p "\\tag{" content))
|
|
|
|
(cl-incf counter))))))
|
|
|
|
table))
|
|
|
|
|
2023-02-26 12:27:47 +00:00
|
|
|
(defun org-latex-preview--get-numbered-environments (&optional beg end parse-tree)
|
|
|
|
"Find all numbered environments between BEG and END.
|
|
|
|
If PARSE-TREE is provided, it will be used insead of
|
|
|
|
`org-element-cache-map' or `org-element-parse-buffer'."
|
|
|
|
(cond
|
|
|
|
(parse-tree
|
|
|
|
(org-element-map
|
|
|
|
parse-tree
|
|
|
|
'(latex-environment)
|
|
|
|
(lambda (datum)
|
|
|
|
(and (<= (or beg (point-min)) (org-element-property :begin datum)
|
|
|
|
(org-element-property :end datum) (or end (point-max)))
|
|
|
|
(let* ((content (org-element-property :value datum))
|
|
|
|
(env (and (string-match "\\`\\\\begin{\\([^}]+\\)}" content)
|
|
|
|
(match-string 1 content))))
|
|
|
|
(and (member env org-latex-preview--numbered-environments)
|
|
|
|
datum))))))
|
|
|
|
((org-element--cache-active-p)
|
|
|
|
(org-element-cache-map
|
2023-03-12 09:00:49 +00:00
|
|
|
(lambda (datum)
|
|
|
|
(and (<= (or beg (point-min)) (org-element-property :begin datum)
|
|
|
|
(org-element-property :end datum) (or end (point-max)))
|
|
|
|
(let* ((content (org-element-property :value datum))
|
|
|
|
(env (and (string-match "\\`\\\\begin{\\([^}]+\\)}" content)
|
|
|
|
(match-string 1 content))))
|
|
|
|
(and (member env org-latex-preview--numbered-environments)
|
|
|
|
datum))))
|
|
|
|
:granularity 'element
|
|
|
|
:restrict-elements '(latex-environment)
|
|
|
|
:from-pos beg
|
2023-02-26 12:27:47 +00:00
|
|
|
:to-pos (or end (point-max-marker))))
|
|
|
|
(t
|
2023-03-12 09:00:49 +00:00
|
|
|
(org-element-map
|
|
|
|
(org-element-parse-buffer 'element)
|
|
|
|
'(latex-environment)
|
|
|
|
(lambda (datum)
|
|
|
|
(and (<= (or beg (point-min)) (org-element-property :begin datum)
|
|
|
|
(org-element-property :end datum) (or end (point-max)))
|
|
|
|
(let* ((content (org-element-property :value datum))
|
|
|
|
(env (and (string-match "\\`\\\\begin{\\([^}]+\\)}" content)
|
|
|
|
(match-string 1 content))))
|
|
|
|
(and (member env org-latex-preview--numbered-environments)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (org-element-property :begin datum))
|
2023-02-26 12:27:47 +00:00
|
|
|
(org-element-context))))))))))
|
2023-01-04 02:57:05 +00:00
|
|
|
|
2023-02-25 05:28:36 +00:00
|
|
|
(cl-defun org-latex-preview--create-image-async (processing-type fragments-info &key latex-processor latex-preamble place-preview-p)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
"Preview PREVIEW-STRINGS asynchronously with method PROCESSING-TYPE.
|
2022-12-26 15:35:21 +00:00
|
|
|
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
FRAGMENTS-INFO is a list of plists, each of which provides
|
|
|
|
information on an individual fragment and should have the
|
|
|
|
following structure:
|
|
|
|
(:string fragment-string :overlay fragment-overlay :key fragment-hash)
|
|
|
|
where
|
|
|
|
- fragment-string is the literal content of the fragment
|
|
|
|
- fragment-overlay is the overlay placed for the fragment
|
|
|
|
- fragment-hash is a string that uniquely identifies the fragment
|
2022-12-26 15:35:21 +00:00
|
|
|
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
It is worth noting the FRAGMENTS-INFO plists will be modified
|
2023-01-17 16:06:24 +00:00
|
|
|
during processing to hold more information on the fragments.
|
|
|
|
|
2023-02-25 05:28:36 +00:00
|
|
|
When PLACE-PREVIEW-P is true, it will be set in the extended info
|
|
|
|
plist passed to filters, and is expected to result in the newly
|
|
|
|
generated fragment image being placed in the buffer.
|
|
|
|
|
2023-01-22 07:06:36 +00:00
|
|
|
LATEX-PROCESSOR is a member of `org-latex-compilers' which is guessed if unset.
|
|
|
|
|
|
|
|
When provided, LATEX-PREAMBLE overrides the default LaTeX preamble."
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(let* ((processing-type
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(or processing-type org-latex-preview-default-process))
|
2023-01-17 16:06:24 +00:00
|
|
|
(latex-processor
|
|
|
|
(or latex-processor
|
|
|
|
(and (derived-mode-p 'org-mode)
|
|
|
|
(cdr (assoc "LATEX_COMPILER"
|
|
|
|
(org-collect-keywords
|
|
|
|
'("LATEX_COMPILER") '("LATEX_COMPILER")))))
|
|
|
|
org-latex-compiler))
|
2022-12-26 15:35:21 +00:00
|
|
|
(processing-info
|
2023-01-22 07:06:36 +00:00
|
|
|
(nconc (list :latex-processor latex-processor
|
|
|
|
:latex-header latex-preamble)
|
2023-01-17 16:06:24 +00:00
|
|
|
(alist-get processing-type org-latex-preview-process-alist)))
|
2022-12-26 15:35:21 +00:00
|
|
|
(programs (plist-get processing-info :programs))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(error-message (or (plist-get processing-info :message) "")))
|
2023-01-17 16:06:24 +00:00
|
|
|
;; xelatex produces .xdv (eXtended dvi) files, not .dvi, so as a special
|
|
|
|
;; case we check for xelatex + dvi and if so switch the file extension to xdv.
|
|
|
|
(when (and (equal latex-processor "xelatex")
|
|
|
|
(equal (plist-get processing-info :image-input-type) "dvi"))
|
|
|
|
(setq processing-info
|
|
|
|
(plist-put (copy-sequence processing-info) :image-input-type "xdv")))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(dolist (program programs)
|
|
|
|
(org-check-external-command program error-message))
|
2023-01-09 05:12:52 +00:00
|
|
|
(when org-latex-preview-processing-indicator
|
|
|
|
(dolist (fragment fragments-info)
|
|
|
|
(org-latex-preview--indicate-processing
|
|
|
|
(plist-get fragment :overlay) 'on)))
|
2023-01-07 13:38:47 +00:00
|
|
|
;; At this point we will basically construct a tree of async calls:
|
|
|
|
;;
|
|
|
|
;; dvisvgm case:
|
|
|
|
;; └─ Compile tex file ⟶ stdout to `org-latex-preview--latex-preview-filter'
|
|
|
|
;; └─ (success or failure)
|
|
|
|
;; └─Extact images ⟶ stdout to `org-latex-preview--dvisvgm-filter'
|
|
|
|
;; ├─ (success)
|
|
|
|
;; │ ├─ Call `org-latex-preview--check-all-fragments-produced',
|
|
|
|
;; │ │ which can rerun the async tree if needed.
|
2023-02-06 09:40:16 +00:00
|
|
|
;; │ └─ Delete tempfiles (`org-latex-preview--cleanup-callback').
|
2023-01-07 13:38:47 +00:00
|
|
|
;; └─ (failure)
|
|
|
|
;; ├─ Run `org-latex-preview--failure-callback' (remove overlays).
|
|
|
|
;; └─ Message "creating latex previews... failed. please see %s for details".
|
|
|
|
;;
|
|
|
|
;; dvipng case:
|
|
|
|
;; ├─ Compile tex file ⟶ stdout to `org-latex-preview--latex-preview-filter'
|
|
|
|
;; └─ Extract images ("--follow" tex ouput) ⟶ stdout to `org-latex-preview--dvipng-filter'
|
|
|
|
;; ├─ (success)
|
|
|
|
;; │ ├─ Call `org-latex-preview--check-all-fragments-produced',
|
|
|
|
;; │ │ which can rerun the async tree if needed.
|
2023-02-06 09:40:16 +00:00
|
|
|
;; │ └─ Delete tempfiles (`org-latex-preview--cleanup-callback')
|
2023-01-07 13:38:47 +00:00
|
|
|
;; └─ (failure)
|
|
|
|
;; ├─ Run `org-latex-preview--failure-callback' (remove overlays).
|
|
|
|
;; └─ Message "creating latex previews... failed. please see %s for details".
|
|
|
|
;;
|
|
|
|
;; generic case:
|
|
|
|
;; └─ Compile tex file ⟶ stdout to `org-latex-preview--latex-preview-filter'
|
|
|
|
;; └─ (success or failure)
|
|
|
|
;; └─Extact images
|
|
|
|
;; ├─ (success)
|
2023-01-21 23:31:38 +00:00
|
|
|
;; │ ├─ Call `org-latex-preview--generic-callback'.
|
|
|
|
;; │ ├─ Delete tempfiles (`org-latex-preview--cleanup-callback')
|
2023-02-06 09:40:16 +00:00
|
|
|
;; │ └─ Call `org-latex-preview--check-all-fragments-produced',
|
|
|
|
;; │ which can rerun the async tree if needed.
|
2023-01-07 13:38:47 +00:00
|
|
|
;; └─ (failure)
|
|
|
|
;; ├─ Run `org-latex-preview--failure-callback' (remove overlays).
|
|
|
|
;; └─ Message "creating latex previews... failed. please see %s for details".
|
|
|
|
;;
|
|
|
|
;; With continuous, synchronous processing:
|
|
|
|
;;
|
|
|
|
;; ⟶ stdout to `org-latex-preview--latex-preview-filter'
|
|
|
|
;; ├─ read preview fontsize
|
|
|
|
;; └─ capture compilation errors
|
|
|
|
;;
|
|
|
|
;; ⟶ stdout to `org-latex-preview--dvisvgm-filter'
|
|
|
|
;; ├─ read preview image metadata
|
|
|
|
;; ├─ edit svgs and adjust colors
|
|
|
|
;; ├─ cache svgs with org-persist or in /tmp
|
|
|
|
;; └─ update overlays in buffer with svg images and metadata
|
|
|
|
;;
|
|
|
|
;; ⟶ stdout to `org-latex-preview--dvipng-filter'
|
|
|
|
;; ├─ read preview image metadata
|
|
|
|
;; ├─ cache pngs with org-persist or in /tmp
|
|
|
|
;; └─ update overlays in buffer with png images and metadata
|
|
|
|
;;
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(let* ((extended-info
|
|
|
|
(append processing-info
|
2023-01-03 17:35:22 +00:00
|
|
|
(list :processor processing-type
|
|
|
|
:fragments fragments-info
|
2022-12-30 18:00:22 +00:00
|
|
|
:org-buffer (current-buffer)
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
:texfile (org-latex-preview--create-tex-file
|
2023-02-25 05:28:36 +00:00
|
|
|
processing-info fragments-info)
|
|
|
|
:place-preview-p place-preview-p)))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(tex-compile-async
|
|
|
|
(org-latex-preview--tex-compile-async extended-info))
|
|
|
|
(img-extract-async
|
|
|
|
(org-latex-preview--image-extract-async extended-info)))
|
2022-12-30 18:00:22 +00:00
|
|
|
(plist-put (cddr img-extract-async) :success
|
2023-01-03 17:24:06 +00:00
|
|
|
(list ; The order is important here.
|
|
|
|
#'org-latex-preview--check-all-fragments-produced
|
2023-02-06 09:40:16 +00:00
|
|
|
#'org-latex-preview--cleanup-callback))
|
2023-01-04 04:16:39 +00:00
|
|
|
(plist-put (cddr img-extract-async) :failure
|
2023-01-04 04:27:22 +00:00
|
|
|
(list
|
|
|
|
#'org-latex-preview--failure-callback
|
|
|
|
(format "Creating LaTeX previews... failed. Please see %s for details"
|
|
|
|
(propertize org-latex-preview--image-log 'face 'warning))))
|
2022-12-30 18:00:22 +00:00
|
|
|
(pcase processing-type
|
2023-01-03 08:39:06 +00:00
|
|
|
('dvipng
|
|
|
|
(plist-put (cddr img-extract-async) :filter
|
|
|
|
#'org-latex-preview--dvipng-filter))
|
2022-12-30 18:00:22 +00:00
|
|
|
('dvisvgm
|
|
|
|
(plist-put (cddr img-extract-async) :filter
|
|
|
|
#'org-latex-preview--dvisvgm-filter))
|
|
|
|
(_
|
|
|
|
(plist-put (cddr img-extract-async) :success
|
2023-01-21 23:31:38 +00:00
|
|
|
(list ; The order is important here.
|
|
|
|
#'org-latex-preview--generic-callback
|
|
|
|
#'org-latex-preview--cleanup-callback
|
2023-02-06 09:40:16 +00:00
|
|
|
#'org-latex-preview--check-all-fragments-produced))))
|
2022-12-27 18:11:03 +00:00
|
|
|
(if (and (eq processing-type 'dvipng)
|
2022-12-29 17:48:30 +00:00
|
|
|
(member "--follow" (cadr img-extract-async)))
|
|
|
|
(org-async-call img-extract-async)
|
|
|
|
(plist-put (cddr tex-compile-async) :success img-extract-async)
|
|
|
|
(plist-put (cddr tex-compile-async) :failure img-extract-async))
|
|
|
|
(org-async-call tex-compile-async))))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
|
2023-01-04 04:16:39 +00:00
|
|
|
(defun org-latex-preview--failure-callback (_exit _buf extended-info)
|
|
|
|
"Clear overlays corresponding to previews that failed to generate.
|
|
|
|
|
|
|
|
EXTENDED-INFO contains the information needed to identify such
|
|
|
|
previews."
|
|
|
|
(cl-loop for fragment in (plist-get extended-info :fragments)
|
|
|
|
for path = (plist-get fragment :path)
|
|
|
|
when (not path)
|
|
|
|
for ov = (plist-get fragment :overlay)
|
2023-01-05 18:27:02 +00:00
|
|
|
when ov do
|
2023-01-04 04:16:39 +00:00
|
|
|
;; ;TODO: Other options here include:
|
|
|
|
;; ;Fringe marker
|
|
|
|
;; (overlay-put ov 'before-string
|
|
|
|
;; (propertize "!" 'display
|
|
|
|
;; `(left-fringe exclamation-mark
|
|
|
|
;; warning)))
|
|
|
|
;; ;Special face
|
|
|
|
;; (unless (overlay-get ov 'face)
|
|
|
|
;; (overlay-put ov 'face 'org-latex-preview-processing-face))
|
|
|
|
;;
|
|
|
|
;; ;Note: ov has buffer extended-info, no need to set current-buffer
|
|
|
|
(delete-overlay ov)))
|
|
|
|
|
2023-02-05 08:24:19 +00:00
|
|
|
(defvar-local org-latex-preview--preamble-content nil
|
|
|
|
"Cache of the LaTeX preamble for snippet preview.")
|
|
|
|
|
|
|
|
(defun org-latex-preview--clear-preamble-cache ()
|
|
|
|
"Set `org-latex-preview--preamble-content' to nil."
|
|
|
|
(setq org-latex-preview--preamble-content nil))
|
|
|
|
|
|
|
|
(add-hook 'org-mode-hook #'org-latex-preview--clear-preamble-cache)
|
|
|
|
|
|
|
|
(defun org-latex-preview--get-preamble (&optional buf)
|
|
|
|
"Obtain the LaTeX preview for snippet preview in BUF."
|
|
|
|
(with-current-buffer (or buf (current-buffer))
|
|
|
|
(org-fold-core-ignore-modifications
|
|
|
|
(let ((info (org-combine-plists
|
|
|
|
(org-export--get-export-attributes
|
|
|
|
(org-export-get-backend 'latex))
|
|
|
|
(org-export--get-buffer-attributes)
|
|
|
|
'(:time-stamp-file nil)))
|
|
|
|
org-export-use-babel
|
2023-03-12 10:12:46 +00:00
|
|
|
org-latex-precompile
|
2023-02-06 18:41:42 +00:00
|
|
|
;; (org-latex-conditional-features
|
|
|
|
;; (cl-remove-if
|
|
|
|
;; (lambda (feat)
|
|
|
|
;; (plist-get (alist-get (cdr feat)
|
|
|
|
;; org-latex-feature-implementations)
|
|
|
|
;; :not-preview))
|
|
|
|
;; org-latex-conditional-features))
|
|
|
|
)
|
2023-02-05 08:24:19 +00:00
|
|
|
(org-export-with-buffer-copy
|
|
|
|
:drop-narrowing t
|
|
|
|
(font-lock-mode -1)
|
|
|
|
(setq info
|
|
|
|
(org-export--annotate-info (org-export-get-backend 'latex) info))
|
2023-03-12 10:12:46 +00:00
|
|
|
(org-latex-make-preamble
|
2023-02-05 08:24:19 +00:00
|
|
|
(org-combine-plists
|
|
|
|
(org-export-get-environment
|
|
|
|
(org-export-get-backend 'latex))
|
|
|
|
'(:time-stamp-file nil))
|
|
|
|
org-latex-preview-preamble 'snippet))))))
|
|
|
|
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(defun org-latex-preview--create-tex-file (processing-info fragments)
|
|
|
|
"Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS.
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
|
|
|
|
More specifically, a preamble will be generated based on
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
PROCESSING-INFO. Then, if `org-latex-preview-use-precompilation' is
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
non-nil, a precompiled format file will be generated if needed
|
|
|
|
and used. Otherwise the preamble is used normally.
|
|
|
|
|
|
|
|
Within the body of the created LaTeX file, each of
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
FRAGMENTS will be placed in order, wrapped within a
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
\"preview\" environment.
|
|
|
|
|
|
|
|
The path of the created LaTeX file is returned."
|
|
|
|
(let ((tex-temp-name
|
2023-01-09 03:31:33 +00:00
|
|
|
(expand-file-name (concat (make-temp-name "org-tex-") ".tex")))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(header
|
|
|
|
(concat
|
|
|
|
(or (plist-get processing-info :latex-header)
|
2023-02-05 08:24:19 +00:00
|
|
|
org-latex-preview--preamble-content
|
|
|
|
(setq org-latex-preview--preamble-content
|
|
|
|
(org-latex-preview--get-preamble)))
|
2023-01-17 01:45:31 +00:00
|
|
|
(let ((w org-latex-preview-width))
|
|
|
|
(cond
|
|
|
|
((stringp w)
|
|
|
|
(format "\n\\setlength{\\textwidth}{%s}\n" w))
|
|
|
|
((and (floatp w) (<= 0.0 w 1.0))
|
|
|
|
(format "\n\\setlength{\\textwidth}{%s\\paperwidth}\n" w))))
|
2023-02-04 08:58:58 +00:00
|
|
|
"\n\\usepackage[active,tightpage,auctex]{preview}\n"))
|
|
|
|
(write-region-inhibit-fsync t)
|
|
|
|
(coding-system-for-write buffer-file-coding-system))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(with-temp-file tex-temp-name
|
2023-01-03 17:31:22 +00:00
|
|
|
(insert (if-let ((format-file
|
|
|
|
(and org-latex-preview-use-precompilation
|
|
|
|
(org-latex-preview-precompile processing-info header))))
|
2023-02-12 07:20:30 +00:00
|
|
|
(concat "%& " (file-name-sans-extension format-file))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
header))
|
2023-02-02 16:18:22 +00:00
|
|
|
;; The \abovedisplayskip length must be set after \begin{document} because
|
|
|
|
;; it is usually set during the font size intialisation that occurs at
|
|
|
|
;; \begin{document}. We can either modify the \normalsize command to set
|
|
|
|
;; the \abovedisplayskip length, or just set it after \begin{document}.
|
|
|
|
(insert "\n\\begin{document}\n\n"
|
|
|
|
"\\setlength\\abovedisplayskip{0pt}"
|
|
|
|
" % Remove padding before equation environments.\n\n")
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(dolist (fragment-info fragments)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(insert
|
|
|
|
"\n\\begin{preview}\n"
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
(plist-get fragment-info :string)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
"\n\\end{preview}\n"))
|
|
|
|
(insert "\n\\end{document}\n"))
|
|
|
|
tex-temp-name))
|
|
|
|
|
|
|
|
(defun org-latex-preview--tex-compile-async (extended-info)
|
|
|
|
"Create an `org-async-call' spec to compile the texfile in EXTENDED-INFO."
|
|
|
|
(let* ((tex-process-buffer
|
|
|
|
(with-current-buffer
|
2023-01-04 04:27:22 +00:00
|
|
|
(get-buffer-create org-latex-preview--latex-log)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(erase-buffer)
|
|
|
|
(current-buffer)))
|
2023-01-17 16:06:24 +00:00
|
|
|
(tex-compile-command-fmt
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(pcase (plist-get extended-info :latex-compiler)
|
|
|
|
((and (pred stringp) cmd) cmd)
|
|
|
|
((and (pred consp) cmds)
|
|
|
|
(when (> (length cmds) 1)
|
|
|
|
(warn "Preview :latex-compiler must now be a single command. %S will be ignored."
|
|
|
|
(cdr cmds)))
|
|
|
|
(car cmds))))
|
|
|
|
(texfile (plist-get extended-info :texfile))
|
2023-01-17 16:06:24 +00:00
|
|
|
(org-tex-compiler
|
|
|
|
(cdr (assoc (plist-get extended-info :latex-processor)
|
|
|
|
org-latex-preview-compiler-command-map)))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(tex-command-spec
|
2023-01-08 09:35:03 +00:00
|
|
|
`((?o . ,(shell-quote-argument temporary-file-directory))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(?b . ,(shell-quote-argument (file-name-base texfile)))
|
2023-01-17 16:06:24 +00:00
|
|
|
(?f . ,(shell-quote-argument texfile))
|
|
|
|
(?l . ,org-tex-compiler)
|
|
|
|
(?L . ,(car (split-string org-tex-compiler)))))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(tex-formatted-command
|
|
|
|
(split-string-shell-command
|
2023-01-17 16:06:24 +00:00
|
|
|
(format-spec tex-compile-command-fmt tex-command-spec))))
|
|
|
|
(unless org-tex-compiler
|
|
|
|
(user-error "No `org-latex-preview-compiler-command-map' entry found for LaTeX processor %S, it should be a member of `org-latex-compilers' %S"
|
|
|
|
(plist-get extended-info :latex-processor)
|
|
|
|
org-latex-compilers))
|
2022-12-29 17:48:30 +00:00
|
|
|
(list 'org-async-task
|
|
|
|
tex-formatted-command
|
|
|
|
:buffer tex-process-buffer
|
|
|
|
:info extended-info
|
2022-12-30 18:42:05 +00:00
|
|
|
:filter #'org-latex-preview--latex-preview-filter
|
2022-12-29 17:48:30 +00:00
|
|
|
:failure "LaTeX compilation for preview failed! (error code %d)")))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview--image-extract-async (extended-info)
|
|
|
|
"Create an `org-async-call' spec to extract images according to EXTENDED-INFO."
|
|
|
|
(let* ((img-process-buffer
|
|
|
|
(with-current-buffer
|
2023-01-04 04:27:22 +00:00
|
|
|
(get-buffer-create org-latex-preview--image-log)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(erase-buffer)
|
|
|
|
(current-buffer)))
|
|
|
|
(img-extract-command
|
|
|
|
(pcase
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(or (and (string= (plist-get org-latex-preview-options :background)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
"Transparent")
|
|
|
|
(plist-get extended-info :transparent-image-converter))
|
|
|
|
(plist-get extended-info :image-converter))
|
|
|
|
((and (pred stringp) cmd) cmd)
|
|
|
|
((and (pred consp) cmds)
|
|
|
|
(when (> (length cmds) 1)
|
|
|
|
(warn "Preview converter must now be a single command. %S will be ignored."
|
|
|
|
(cdr cmds)))
|
|
|
|
(car cmds))))
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
(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)
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(org-latex-preview--get-display-dpi)
|
|
|
|
140.0)))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(texfile (plist-get extended-info :texfile))
|
2023-01-09 03:24:55 +00:00
|
|
|
(texfile-base (file-name-base texfile))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(img-command-spec
|
2023-01-08 09:35:03 +00:00
|
|
|
`((?o . ,(shell-quote-argument temporary-file-directory))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(?b . ,(shell-quote-argument (file-name-base texfile)))
|
2023-01-09 03:24:55 +00:00
|
|
|
(?B . ,(shell-quote-argument
|
|
|
|
(expand-file-name texfile-base temporary-file-directory)))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(?D . ,(shell-quote-argument (format "%s" dpi)))
|
|
|
|
(?f . ,(shell-quote-argument
|
|
|
|
(expand-file-name
|
2023-01-09 03:24:55 +00:00
|
|
|
(concat texfile-base
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
"." (plist-get extended-info :image-input-type))
|
2023-01-08 09:35:03 +00:00
|
|
|
temporary-file-directory)))))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(img-formatted-command
|
|
|
|
(split-string-shell-command
|
|
|
|
(format-spec img-extract-command img-command-spec))))
|
2022-12-29 17:48:30 +00:00
|
|
|
(list 'org-async-task
|
|
|
|
img-formatted-command
|
|
|
|
:buffer img-process-buffer
|
|
|
|
:info extended-info
|
|
|
|
:failure "LaTeX preview image conversion failed! (error code %d)")))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview--cleanup-callback (_exit-code _stdout extended-info)
|
2023-01-06 16:25:34 +00:00
|
|
|
"Schedule cleanup with EXTENDED-INFO."
|
|
|
|
(run-with-idle-timer
|
|
|
|
1.0 nil
|
|
|
|
#'org-latex-preview--do-cleanup
|
|
|
|
extended-info))
|
|
|
|
|
|
|
|
(defun org-latex-preview--do-cleanup (extended-info)
|
2022-12-30 18:00:22 +00:00
|
|
|
"Delete files after image creation, in accord with EXTENDED-INFO."
|
2023-01-08 09:35:03 +00:00
|
|
|
(let* ((texfile (plist-get extended-info :texfile))
|
2023-01-09 03:24:55 +00:00
|
|
|
(outputs-no-ext (expand-file-name (file-name-base texfile)
|
|
|
|
temporary-file-directory))
|
2022-12-30 18:00:22 +00:00
|
|
|
(images
|
|
|
|
(mapcar
|
|
|
|
(lambda (fragment-info)
|
|
|
|
(plist-get fragment-info :path))
|
|
|
|
(plist-get extended-info :fragments)))
|
|
|
|
(clean-exts
|
|
|
|
(or (plist-get extended-info :post-clean)
|
|
|
|
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
|
|
|
|
".svg" ".png" ".jpg" ".jpeg" ".out"))))
|
2023-01-08 09:35:03 +00:00
|
|
|
(when (file-exists-p texfile) (delete-file texfile))
|
2022-12-30 18:00:22 +00:00
|
|
|
(dolist (img images)
|
2023-01-03 17:18:34 +00:00
|
|
|
(and img (delete-file img)))
|
2022-12-30 18:00:22 +00:00
|
|
|
(dolist (ext clean-exts)
|
2023-01-09 03:24:55 +00:00
|
|
|
(when (file-exists-p (concat outputs-no-ext ext))
|
|
|
|
(delete-file (concat outputs-no-ext ext))))))
|
2022-12-30 18:00:22 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview--generic-callback (_exit-code _stdout extended-info)
|
2023-01-21 23:31:38 +00:00
|
|
|
"Place generated images, in accord with EXTENDED-INFO."
|
2023-01-09 03:31:33 +00:00
|
|
|
(let* ((texfile (plist-get extended-info :texfile))
|
|
|
|
(outputs-no-ext (expand-file-name (file-name-base texfile)
|
|
|
|
temporary-file-directory))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(images
|
|
|
|
(file-expand-wildcards
|
2023-01-09 03:24:55 +00:00
|
|
|
(concat outputs-no-ext "*." (plist-get extended-info :image-output-type))
|
2023-01-21 23:31:38 +00:00
|
|
|
'full)))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(save-excursion
|
|
|
|
(cl-loop
|
2022-12-30 11:10:52 +00:00
|
|
|
for fragment-info in (plist-get extended-info :fragments)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
for image-file in images
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
for ov = (plist-get fragment-info :overlay)
|
2023-02-25 05:28:36 +00:00
|
|
|
for cached-img =
|
|
|
|
(org-latex-preview--cache-image
|
|
|
|
(plist-get fragment-info :key)
|
|
|
|
image-file
|
|
|
|
(org-latex-preview--display-info
|
|
|
|
extended-info fragment-info))
|
|
|
|
do
|
|
|
|
(plist-put fragment-info :path image-file)
|
|
|
|
(when (plist-get extended-info :place-preview-p)
|
|
|
|
(org-latex-preview--update-overlay ov cached-img))))))
|
2022-12-26 15:35:21 +00:00
|
|
|
|
2023-01-03 17:24:06 +00:00
|
|
|
(defun org-latex-preview--check-all-fragments-produced (_exit-code _stdout extended-info)
|
|
|
|
"Check each of the fragments in EXTENDED-INFO has a path.
|
|
|
|
Should this not be the case, the fragment immediately before the first
|
|
|
|
fragment without a path is marked as erronious, and the remaining
|
|
|
|
fragments are regenerated."
|
|
|
|
(let ((fragments (cons nil (copy-sequence (plist-get extended-info :fragments)))))
|
|
|
|
(while (cdr fragments)
|
|
|
|
(if (or (plist-get (cadr fragments) :path)
|
|
|
|
(plist-get (cadr fragments) :error))
|
|
|
|
(setq fragments (cdr fragments))
|
|
|
|
;; If output ends prematurely, this is most likely due to an issue with
|
|
|
|
;; the last "succesfully" produced fragment, and so we mark it as erronious
|
|
|
|
;; and attempt to re-generate the rest.
|
|
|
|
(let ((bad-fragment (car fragments))
|
|
|
|
(bad-fragment-err (plist-get (car fragments) :errors)))
|
|
|
|
(plist-put bad-fragment :errors
|
|
|
|
(concat bad-fragment-err
|
|
|
|
(and bad-fragment-err "\n\n")
|
|
|
|
"Preview generation catastrophically failed after this fragment."))
|
|
|
|
(org-latex-preview--remove-cached
|
|
|
|
(plist-get bad-fragment :key))
|
|
|
|
(org-latex-preview--update-overlay
|
|
|
|
(plist-get bad-fragment :overlay)
|
|
|
|
(org-latex-preview--cache-image
|
|
|
|
(plist-get bad-fragment :key)
|
|
|
|
(plist-get bad-fragment :path)
|
|
|
|
(org-latex-preview--display-info
|
|
|
|
extended-info bad-fragment))))
|
|
|
|
;; Re-generate the remaining fragments.
|
2023-01-22 07:06:36 +00:00
|
|
|
(org-latex-preview--create-image-async
|
2023-01-03 17:24:06 +00:00
|
|
|
(plist-get extended-info :processor)
|
2023-02-25 05:28:36 +00:00
|
|
|
(cdr fragments)
|
|
|
|
:place-preview-p t)
|
2023-01-03 17:24:06 +00:00
|
|
|
(setq fragments nil)))))
|
|
|
|
|
2022-12-30 11:10:52 +00:00
|
|
|
(defun org-latex-preview--display-info (extended-info fragment-info)
|
|
|
|
"From FRAGMENT-INFO and EXTENDED-INFO obtain display-relevant information."
|
|
|
|
(let ((image-type (intern (plist-get extended-info :image-output-type)))
|
|
|
|
info)
|
2022-12-30 18:00:22 +00:00
|
|
|
(setq info (plist-put info :image-type image-type))
|
|
|
|
(dolist (key '(:width :height :depth))
|
|
|
|
(when-let ((val (plist-get fragment-info key)))
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
(plist-put info key val)))
|
2022-12-30 18:42:05 +00:00
|
|
|
(plist-put info :errors (plist-get fragment-info :errors))
|
2022-12-30 18:00:22 +00:00
|
|
|
info))
|
|
|
|
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
;; TODO: Figure out why this factor is needed.
|
|
|
|
(defconst org-latex-preview--shameful-magic-tex-scaling-factor
|
|
|
|
1.01659593
|
|
|
|
"Extra factor for aligning preview image baselines.
|
|
|
|
|
|
|
|
Sometimes a little sprinkling of pixie dust is needed to get
|
|
|
|
things just right. Even just 2.7% magic can suffice.
|
|
|
|
|
|
|
|
This is the ratio of image sizes as reported by preview.sty and
|
|
|
|
computed by dvisvgm. The latter is correct.")
|
|
|
|
|
|
|
|
(defconst org-latex-preview--tex-scale-divisor
|
|
|
|
(* 65781.76 org-latex-preview--shameful-magic-tex-scaling-factor)
|
|
|
|
"Base pt to point conversion for preview.sty output.
|
|
|
|
|
|
|
|
This is the product of three scaling quantities:
|
|
|
|
|
|
|
|
- Point to scaled point ratio: 1:65536
|
|
|
|
- Base point to scaled point ratio: 72:72.27
|
|
|
|
- The magic scaling factor
|
|
|
|
(see `org-latex-preview--shameful-magic-tex-scaling-factor').")
|
|
|
|
|
2022-12-30 18:42:05 +00:00
|
|
|
(defun org-latex-preview--latex-preview-filter (_proc _string extended-info)
|
|
|
|
"Examine the stdout from LaTeX compilation with preview.sty.
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
|
|
|
|
- The detected fontsize is directly entered into EXTENDED-INFO.
|
|
|
|
- The tightpage bounds information is captured and stored in EXTENDED-INFO.
|
|
|
|
- Fragment geometry and alignment info is computed using the
|
|
|
|
tightpage info and page geometry reported by preview.sty.
|
|
|
|
- Fragment errors are put into the :errors slot of the relevant
|
2022-12-30 18:42:05 +00:00
|
|
|
fragments in EXTENDED-INFO."
|
|
|
|
(unless (plist-get extended-info :fontsize)
|
|
|
|
(when (save-excursion
|
|
|
|
(re-search-forward "^Preview: Fontsize \\([0-9]+\\)pt$" nil t))
|
|
|
|
(plist-put extended-info :fontsize (string-to-number (match-string 1)))))
|
|
|
|
(let ((preview-start-re
|
|
|
|
"^! Preview: Snippet \\([0-9]+\\) started.\n<-><->\n *\nl\\.\\([0-9]+\\)[^\n]+\n")
|
|
|
|
(preview-end-re
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
"\\(?:^Preview: Tightpage.*$\\)?\n! Preview: Snippet [0-9]+ ended.(\\([0-9]+\\)\\+\\([0-9]+\\)x\\([0-9]+\\))")
|
2022-12-30 18:42:05 +00:00
|
|
|
(fragments (plist-get extended-info :fragments))
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
(tightpage-info (plist-get extended-info :tightpage))
|
2022-12-30 18:42:05 +00:00
|
|
|
preview-marks)
|
|
|
|
(beginning-of-line)
|
|
|
|
(save-excursion
|
|
|
|
(while (re-search-forward preview-start-re nil t)
|
|
|
|
(push (list (match-beginning 0)
|
|
|
|
(match-end 0)
|
|
|
|
(string-to-number (match-string 1)) ; Preview index.
|
|
|
|
(1+ (string-to-number (match-string 2)))) ; Base line number.
|
|
|
|
preview-marks)))
|
|
|
|
(setq preview-marks (nreverse preview-marks))
|
|
|
|
(while preview-marks
|
|
|
|
(goto-char (caar preview-marks))
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
;; Check for tightpage-info
|
|
|
|
(unless tightpage-info
|
|
|
|
(save-excursion
|
|
|
|
(when (re-search-forward
|
|
|
|
"^Preview: Tightpage \\(-?[0-9]+\\) *\\(-?[0-9]+\\) *\\(-?[0-9]+\\) *\\(-?[0-9]+\\)"
|
|
|
|
(or (caadr preview-marks) (point-max)) t)
|
|
|
|
(setq tightpage-info
|
|
|
|
(mapcar #'string-to-number
|
|
|
|
;; left-margin bottom-margin
|
|
|
|
;; right-margin top-margin
|
|
|
|
(list (match-string 1) (match-string 2)
|
|
|
|
(match-string 3) (match-string 4))))
|
|
|
|
(plist-put extended-info :tightpage tightpage-info))))
|
|
|
|
;; Check for processed fragment
|
2022-12-30 18:42:05 +00:00
|
|
|
(if (re-search-forward preview-end-re (or (caadr preview-marks) (point-max)) t)
|
|
|
|
(let ((fragment-info (nth (1- (nth 2 (car preview-marks))) fragments))
|
|
|
|
(errors-substring
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
(save-match-data
|
|
|
|
(string-trim
|
|
|
|
(buffer-substring (cadar preview-marks)
|
|
|
|
(match-beginning 0));; In certain situations we can end up with non-error
|
|
|
|
;; logging informattion within the preview output.
|
|
|
|
;; To make sure this is not captured, we rely on the fact
|
|
|
|
;; that LaTeX error messages have a consistent format
|
|
|
|
;; and start with an exclamation mark "!". Thus, we
|
|
|
|
;; can safely strip everything prior to the first "!"
|
|
|
|
;; from the output.
|
|
|
|
"[^!]*")))
|
|
|
|
depth)
|
|
|
|
;; Gather geometry and alignment info
|
|
|
|
(if tightpage-info
|
|
|
|
(progn
|
|
|
|
(setq depth
|
|
|
|
(/ (- (string-to-number (match-string 2))
|
|
|
|
(nth 1 tightpage-info))
|
|
|
|
org-latex-preview--tex-scale-divisor
|
|
|
|
(or (plist-get fragment-info :fontsize) 10)))
|
|
|
|
(plist-put fragment-info :depth depth)
|
|
|
|
(plist-put fragment-info :height
|
|
|
|
(+ (or depth 0)
|
|
|
|
(/ (+ (string-to-number (match-string 1))
|
|
|
|
(nth 3 tightpage-info))
|
|
|
|
org-latex-preview--tex-scale-divisor
|
|
|
|
(or (plist-get fragment-info :fontsize) 10))))
|
|
|
|
(plist-put fragment-info :width
|
|
|
|
(/ (+ (string-to-number (match-string 3))
|
|
|
|
(nth 2 tightpage-info)
|
|
|
|
(- (nth 1 tightpage-info)))
|
|
|
|
org-latex-preview--tex-scale-divisor
|
|
|
|
(or (plist-get fragment-info :fontsize) 10))))
|
|
|
|
(cl-loop for (geom . match-index)
|
|
|
|
in '((:height . 1) (:depth . 2) (:width . 3))
|
|
|
|
do
|
|
|
|
(plist-put fragment-info geom
|
|
|
|
(/ (string-to-number (match-string match-index))
|
|
|
|
org-latex-preview--tex-scale-divisor
|
|
|
|
(or (plist-get fragment-info :fontsize) 10)))))
|
2022-12-30 18:42:05 +00:00
|
|
|
(plist-put fragment-info :errors
|
|
|
|
(and (not (string-blank-p errors-substring))
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"^l\\.[0-9]+"
|
|
|
|
(lambda (linum)
|
|
|
|
(format "l.%d"
|
|
|
|
(- (string-to-number (substring linum 2))
|
|
|
|
(nth 3 (car preview-marks)))))
|
|
|
|
errors-substring))))
|
|
|
|
(goto-char (caar preview-marks)))
|
|
|
|
(setq preview-marks (cdr preview-marks)))))
|
|
|
|
|
2022-12-30 18:00:22 +00:00
|
|
|
(defun org-latex-preview--dvisvgm-filter (_proc _string extended-info)
|
|
|
|
"Look for newly created images in the dvisvgm stdout buffer.
|
|
|
|
Any matches found will be matched against the fragments recorded in
|
|
|
|
EXTENDED-INFO, and displayed in the buffer."
|
|
|
|
(let ((dvisvgm-processing-re "^processing page \\([0-9]+\\)\n")
|
|
|
|
(fragments (plist-get extended-info :fragments))
|
|
|
|
page-marks fragments-to-show)
|
|
|
|
(beginning-of-line)
|
|
|
|
(save-excursion
|
|
|
|
(while (re-search-forward dvisvgm-processing-re nil t)
|
|
|
|
(push (cons (string-to-number (match-string 1))
|
|
|
|
(match-beginning 0))
|
|
|
|
page-marks)))
|
|
|
|
(setq page-marks (nreverse page-marks))
|
|
|
|
(while page-marks
|
|
|
|
(let ((start (cdar page-marks))
|
|
|
|
(end (or (cdadr page-marks) (point-max)))
|
|
|
|
(page (caar page-marks))
|
|
|
|
fragment-info)
|
|
|
|
(goto-char start)
|
|
|
|
(when (save-excursion
|
|
|
|
(re-search-forward "output written to \\(.*.svg\\)$" end t))
|
|
|
|
(setq fragment-info (nth (1- page) fragments))
|
|
|
|
(plist-put fragment-info :path (expand-file-name (match-string 1) temporary-file-directory))
|
|
|
|
(when (save-excursion
|
|
|
|
(re-search-forward "^ page is empty" end t))
|
|
|
|
(unless (plist-get fragment-info :error)
|
|
|
|
(plist-put fragment-info :error "Image file not produced."))
|
|
|
|
(plist-put fragment-info :path nil))
|
|
|
|
(push fragment-info fragments-to-show)
|
|
|
|
(goto-char end)))
|
|
|
|
(setq page-marks (cdr page-marks)))
|
|
|
|
(when fragments-to-show
|
|
|
|
(setq fragments-to-show (nreverse fragments-to-show))
|
2023-02-26 11:27:12 +00:00
|
|
|
(mapc #'org-latex-preview--svg-make-fg-currentColor fragments-to-show)
|
|
|
|
(if (plist-get extended-info :place-preview-p)
|
|
|
|
(org-latex-preview--place-images extended-info fragments-to-show)
|
|
|
|
(dolist (fragment-info fragments-to-show)
|
|
|
|
(org-latex-preview--cache-image
|
|
|
|
(plist-get fragment-info :key)
|
|
|
|
(plist-get fragment-info :path)
|
|
|
|
(org-latex-preview--display-info
|
|
|
|
extended-info fragment-info)))))))
|
2022-12-30 18:00:22 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview--svg-make-fg-currentColor (svg-fragment)
|
|
|
|
"Replace the foreground color in SVG-FRAGMENT's file with \"currentColor\".
|
|
|
|
The foreground color is guessed to be the first specified <g>
|
|
|
|
fill color, which appears to be a reliable heuristic from a few
|
|
|
|
tests with the output of dvisvgm."
|
2023-01-03 08:46:35 +00:00
|
|
|
(let ((write-region-inhibit-fsync t)
|
|
|
|
;; dvisvgm produces UTF-8 encoded files, so we might as well
|
|
|
|
;; avoid calling `find-auto-coding'.
|
|
|
|
(coding-system-for-read 'utf-8)
|
|
|
|
(coding-system-for-write 'utf-8)
|
|
|
|
;; Prevent any file handlers (specifically
|
|
|
|
;; `image-file-handler') from being called.
|
2023-01-03 17:18:34 +00:00
|
|
|
(file-name-handler-alist nil)
|
|
|
|
(path (plist-get svg-fragment :path)))
|
2023-02-26 11:27:12 +00:00
|
|
|
(catch 'svg-exists
|
|
|
|
(dotimes (_ 1000) ; Check for svg existance over 1s.
|
|
|
|
(when (file-exists-p path)
|
|
|
|
(throw 'svg-exists t))
|
|
|
|
(sleep-for 0.001)))
|
2023-01-03 17:18:34 +00:00
|
|
|
(when path
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents path)
|
2023-01-10 13:05:52 +00:00
|
|
|
(unless ; When the svg is incomplete, wait for it to be completed.
|
2023-02-26 11:27:12 +00:00
|
|
|
(string= (buffer-substring (max 1 (- (point-max) 6)) (point-max))
|
2023-01-10 13:05:52 +00:00
|
|
|
"</svg>")
|
|
|
|
(catch 'svg-complete
|
|
|
|
(dotimes (_ 1000) ; Check for complete svg over 1s.
|
2023-02-26 11:27:12 +00:00
|
|
|
(if (string= (buffer-substring (max 1 (- (point-max) 6)) (point-max))
|
2023-01-10 13:05:52 +00:00
|
|
|
"</svg>")
|
|
|
|
(throw 'svg-complete t)
|
|
|
|
(erase-buffer)
|
2023-02-26 11:27:12 +00:00
|
|
|
(sleep-for 0.001)
|
2023-01-10 13:05:52 +00:00
|
|
|
(insert-file-contents path)))
|
|
|
|
(erase-buffer)))
|
2023-01-03 17:18:34 +00:00
|
|
|
(goto-char (point-min))
|
2023-01-10 13:05:52 +00:00
|
|
|
(if (or (= (buffer-size) 0)
|
|
|
|
(re-search-forward "<svg[^>]*>\n<g[^>]*>\n</svg>" nil t))
|
2023-01-03 17:18:34 +00:00
|
|
|
;; We never want to show an empty SVG, instead it is better to delete
|
|
|
|
;; it and leave the LaTeX fragment without an image overlay.
|
|
|
|
;; This also works better with other parts of the system, such as
|
|
|
|
;; the display of errors.
|
|
|
|
(delete-file path)
|
|
|
|
(when (re-search-forward "<g fill='\\(#[0-9a-f]\\{6\\}\\)'" nil t)
|
|
|
|
(let* ((same-color (format "\\(?:fill\\|stroke\\)='\\(%s\\)'" (match-string 1))))
|
|
|
|
(replace-match "currentColor" t t nil 1)
|
|
|
|
(while (re-search-forward same-color nil t)
|
|
|
|
(replace-match "currentColor" t t nil 1)))
|
|
|
|
(write-region nil nil path nil 0)))))))
|
2022-12-30 18:00:22 +00:00
|
|
|
|
2023-01-03 08:39:06 +00:00
|
|
|
(defun org-latex-preview--dvipng-filter (_proc _string extended-info)
|
|
|
|
"Look for newly created images in the dvipng stdout buffer.
|
|
|
|
Any matches found will be matched against the fragments recorded in
|
|
|
|
EXTENDED-INFO, and displayed in the buffer."
|
org-latex-preview: Get geometry from preview.sty
* lisp/org-latex-preview.el (org-latex-preview--latex-preview-filter,
org-latex-preview--tex-scale-divisor,
org-latex-preview--dvipng-dpi-pt-factor): Fetch image geometry and
alignment information from the LaTeX compilation output instead of
dvisvgm or dvipng. This calculation is simpler and should work for all
image converters (including imagemagick) and with all latex
processors (including xelatex and lualatex).
(org-latex-preview--shameful-magic-tex-scaling-factor): New
variable to match image geometry reported by preview.sty and that
computed by dvisvgm.
(org-latex-preview--dvipng-filter, org-latex-preview--dvisvgm-filter,
org-latex-preview--latex-preview-filter,
org-latex-preview--display-info): Adjust to no longer use the old sizing
information.
* lisp/org-latex-preview.el (org-latex-preview-process-alist,
org-latex-preview-create-image, org-latex-preview--display-info,
org-latex-preview--image-extract-async): Remove the :image-size-adjust
keyword, as with the new geometry detection system it is redundant.
We tried also switching dvisgm from "--bbox=preview" to "--exact-bbox",
as it should no longer be needed, but testing found "--exact-bbox" to
cause sizing issues in practice.
2023-02-25 05:32:11 +00:00
|
|
|
(let ((outputs-no-ext (expand-file-name
|
2023-01-09 03:31:33 +00:00
|
|
|
(file-name-base
|
|
|
|
(plist-get extended-info :texfile))
|
|
|
|
temporary-file-directory))
|
2023-01-03 08:39:06 +00:00
|
|
|
(fragments (plist-get extended-info :fragments))
|
|
|
|
fragments-to-show page-info-end)
|
|
|
|
(while (search-forward "]" nil t)
|
|
|
|
(setq page-info-end (point))
|
|
|
|
(save-excursion
|
|
|
|
(backward-list)
|
|
|
|
(if (re-search-forward "\\=\\[\\([0-9]+\\) " page-info-end t)
|
|
|
|
(let* ((page (string-to-number (match-string 1)))
|
|
|
|
(fragment-info (nth (1- page) fragments)))
|
|
|
|
(plist-put fragment-info :path
|
2023-01-09 03:31:33 +00:00
|
|
|
(format "%s-%09d.png" outputs-no-ext page))
|
2023-01-03 08:39:06 +00:00
|
|
|
(push fragment-info fragments-to-show)))))
|
|
|
|
(when fragments-to-show
|
|
|
|
(setq fragments-to-show (nreverse fragments-to-show))
|
2023-02-25 05:28:36 +00:00
|
|
|
(if (plist-get extended-info :place-preview-p)
|
|
|
|
(org-latex-preview--place-images extended-info fragments-to-show)
|
|
|
|
(dolist (fragment-info fragments-to-show)
|
|
|
|
(org-latex-preview--cache-image
|
|
|
|
(plist-get fragment-info :key)
|
|
|
|
(plist-get fragment-info :path)
|
|
|
|
(org-latex-preview--display-info
|
|
|
|
extended-info fragment-info)))))))
|
2023-01-03 08:39:06 +00:00
|
|
|
|
2022-12-30 18:00:22 +00:00
|
|
|
(defun org-latex-preview--place-images (extended-info &optional fragments)
|
|
|
|
"Place images for each of FRAGMENTS, according to their data and EXTENDED-INFO.
|
|
|
|
Should FRAGMENTS not be explicitly provided, all of the fragments
|
|
|
|
listed in EXTENDED-INFO will be used."
|
|
|
|
(let ((fragments (or fragments (plist-get extended-info :fragments))))
|
|
|
|
(with-current-buffer (plist-get extended-info :org-buffer)
|
|
|
|
(save-excursion
|
|
|
|
(cl-loop
|
|
|
|
for fragment-info in fragments
|
|
|
|
for image-file = (plist-get fragment-info :path)
|
org-latex-preview: Eagerly make fragment overlays
* lisp/org-latex-preview.el (org-create-latex-export,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--create-tex-file,
org-latex-preview-create-image-async, org-latex-preview--create,
org-latex-preview--close-previous-overlay,
org-latex-preview--make-overlay, org-latex-preview--update-overlay,
org-latex-preview-processing-face): Instead of saving buffer locations
and creating an overlay after the fragment image has been generated,
create an overlay initially and then update it when the image has been
created. This is done by splitting the image-related code of
`org-latex-preview--make-overlay' into a new function,
`org-latex-preview--update-overlay'. This provides a number of
advantages, primarily robustness to buffer edits during image
generation. It also allows us to create a face to indicate
in-progress (`org-latex-preview-processing-face'), which is a nice
visual indicator.
2023-01-02 16:29:40 +00:00
|
|
|
for ov = (plist-get fragment-info :overlay)
|
|
|
|
do (org-latex-preview--update-overlay
|
|
|
|
ov
|
2022-12-30 18:00:22 +00:00
|
|
|
(org-latex-preview--cache-image
|
|
|
|
(plist-get fragment-info :key)
|
|
|
|
image-file
|
|
|
|
(org-latex-preview--display-info
|
|
|
|
extended-info fragment-info))))))))
|
2022-12-28 02:38:39 +00:00
|
|
|
|
2023-01-03 17:24:06 +00:00
|
|
|
(defconst org-latex-preview--cache-name "LaTeX preview cached image data"
|
|
|
|
"The name used for Org LaTeX Preview objects in the org-persist cache.")
|
|
|
|
|
2023-01-05 08:00:45 +00:00
|
|
|
(defvar org-latex-preview--table nil
|
|
|
|
"Hash table to hold LaTeX preview image metadata.
|
|
|
|
|
|
|
|
This is only used if image caching is disabled by setting
|
|
|
|
`org-latex-preview-persist' to nil.")
|
|
|
|
|
2022-12-30 07:52:48 +00:00
|
|
|
(defun org-latex-preview--cache-image (key path info)
|
|
|
|
"Save the image at PATH with associated INFO in the cache indexed by KEY.
|
2023-01-05 08:00:45 +00:00
|
|
|
Return (path . info).
|
|
|
|
|
|
|
|
The caching location depends on whether preview persistence is
|
|
|
|
enabled, see `org-latex-preview-persist'."
|
|
|
|
(if org-latex-preview-persist
|
|
|
|
(let ((label-path-info
|
|
|
|
(or (org-persist-read org-latex-preview--cache-name
|
2023-01-02 10:03:11 +00:00
|
|
|
(list :key key)
|
2023-01-05 08:00:45 +00:00
|
|
|
nil nil :read-related t)
|
|
|
|
(org-persist-register `(,org-latex-preview--cache-name
|
|
|
|
(file ,path)
|
|
|
|
(elisp-data ,info))
|
|
|
|
(list :key key)
|
2023-01-17 15:43:00 +00:00
|
|
|
:expiry org-latex-preview-persist-expiry
|
2023-01-05 08:00:45 +00:00
|
|
|
:write-immediately t))))
|
|
|
|
(cons (cadr label-path-info) info))
|
|
|
|
(unless org-latex-preview--table
|
|
|
|
(setq org-latex-preview--table (make-hash-table :test 'equal :size 240)))
|
|
|
|
(when-let ((path)
|
|
|
|
(new-path (expand-file-name
|
|
|
|
(concat "org-tex-" key "." (file-name-extension path))
|
|
|
|
temporary-file-directory)))
|
|
|
|
(copy-file path new-path 'replace)
|
|
|
|
(puthash key (cons new-path info)
|
|
|
|
org-latex-preview--table))))
|
2022-12-30 07:52:48 +00:00
|
|
|
|
|
|
|
(defun org-latex-preview--get-cached (key)
|
|
|
|
"Retrieve the image path and info associated with KEY.
|
|
|
|
The result will be of the form (path . info).
|
|
|
|
|
|
|
|
Example result:
|
|
|
|
(\"/path/.../to/.../image.svg\"
|
|
|
|
:type svg
|
|
|
|
:height 1.4
|
|
|
|
:width 7.6
|
|
|
|
:depth 0.2
|
|
|
|
:errors nil)"
|
2023-01-05 08:00:45 +00:00
|
|
|
(if org-latex-preview-persist
|
|
|
|
(when-let ((label-path-info
|
|
|
|
(org-persist-read org-latex-preview--cache-name
|
|
|
|
(list :key key)
|
|
|
|
nil nil :read-related t)))
|
|
|
|
(cons (cadr label-path-info)
|
|
|
|
(caddr label-path-info)))
|
|
|
|
(when org-latex-preview--table
|
|
|
|
(gethash key org-latex-preview--table))))
|
2022-12-30 07:52:48 +00:00
|
|
|
|
2023-01-03 17:24:06 +00:00
|
|
|
(defun org-latex-preview--remove-cached (key)
|
|
|
|
"Remove the fragment cache associated with KEY."
|
2023-01-05 08:00:45 +00:00
|
|
|
(if org-latex-preview-persist
|
|
|
|
(org-persist-unregister org-latex-preview--cache-name
|
|
|
|
(list :key key)
|
|
|
|
:remove-related t)
|
|
|
|
(when org-latex-preview--table
|
|
|
|
(remhash key org-latex-preview--table)
|
|
|
|
(dolist (ext '("svg" "png"))
|
|
|
|
(when-let ((image-file
|
|
|
|
(expand-file-name
|
|
|
|
(concat "org-tex-" key "." ext)
|
|
|
|
temporary-file-directory))
|
|
|
|
((file-exists-p image-file)))
|
|
|
|
(delete-file image-file))))))
|
2023-01-03 17:24:06 +00:00
|
|
|
|
2023-01-04 03:03:31 +00:00
|
|
|
(defun org-latex-preview-clear-cache (&optional beg end clear-entire-cache)
|
|
|
|
"Clear LaTeX preview cache for fragments between BEG and END.
|
|
|
|
|
|
|
|
Interactively, act on
|
|
|
|
- the region if it is active,
|
|
|
|
- the fragment at point if in a fragment,
|
|
|
|
- the whole buffer otherwise.
|
|
|
|
|
|
|
|
When CLEAR-ENTIRE-CACHE is non-nil (interactively set by \\[universal-argument]),
|
|
|
|
the *entire* preview cache will be cleared, and `org-persist-gc' run."
|
|
|
|
(interactive
|
|
|
|
(if current-prefix-arg
|
2023-01-06 09:52:50 +00:00
|
|
|
(list nil nil (y-or-n-p "This will clear the systemwide LaTeX preview cache, continue? "))
|
2023-01-04 03:03:31 +00:00
|
|
|
(let ((context (if (derived-mode-p 'org-mode)
|
|
|
|
(org-element-context)
|
|
|
|
(user-error "This command must be run in an org-mode buffer"))))
|
|
|
|
(cond
|
|
|
|
((use-region-p)
|
|
|
|
(list (region-beginning) (region-end)))
|
|
|
|
((memq (org-element-type context)
|
|
|
|
'(latex-fragment latex-environment))
|
|
|
|
(list (org-element-property :begin context)
|
|
|
|
(org-element-property :end context)))
|
2023-01-06 09:52:50 +00:00
|
|
|
(t (list nil nil))))))
|
2023-03-12 10:12:46 +00:00
|
|
|
;; Clear the precompile cache if clearing the whole buffer or everything.
|
|
|
|
(when (or clear-entire-cache (not (or beg end)))
|
|
|
|
(dolist (compiler org-latex-compilers)
|
|
|
|
(org-latex--remove-cached-preamble
|
|
|
|
compiler org-latex-preview--preamble-content nil)
|
|
|
|
(org-latex--remove-cached-preamble
|
|
|
|
compiler org-latex-preview--preamble-content t)))
|
2023-01-04 03:03:31 +00:00
|
|
|
(org-latex-preview-clear-overlays beg end)
|
|
|
|
(if clear-entire-cache
|
|
|
|
(let ((n 0))
|
|
|
|
(dolist (collection org-persist--index)
|
|
|
|
(when (equal (cadar (plist-get collection :container))
|
|
|
|
org-latex-preview--cache-name)
|
|
|
|
(org-latex-preview--remove-cached
|
|
|
|
(plist-get (plist-get collection :associated) :key))
|
|
|
|
(cl-incf n)))
|
|
|
|
(if (= n 0)
|
|
|
|
(message "The Org LaTeX preview cache was already empty.")
|
|
|
|
(org-persist-gc)
|
|
|
|
(message "Cleared all %d entries fom the Org LaTeX preview cache." n)))
|
2023-01-06 09:52:50 +00:00
|
|
|
(let ((imagetype
|
|
|
|
(or (plist-get (alist-get org-latex-preview-default-process
|
|
|
|
org-latex-preview-process-alist)
|
|
|
|
:image-output-type)
|
2023-03-12 09:00:49 +00:00
|
|
|
"png"))
|
|
|
|
(numbering-table
|
|
|
|
(and org-latex-preview-numbered
|
|
|
|
(org-latex-preview--environment-numbering-table))))
|
2023-01-04 03:03:31 +00:00
|
|
|
(dolist (element (org-latex-preview-collect-fragments beg end))
|
2023-01-30 03:20:36 +00:00
|
|
|
(pcase-let* ((begin (or (org-element-property :post-affiliated element)
|
|
|
|
(org-element-property :begin element)))
|
2023-01-04 03:03:31 +00:00
|
|
|
(`(,fg ,bg) (org-latex-preview--colors-at begin))
|
2023-03-12 09:00:49 +00:00
|
|
|
(value (org-element-property :value element))
|
|
|
|
(number (and numbering-table
|
|
|
|
(eq (org-element-type element)
|
|
|
|
'latex-environment)
|
|
|
|
(gethash element numbering-table))))
|
2023-01-04 03:03:31 +00:00
|
|
|
(org-latex-preview--remove-cached
|
|
|
|
(org-latex-preview--hash
|
|
|
|
org-latex-preview-default-process
|
2023-03-12 09:00:49 +00:00
|
|
|
value imagetype fg bg number))))
|
2023-01-06 09:52:50 +00:00
|
|
|
(message "Cleared LaTeX preview cache for %s."
|
|
|
|
(if (or beg end) "region" "buffer")))))
|
2023-01-04 03:03:31 +00:00
|
|
|
|
2023-02-12 07:20:30 +00:00
|
|
|
(defun org-latex-preview-precompile (processing-info preamble)
|
|
|
|
"Precompile/dump LaTeX PREAMBLE text.
|
2022-12-26 20:15:07 +00:00
|
|
|
|
2023-02-12 07:20:30 +00:00
|
|
|
The path to the format file (.fmt) is returned. If the format
|
|
|
|
file could not be found in the persist cache, it is generated
|
|
|
|
according to PROCESSING-INFO and stored.
|
2022-12-26 20:15:07 +00:00
|
|
|
|
|
|
|
This is intended to speed up Org's LaTeX preview generation
|
|
|
|
process."
|
2023-03-12 10:12:46 +00:00
|
|
|
(org-latex--precompile
|
|
|
|
(list :latex-compiler (plist-get processing-info :latex-processor)
|
|
|
|
:precompile-format-spec
|
2023-02-12 07:20:30 +00:00
|
|
|
(let ((org-tex-compiler
|
|
|
|
(cdr (assoc (plist-get processing-info :latex-processor)
|
|
|
|
org-latex-preview-compiler-command-map))))
|
|
|
|
`((?l . ,org-tex-compiler)
|
|
|
|
(?L . ,(car (split-string org-tex-compiler))))))
|
2023-03-12 10:12:46 +00:00
|
|
|
preamble))
|
2022-12-26 20:15:07 +00:00
|
|
|
|
2023-01-03 17:35:22 +00:00
|
|
|
(defun org-latex-preview--tex-styled (processing-type value options &optional html-p)
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
"Apply LaTeX style commands to VALUE based on OPTIONS.
|
2023-01-03 17:35:22 +00:00
|
|
|
If PROCESSING-TYPE is dvipng, the colours are set with DVI
|
|
|
|
\"\\special\" commands instead of \"\\color\" and
|
|
|
|
\"\\pagecolor\".
|
2022-12-26 15:35:21 +00:00
|
|
|
|
|
|
|
VALUE is the math fragment text to be previewed.
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
OPTIONS is the plist `org-latex-preview-options' with customized
|
2022-12-26 15:35:21 +00:00
|
|
|
color information for this run.
|
|
|
|
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
HTML-P, if true, uses colors required for HTML processing."
|
|
|
|
(let* ((fg (pcase (plist-get options (if html-p :html-foreground :foreground))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
('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))))
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
(bg (pcase (plist-get options (if html-p :html-background :background))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
('default (org-latex-preview--attr-color :background))
|
2022-12-26 15:35:21 +00:00
|
|
|
("Transparent" nil)
|
2023-03-12 09:00:49 +00:00
|
|
|
(bg (org-latex-preview--format-color bg))))
|
|
|
|
(num (or (plist-get options :number) 1)))
|
2023-01-03 17:35:22 +00:00
|
|
|
(concat (and (not (plist-get options :continue-color))
|
|
|
|
(if (eq processing-type 'dvipng)
|
|
|
|
(concat (and fg (format "\\special{color rgb %s}"
|
|
|
|
(subst-char-in-string
|
|
|
|
?, ?\s fg)))
|
|
|
|
(and bg (format "\\special{background rgb %s}"
|
|
|
|
(subst-char-in-string
|
|
|
|
?, ?\s bg))))
|
|
|
|
(concat
|
|
|
|
(and bg (format "\\pagecolor[rgb]{%s}" bg))
|
|
|
|
(and fg (format "\\color[rgb]{%s}" fg)))))
|
2023-03-12 09:00:49 +00:00
|
|
|
(format "\\setcounter{equation}{%d}" (1- num))
|
2022-12-30 18:42:05 +00:00
|
|
|
"%\n"
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
value)))
|
2022-12-26 10:49:33 +00:00
|
|
|
|
|
|
|
(defun org-create-latex-export (processing-type element prefix dir &optional block-type)
|
|
|
|
"Create a export of the LaTeX math fragment ELEMENT using PROCESSING-TYPE.
|
|
|
|
|
org-latex-preview: Refactor async formula function
* lisp/org-latex-preview.el (org-create-preview-string,
org-create-latex-preview, org-latex-replace-fragments,
org-create-formula-image-async): Refactor
`org-create-formula-image-async', specifically by splitting up the
texfile creation, texfile compilation, image extraction, and cleanup
phases into individual functions (`org-preview-latex--create-tex-file',
`org-latex-preview--tex-compile-async',
`org-latex-preview--image-extract-async',
`org-latex-preview--cleanup-callback') and use `org-async-call' for
managing async. Along the way a few other minor tweaks have crept in.
2022-12-27 17:04:46 +00:00
|
|
|
Generated image files are placed in DIR with the prefix PREFIX.
|
|
|
|
Note that PREFIX may itself contain a directory path component.
|
2022-12-26 10:49:33 +00:00
|
|
|
|
|
|
|
BLOCK-TYPE determines whether the result is placed inline or as a paragraph."
|
2022-12-26 01:34:04 +00:00
|
|
|
(let* ((processing-info
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(cdr (assq processing-type org-latex-preview-process-alist)))
|
2022-12-26 10:49:33 +00:00
|
|
|
(beg (org-element-property :begin element))
|
|
|
|
(end (save-excursion
|
|
|
|
(goto-char (org-element-property :end element))
|
|
|
|
(skip-chars-backward " \r\t\n")
|
|
|
|
(point)))
|
|
|
|
(value (org-element-property :value element))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(fg (plist-get org-latex-preview-options :foreground))
|
|
|
|
(bg (plist-get org-latex-preview-options :background))
|
2022-12-26 01:34:04 +00:00
|
|
|
(hash (sha1 (prin1-to-string
|
2022-12-30 07:52:48 +00:00
|
|
|
(list processing-type
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
org-latex-preview-preamble
|
2022-12-26 01:34:04 +00:00
|
|
|
org-latex-default-packages-alist
|
|
|
|
org-latex-packages-alist
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
org-latex-preview-options
|
2022-12-26 10:49:33 +00:00
|
|
|
'export value fg bg))))
|
2022-12-26 01:34:04 +00:00
|
|
|
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
|
|
|
(absprefix (expand-file-name prefix dir))
|
|
|
|
(linkfile (format "%s_%s.%s" prefix hash imagetype))
|
|
|
|
(movefile (format "%s_%s.%s" absprefix hash imagetype))
|
|
|
|
(sep (and block-type "\n\n"))
|
|
|
|
(link (concat sep "[[file:" linkfile "]]" sep))
|
2022-12-26 10:49:33 +00:00
|
|
|
(options (org-combine-plists
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
org-latex-preview-options
|
2022-12-26 10:49:33 +00:00
|
|
|
(list :foreground fg :background bg))))
|
2022-12-26 01:34:04 +00:00
|
|
|
(unless (file-exists-p movefile)
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(org-latex-preview-create-image
|
2022-12-26 10:49:33 +00:00
|
|
|
value movefile options nil processing-type))
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(org-latex-preview-place-image-link link block-type beg end value)))
|
2022-12-26 01:34:04 +00:00
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview-place-image-link (link block-type beg end value)
|
2022-12-26 08:17:25 +00:00
|
|
|
"Place then link LINK at BEG END."
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert
|
|
|
|
(org-add-props link
|
|
|
|
(list 'org-latex-src
|
|
|
|
(replace-regexp-in-string "\"" "" value)
|
|
|
|
'org-latex-src-embed-type
|
|
|
|
(if block-type 'paragraph 'character)))))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
|
|
|
(defun org-create-math-formula (latex-frag &optional mathml-file)
|
|
|
|
"Convert LATEX-FRAG to MathML and store it in MATHML-FILE.
|
|
|
|
Use `org-latex-to-mathml-convert-command'. If the conversion is
|
|
|
|
successful, return the portion between \"<math...> </math>\"
|
|
|
|
elements otherwise return nil. When MATHML-FILE is specified,
|
|
|
|
write the results in to that file. When invoked as an
|
|
|
|
interactive command, prompt for LATEX-FRAG, with initial value
|
|
|
|
set to the current active region and echo the results for user
|
|
|
|
inspection."
|
|
|
|
(interactive (list (let ((frag (when (org-region-active-p)
|
|
|
|
(buffer-substring-no-properties
|
|
|
|
(region-beginning) (region-end)))))
|
|
|
|
(read-string "LaTeX Fragment: " frag nil frag))))
|
|
|
|
(unless latex-frag (user-error "Invalid LaTeX fragment"))
|
|
|
|
(let* ((tmp-in-file
|
|
|
|
(let ((file (file-relative-name
|
|
|
|
(make-temp-name (expand-file-name "ltxmathml-in")))))
|
|
|
|
(write-region latex-frag nil file)
|
|
|
|
file))
|
|
|
|
(tmp-out-file (file-relative-name
|
|
|
|
(make-temp-name (expand-file-name "ltxmathml-out"))))
|
|
|
|
(cmd (format-spec
|
|
|
|
org-latex-to-mathml-convert-command
|
|
|
|
`((?j . ,(and org-latex-to-mathml-jar-file
|
|
|
|
(shell-quote-argument
|
|
|
|
(expand-file-name
|
|
|
|
org-latex-to-mathml-jar-file))))
|
|
|
|
(?I . ,(shell-quote-argument tmp-in-file))
|
|
|
|
(?i . ,latex-frag)
|
|
|
|
(?o . ,(shell-quote-argument tmp-out-file)))))
|
|
|
|
mathml shell-command-output)
|
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(unless (org-format-latex-mathml-available-p)
|
|
|
|
(user-error "LaTeX to MathML converter not configured")))
|
|
|
|
(message "Running %s" cmd)
|
|
|
|
(setq shell-command-output (shell-command-to-string cmd))
|
|
|
|
(setq mathml
|
|
|
|
(when (file-readable-p tmp-out-file)
|
|
|
|
(with-current-buffer (find-file-noselect tmp-out-file t)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(when (re-search-forward
|
|
|
|
(format "<math[^>]*?%s[^>]*?>\\(.\\|\n\\)*</math>"
|
|
|
|
(regexp-quote
|
|
|
|
"xmlns=\"http://www.w3.org/1998/Math/MathML\""))
|
|
|
|
nil t)
|
|
|
|
(prog1 (match-string 0) (kill-buffer))))))
|
|
|
|
(cond
|
|
|
|
(mathml
|
|
|
|
(setq mathml
|
|
|
|
(concat "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" mathml))
|
|
|
|
(when mathml-file
|
|
|
|
(write-region mathml nil mathml-file))
|
|
|
|
(when (called-interactively-p 'any)
|
|
|
|
(message mathml)))
|
|
|
|
((warn "LaTeX to MathML conversion failed")
|
|
|
|
(message shell-command-output)))
|
|
|
|
(delete-file tmp-in-file)
|
|
|
|
(when (file-exists-p tmp-out-file)
|
|
|
|
(delete-file tmp-out-file))
|
|
|
|
mathml))
|
|
|
|
|
|
|
|
(defun org-format-latex-as-mathml (latex-frag latex-frag-type
|
|
|
|
prefix &optional dir)
|
|
|
|
"Use `org-create-math-formula' but check local cache first."
|
|
|
|
(let* ((absprefix (expand-file-name prefix dir))
|
|
|
|
(print-length nil) (print-level nil)
|
|
|
|
(formula-id (concat
|
|
|
|
"formula-"
|
|
|
|
(sha1
|
|
|
|
(prin1-to-string
|
|
|
|
(list latex-frag
|
|
|
|
org-latex-to-mathml-convert-command)))))
|
|
|
|
(formula-cache (format "%s-%s.mathml" absprefix formula-id))
|
|
|
|
(formula-cache-dir (file-name-directory formula-cache)))
|
|
|
|
|
|
|
|
(unless (file-directory-p formula-cache-dir)
|
|
|
|
(make-directory formula-cache-dir t))
|
|
|
|
|
|
|
|
(unless (file-exists-p formula-cache)
|
|
|
|
(org-create-math-formula latex-frag formula-cache))
|
|
|
|
|
|
|
|
(if (file-exists-p formula-cache)
|
|
|
|
;; Successful conversion. Return the link to MathML file.
|
|
|
|
(org-add-props
|
|
|
|
(format "[[file:%s]]" (file-relative-name formula-cache dir))
|
|
|
|
(list 'org-latex-src (replace-regexp-in-string "\"" "" latex-frag)
|
|
|
|
'org-latex-src-embed-type (if latex-frag-type
|
|
|
|
'paragraph 'character)))
|
|
|
|
;; Failed conversion. Return the LaTeX fragment verbatim
|
|
|
|
latex-frag)))
|
|
|
|
|
|
|
|
(defun org-format-latex-as-html (latex-fragment)
|
|
|
|
"Convert LATEX-FRAGMENT to HTML.
|
|
|
|
This uses `org-latex-to-html-convert-command', which see."
|
|
|
|
(let ((cmd (format-spec org-latex-to-html-convert-command
|
|
|
|
`((?i . ,latex-fragment)))))
|
|
|
|
(message "Running %s" cmd)
|
|
|
|
(shell-command-to-string cmd)))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview--get-display-dpi ()
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Get the DPI of the display.
|
|
|
|
The function assumes that the display has the same pixel width in
|
|
|
|
the horizontal and vertical directions."
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(round (/ (display-pixel-height)
|
|
|
|
(/ (display-mm-height) 25.4)))
|
|
|
|
(error "Attempt to calculate the dpi of a non-graphic display")))
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview--attr-color (attr)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Return a RGB color for the LaTeX color package."
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(org-latex-preview--format-color (face-attribute 'default attr nil)))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
2023-01-03 11:25:23 +00:00
|
|
|
(defvar org-latex-preview--format-color-cache nil
|
|
|
|
"Cache for `org-latex-preview--format-color'.
|
|
|
|
Because `org-latex-preview--format-color' is called multiple
|
|
|
|
times for every fragment, even though only few colors will be
|
|
|
|
used it can be worth storing the results to avoid re-computing.")
|
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview--format-color (color-name)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Convert COLOR-NAME to a RGB color value."
|
2023-01-03 11:25:23 +00:00
|
|
|
(or (alist-get color-name org-latex-preview--format-color-cache nil nil #'equal)
|
|
|
|
(cdar (push (cons color-name
|
|
|
|
(apply #'format "%s,%s,%s"
|
|
|
|
(mapcar 'org-latex-preview--normalize-color
|
|
|
|
(color-values color-name))))
|
|
|
|
org-latex-preview--format-color-cache))))
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
|
org-latex-preview: Use prefix more consistently
* lisp/ox-odt.el (org-odt--translate-latex-fragments): Use renamed
org-latex-preview-* functions/variables.
* lisp/ox-html.el (org-html-latex-fragment, org-html-latex-environment,
org-html-format-latex, org-html-with-latex): Use renamed
org-latex-preview-* functions/variables.
* lisp/org.el (org-compute-latex-and-related-regexp,
org-latex-packages-alist): Use renamed org-latex-preview-*
functions/variables.
* lisp/org-latex-preview.el (org-dvipng-color, org-create-formula-image,
org--get-display-dpi, org-create-latex-export,
org-preview-latex--tex-styled, org-preview-precompile,
org-latex-preview--place-images, org-latex-preview--generic-callback,
org-latex-preview--image-extract-async,
org-preview-latex--create-tex-file, org-create-formula-image-async,
org-create-latex-preview, org-format-latex, org-latex-preview-fragments,
org-latex-replace-fragments, org-latex-preview,
org--latex-preview-region, org-clear-latex-preview,
org-latex-preview--handle-insert,
org-latex-preview--close-previous-overlay,
org-latex-preview--handle-post-cursor, org--make-preview-overlay,
org-latex-preview-auto-generate-p, org-preview-use-precompilation,
org-format-latex-header, org-preview-latex-process-alist,
org-preview-latex-default-process, org-format-latex-signal-error,
org-format-latex-options): Use renamed org-latex-preview-*
functions/variables. Use the org-latex-preview group instead of
org-latex for preview-related variables.
* lisp/org-compat.el: Add entries for renamed and obsoleted
org-latex-preview-* functions/variables.
* lisp/ob-latex.el (org-babel-execute:latex, org-format-latex-header)):
Use renamed org-latex-preview-* functions/variables.
* doc/org-manual.org (Footnotes, Previewing LaTeX fragments, LaTeX
fragments): Use renamed org-latex-preview-* functions/variables.
org-latex-preview: clear overlays name
* lisp/org-latex-preview.el (org-clear-latex-preview):
2023-01-01 04:09:52 +00:00
|
|
|
(defun org-latex-preview--normalize-color (value)
|
org.el: Relocate LaTeX preview code to new file
* lisp/org.el (org-format-latex-options, org-format-latex-signal-error,
org-latex-to-mathml-jar-file, org-latex-to-mathml-convert-command,
org-latex-to-html-convert-command, org-preview-latex-default-process,
org-preview-latex-process-alist, org-preview-latex-image-directory,
org-format-latex-header, org-format-latex-mathml-available-p,
org--make-preview-overlay, org-clear-latex-preview,
org--latex-preview-region, org-latex-preview, org-format-latex,
org-place-formula-image, org-create-math-formula,
org-format-latex-as-mathml, org-format-latex-as-html,
org--get-display-dpi, org-create-formula-image, org-dvipng-color,
org-dvipng-color-format, org-latex-color, org-latex-color-format,
org-normalize-color): Move to org-latex-preview.el.
* lisp/org-latex-preview.el: A new home for code related to the
generated of in-buffer previews of LaTeX fragments.
2022-12-25 15:52:25 +00:00
|
|
|
"Return string to be used as color value for an RGB component."
|
|
|
|
(format "%g" (/ value 65535.0)))
|
|
|
|
|
|
|
|
(provide 'org-latex-preview)
|
|
|
|
;;; org-latex-preview.el ends here
|