org-latex-preview: Fix xelatex preview image sizes

*
lisp/org-latex-preview.el (org-latex-preview--include-preview-string,
org-latex-preview--latex-preview-filter):  when xetex is used,
preview.sty assumes PDF output by default and does not write any
postscript data to the output XDV file.  This makes dvisvgm unable to
correctly determine the preview geometry.  Fix by specifying the
`dvips' option to preview, which adds (apparently as a side effect)
this geometry information to the XDV file.

Remove a conditional in `org-latex-preview--latex-preview-filter' that
was previously used to attempt to work around this issue.
This commit is contained in:
Karthik Chikmagalur 2023-10-08 16:04:12 -07:00 committed by TEC
parent 3b7c6faf9f
commit f206164ef4
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 19 additions and 7 deletions

View File

@ -1475,8 +1475,24 @@ previews."
org-latex-preview--single-eqn-format)))))))
(defconst org-latex-preview--include-preview-string
"\n\\usepackage[active,tightpage,auctex]{preview}\n"
"A LaTeX preamble snippet that includes preview.sty for previews.")
"\n\\usepackage[active,tightpage,auctex,dvips]{preview}\n"
"A LaTeX preamble snippet that includes preview.sty for previews.
The options passed to preview.sty are:
- active: activate preview package
- auctex: Produce fake error messages at the start and end of
every preview environment. We use this to help with parsing
the tex compilation stdout using regexes.
- tightpage: (effectively) shrink page sizes to fit each
previewed math environment.
- dvips: Only required for xelatex runs. Add (as a side effect)
preview geometry data to the output XDV file.
This is an abridged summary. See the documentation of
preview.sty for more details.")
(defun org-latex-preview--create-tex-file (processing-info fragments)
"Create a LaTeX file based on PROCESSING-INFO and FRAGMENTS.
@ -1812,11 +1828,7 @@ fragments in EXTENDED-INFO."
(setq preview-marks (nreverse preview-marks))
(while preview-marks
(goto-char (caar preview-marks))
;; Check for tightpage-info, as long as XeLaTeX is not being used,
;; as it seems to behave differently to pdfLaTeX and luaLaTeX and
;; produces an image without the margins that tightpage reports.
(unless (or tightpage-info (equal (plist-get extended-info :latex-processor)
"xelatex"))
(unless tightpage-info
(save-excursion
(when (re-search-forward
"^Preview: Tightpage \\(-?[0-9]+\\) *\\(-?[0-9]+\\) *\\(-?[0-9]+\\) *\\(-?[0-9]+\\)"