forked from mirrors/org-mode
org-latex-preview: Better handle temp/remote files
* lisp/org-latex-preview.el (org-latex-preview-precompile, org-latex-preview--create-tex-file): Before obtaining the (compiled) preamble, check for the temp-ness and remote-ness of the file, and act accordingly. Non-temp remote files are not currently supported, and an error will now be thrown in such cases. The temporary file status is now passed on to `org-latex-preview-precompile' and through to `org-latex--precompile'.
This commit is contained in:
parent
96dc874f91
commit
ec8662aa82
|
@ -1476,23 +1476,30 @@ FRAGMENTS will be placed in order, wrapped within a
|
||||||
\"preview\" environment.
|
\"preview\" environment.
|
||||||
|
|
||||||
The path of the created LaTeX file is returned."
|
The path of the created LaTeX file is returned."
|
||||||
(let ((tex-temp-name
|
(let* ((header
|
||||||
(expand-file-name (concat (make-temp-name "org-tex-") ".tex")))
|
(concat
|
||||||
(header
|
(or (plist-get processing-info :latex-header)
|
||||||
(concat
|
org-latex-preview--preamble-content
|
||||||
(or (plist-get processing-info :latex-header)
|
(setq org-latex-preview--preamble-content
|
||||||
org-latex-preview--preamble-content
|
(org-latex-preview--get-preamble)))
|
||||||
(setq org-latex-preview--preamble-content
|
(let ((w org-latex-preview-width))
|
||||||
(org-latex-preview--get-preamble)))
|
(cond
|
||||||
(let ((w org-latex-preview-width))
|
((stringp w)
|
||||||
(cond
|
(format "\n\\setlength{\\textwidth}{%s}\n" w))
|
||||||
((stringp w)
|
((and (floatp w) (<= 0.0 w 1.0))
|
||||||
(format "\n\\setlength{\\textwidth}{%s}\n" w))
|
(format "\n\\setlength{\\textwidth}{%s\\paperwidth}\n" w))))
|
||||||
((and (floatp w) (<= 0.0 w 1.0))
|
"\n\\usepackage[active,tightpage,auctex]{preview}\n"))
|
||||||
(format "\n\\setlength{\\textwidth}{%s\\paperwidth}\n" w))))
|
(relative-file-p
|
||||||
"\n\\usepackage[active,tightpage,auctex]{preview}\n"))
|
(string-match-p "\\(?:\\\\input{\\|\\\\include{\\)[^/]" header))
|
||||||
(write-region-inhibit-fsync t)
|
(remote-file-p (file-remote-p default-directory))
|
||||||
(coding-system-for-write buffer-file-coding-system))
|
(tex-temp-name
|
||||||
|
(expand-file-name
|
||||||
|
(concat (make-temp-name "org-tex-") ".tex")
|
||||||
|
(and remote-file-p temporary-file-directory)))
|
||||||
|
(write-region-inhibit-fsync t)
|
||||||
|
(coding-system-for-write buffer-file-coding-system))
|
||||||
|
(when (and relative-file-p remote-file-p)
|
||||||
|
(error "Org LaTeX Preview does not currently support \\input/\\include in remote files"))
|
||||||
(when org-latex-preview-use-precompilation
|
(when org-latex-preview-use-precompilation
|
||||||
(if-let ((format-file (org-latex-preview-precompile processing-info header)))
|
(if-let ((format-file (org-latex-preview-precompile processing-info header)))
|
||||||
;; Replace header with .fmt file path.
|
;; Replace header with .fmt file path.
|
||||||
|
@ -2135,13 +2142,16 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
|
||||||
(message "Cleared LaTeX preview cache for %s."
|
(message "Cleared LaTeX preview cache for %s."
|
||||||
(if (or beg end) "region" "buffer")))))
|
(if (or beg end) "region" "buffer")))))
|
||||||
|
|
||||||
(defun org-latex-preview-precompile (processing-info preamble)
|
(defun org-latex-preview-precompile (processing-info preamble &optional tempfile-p)
|
||||||
"Precompile/dump LaTeX PREAMBLE text.
|
"Precompile/dump LaTeX PREAMBLE text.
|
||||||
|
|
||||||
The path to the format file (.fmt) is returned. If the format
|
The path to the format file (.fmt) is returned. If the format
|
||||||
file could not be found in the persist cache, it is generated
|
file could not be found in the persist cache, it is generated
|
||||||
according to PROCESSING-INFO and stored.
|
according to PROCESSING-INFO and stored.
|
||||||
|
|
||||||
|
If TEMPFILE-P is non-nil, then it is assumed the preamble does
|
||||||
|
not contain any relative references to other files.
|
||||||
|
|
||||||
This is intended to speed up Org's LaTeX preview generation
|
This is intended to speed up Org's LaTeX preview generation
|
||||||
process."
|
process."
|
||||||
(org-latex--precompile
|
(org-latex--precompile
|
||||||
|
@ -2152,7 +2162,8 @@ process."
|
||||||
org-latex-preview-compiler-command-map))))
|
org-latex-preview-compiler-command-map))))
|
||||||
`((?l . ,org-tex-compiler)
|
`((?l . ,org-tex-compiler)
|
||||||
(?L . ,(car (split-string org-tex-compiler))))))
|
(?L . ,(car (split-string org-tex-compiler))))))
|
||||||
preamble))
|
preamble
|
||||||
|
tempfile-p))
|
||||||
|
|
||||||
(defun org-latex-preview--tex-styled (processing-type value options &optional html-p)
|
(defun org-latex-preview--tex-styled (processing-type value options &optional html-p)
|
||||||
"Apply LaTeX style commands to VALUE based on OPTIONS.
|
"Apply LaTeX style commands to VALUE based on OPTIONS.
|
||||||
|
|
Loading…
Reference in New Issue