tecosaur / org-latex-preview-todos

A tracker for the Org LaTeX Preview effort on https://git.tecosaur.net/tec/org-mode
5 stars 0 forks source link

\frac previews in align environments not working #44

Closed egstatsml closed 1 day ago

egstatsml commented 3 days ago

Fraction environments not always working within an align environment.

Can show with an example,

\begin{align}
x = \frac{2}{\pi}
\end{align}

\begin{equation}
 x = \frac{2}{\pi}
\end{equation}

produces, image

This is on a clean install on emacs 29.4 and commit 684b01e6a29fd8eb31d721245774c3a127a03d15 from the dev branch of the org-preview-latex repo

Config is,


;;; Elpaca
(defvar elpaca-installer-version 0.7)
(defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
(defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
(defvar elpaca-repos-directory (expand-file-name "repos/" elpaca-directory))
(defvar elpaca-order '(elpaca :repo "https://github.com/progfolio/elpaca.git"
                              :ref nil :depth 1
                              :files (:defaults "elpaca-test.el" (:exclude "extensions"))
                              :build (:not elpaca--activate-package)))
(let* ((repo  (expand-file-name "elpaca/" elpaca-repos-directory))
       (build (expand-file-name "elpaca/" elpaca-builds-directory))
       (order (cdr elpaca-order))
       (default-directory repo))
  (add-to-list 'load-path (if (file-exists-p build) build repo))
  (unless (file-exists-p repo)
    (make-directory repo t)
    (when (< emacs-major-version 28) (require 'subr-x))
    (condition-case-unless-debug err
        (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
                 ((zerop (apply #'call-process `("git" nil ,buffer t "clone"
                                                 ,@(when-let ((depth (plist-get order :depth)))
                                                     (list (format "--depth=%d" depth) "--no-single-branch"))
                                                 ,(plist-get order :repo) ,repo))))
                 ((zerop (call-process "git" nil buffer t "checkout"
                                       (or (plist-get order :ref) "--"))))
                 (emacs (concat invocation-directory invocation-name))
                 ((zerop (call-process emacs nil buffer nil "-Q" "-L" "." "--batch"
                                       "--eval" "(byte-recompile-directory \".\" 0 'force)")))
                 ((require 'elpaca))
                 ((elpaca-generate-autoloads "elpaca" repo)))
            (progn (message "%s" (buffer-string)) (kill-buffer buffer))
          (error "%s" (with-current-buffer buffer (buffer-string))))
      ((error) (warn "%s" err) (delete-directory repo 'recursive))))
  (unless (require 'elpaca-autoloads nil t)
    (require 'elpaca)
    (elpaca-generate-autoloads "elpaca" repo)
    (load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))

;; Install use-package support
(elpaca elpaca-use-package
  ;; Enable use-package :ensure support for Elpaca.
  (elpaca-use-package-mode))

;;; org-mode latex preview
(use-package org
  :defer
  :ensure `(org
            :remotes ("tecosaur"
                      :repo "https://git.tecosaur.net/tec/org-mode.git"
                      :branch "dev")
            :files (:defaults ("etc/styles/" "etc/styles/*" "doc/*.texi"))
            :build t
            :pre-build
            (progn
              (with-temp-file "org-version.el"
        (require 'lisp-mnt)
        (let ((version
                       (with-temp-buffer
                         (insert-file-contents "lisp/org.el")
                         (lm-header "version")))
                      (git-version
                       (string-trim
            (with-temp-buffer
                          (call-process "git" nil t nil "rev-parse" "--short" "HEAD")
                          (buffer-string)))))
                  (insert
                   (format "(defun org-release () \"The release version of Org.\" %S)\n" version)
                   (format "(defun org-git-version () \"The truncate git commit hash of Org mode.\" %S)\n" git-version)
                   "(provide 'org-version)\n")))
              (require 'elpaca-menu-org)
              (elpaca-menu-org--build))
            :pin nil))

(use-package org-latex-preview
  :after org
  :config
  ;; Increase preview width
  (plist-put org-latex-preview-appearance-options
             :page-width 0.8)

  ;; Use dvisvgm to generate previews
  ;; You don't need this, it's the default:
  (setq org-latex-preview-process-default 'dvisvgm)

  ;; Turn on auto-mode, it's built into Org and much faster/more featured than
  ;; org-fragtog. (Remember to turn off/uninstall org-fragtog.)
  (add-hook 'org-mode-hook 'org-latex-preview-auto-mode)

  ;; Block C-n, C-p etc from opening up previews when using auto-mode
  (setq org-latex-preview-auto-ignored-commands
        '(next-line previous-line mwheel-scroll
            scroll-up-command scroll-down-command))

  ;; Enable consistent equation numbering
  (setq org-latex-preview-numbered t)

  ;; Bonus: Turn on live previews.  This shows you a live preview of a LaTeX
  ;; fragment and updates the preview in real-time as you edit it.
  ;; To preview only environments, set it to '(block edit-special) instead
  (setq org-latex-preview-live t)

  ;; More immediate live-previews -- the default delay is 1 second
  (setq org-latex-preview-live-debounce 0.25))
egstatsml commented 3 days ago

And the diagnostics info provided by org-latex-preview-check-health.el

Your LaTeX preview process

Precompile with latex → LaTeX Compile with pdflatex → Convert to SVG with dvisvgm

pdflatex
pdfTeX 3.141592653-2.6-1.40.26 (TeX Live 2024/Arch Linux)
/usr/bin/pdflatex

dvisvgm
dvisvgm 3.4.1
/usr/bin/dvisvgm

LaTeX preview options
• Precompilation           ON
• Equation renumbering     ON
• Caching with org-persist ON

LaTeX preview sizing
• Page width  0.8   (display equation width in LaTeX)
• Scale       1.00  (PNG pixel density multiplier)
• Zoom        1.00  (display scaling factor)

LaTeX preview preamble
\documentclass{article}
[DEFAULT-PACKAGES]
[PACKAGES]
\usepackage{xcolor}

Diagnostic info (copied)

(:image-converters
 (("convert" "WARNING: The convert command is deprecated in IMv7, use \"magick\" instead of \"convert\" or \"magick convert\"" "/usr/bin/convert")
  ("dvisvgm" "dvisvgm 3.4.1" "/usr/bin/dvisvgm")
  ("dvipng" "This is dvipng 1.17 Copyright 2002-2015, 2019 Jan-Ake Larsson" "/usr/bin/dvipng"))
 :latex-processors
 (("lualatex" "This is LuaHBTeX, Version 1.18.0 (TeX Live 2024/Arch Linux)" "/usr/bin/lualatex")
  ("xelatex" "XeTeX 3.141592653-2.6-0.999996 (TeX Live 2024/Arch Linux)" "/usr/bin/xelatex")
  ("pdflatex" "pdfTeX 3.141592653-2.6-1.40.26 (TeX Live 2024/Arch Linux)" "/usr/bin/pdflatex"))
 :interactive t :org-version "9.8-pre" :modified
 ((org-latex-preview-overlay-open-functions org-latex-preview-live--ensure-overlay t)
  (org-latex-preview-appearance-options :foreground auto :background "Transparent" :scale 1.0 :zoom 1.0 :page-width 0.8 :matchers
                    ("begin" "$1" "$" "$$" "\\(" "\\["))
  (org-persist-after-read-hook org-element--cache-persist-after-read)
  (org-persist-before-read-hook org-element--cache-persist-before-read)
  (org-latex-format-drawer-function .
                    #[514 "\207"
                      []
                      3 "\n\n(fn _ CONTENTS)"])
  (org-latex-format-headline-function . org-latex-format-headline-default-function)
  (org-latex-preview-live-debounce . 0.25)
  (org-latex-preview-process-alist
   (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" :latex-compiler
       ("%l -interaction nonstopmode -output-directory %o %f")
       :latex-precompiler
       ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
       :image-converter
       ("dvipng --follow -D %D -T tight --depth --height -o %B-%%09d.png %f")
       :transparent-image-converter
       ("dvipng --follow -D %D -T tight -bg Transparent --depth --height -o %B-%%09d.png %f"))
   (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" :latex-compiler
        ("%l -interaction nonstopmode -output-directory %o %f")
        :latex-precompiler
        ("%l -output-directory %o -ini -jobname=%b \"&%L\" mylatexformat.ltx %f")
        :image-converter
        ("dvisvgm --page=1- --optimize --clipjoin --relative --no-fonts -v3 --message='processing page {?pageno}: output written to {?svgfile}' --bbox=preview -o %B-%%9p.svg %f"))
   (imagemagick :programs
        ("pdflatex" "convert")
        :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")
        :latex-precompiler
        ("pdftex -output-directory %o -ini -jobname=%b \"&pdflatex\" mylatexformat.ltx %f")
        :image-converter
        ("convert -density %D -trim -antialias %f -quality 100 %B-%%09d.png")))
  (org-latex-preview-auto-ignored-commands next-line previous-line mwheel-scroll scroll-up-command scroll-down-command)
  (org-latex-preview-overlay-update-functions org-latex-preview-live--update-overlay t)
  (org-latex-format-inlinetask-function . org-latex-format-inlinetask-default-function)
  (org-persist-before-write-hook org-element--cache-persist-before-write)
  (org-latex-preview-overlay-close-functions org-latex-preview-live--clearout t)
  (org-latex-preview-process-finish-functions org-latex-preview-live--record-hook t)
  (org-latex-preview-live . t)))
karthink commented 3 days ago

Add amsmath to org-latex-packages-alist if you don't have it. See its documentation to figure out how to add it.

egstatsml commented 1 day ago

That fixed it, sorry I thought I checked this properly but only noticed that amsmath is only included with the default packages for lualatex or xetex. Added it and its fixed. Thanks for your help and for your work developing this feature, it is a huge improvement!