emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BUG] LaTeX preview should use a subdirectory in /tmp


From: Ihor Radchenko
Subject: Re: [BUG] LaTeX preview should use a subdirectory in /tmp
Date: Thu, 02 May 2024 10:30:14 +0000

Emmanuel Charpentier <emm.charpentier@free.fr> writes:

>> (plist-put (alist-get 'dvipng org-preview-latex-process-alist)
>>         :image-converter
>>            '("dvipng -D %D -T tight -o %O %F"))
>
> Nope, same problem : the *Org Preview LaTeX Output* buffer says :
>
> ../../../../../tmp/orgtexSyy18r.dvi: No such file or directory
> This is dvipng 1.15 Copyright 2002-2015 Jan-Ake Larsson
>
> If I understand it correctly, the %F placeholder should be an
> *absolute* filename. It is not...

May you try the attached patch?
I changed the default command templates to use absolute paths
everywhere.

>From 7ac1aacb977ded45dc713b24e18d9068baaa5148 Mon Sep 17 00:00:00 2001
Message-ID: 
<7ac1aacb977ded45dc713b24e18d9068baaa5148.1714645744.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Thu, 2 May 2024 13:19:37 +0300
Subject: [PATCH] org-preview-latex-process-alist: Work around relative path
 oddities in WSL

* lisp/org-macs.el (org-compile-file-commands): Add new allowed
placeholder %P - absolute path to output dir.
* lisp/org.el (org-preview-latex-process-alist): Use absolute paths
in commands.  List all the allowed placeholders in the docstring.

Reported-by: Emmanuel Charpentier <emm.charpentier@free.fr>
Link: https://orgmode.org/list/87zftr4uaj.fsf@localhost
---
 lisp/org-macs.el | 18 ++++++++++--------
 lisp/org.el      | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 1254ddb54..53dc75425 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -1690,12 +1690,12 @@ (defun org-compile-file-commands (source process ext 
&optional spec err-msg)
 the SOURCE file.
 
 If PROCESS is a list of commands, each of them is called using
-`shell-command'.  By default, in each command, %b, %f, %F, %o and
-%O are replaced with, respectively, SOURCE base name, relative
-file name, absolute file name, relative directory and absolute
-output file name.  It is possible, however, to use more
-place-holders by specifying them in optional argument SPEC, as an
-alist following the pattern
+`shell-command'.  By default, in each command, %b, %f, %F, %o, %P, and
+%O are replaced with, respectively, SOURCE base name, relative file
+name, absolute file name, relative output directory, absolute output
+directory, and absolute output file name.  It is possible, however, to
+use more place-holders by specifying them in optional argument SPEC,
+as an alist following the pattern
 
   (CHARACTER . REPLACEMENT-STRING).
 
@@ -1707,9 +1707,10 @@ (defun org-compile-file-commands (source process ext 
&optional spec err-msg)
          (pwd (file-truename default-directory))
          (absname (expand-file-name source pwd))
          (relname (if (file-name-absolute-p source)
-                        (file-relative-name source pwd)
-                      source))
+                      (file-relative-name source pwd)
+                    source))
         (relpath (or (file-name-directory relname) "./"))
+         (abspath (expand-file-name relpath))
         (output (concat (file-name-sans-extension absname) "." ext))
         (err-msg (if (stringp err-msg) (concat ".  " err-msg) "")))
     (pcase process
@@ -1720,6 +1721,7 @@ (defun org-compile-file-commands (source process ext 
&optional spec err-msg)
                             (?f . ,(shell-quote-argument relname))
                             (?F . ,(shell-quote-argument absname))
                             (?o . ,(shell-quote-argument relpath))
+                             (?P . ,(shell-quote-argument abspath))
                             (?O . ,(shell-quote-argument output))))))
          (mapcar (lambda (command) (format-spec command spec)) process)))
       (_ (error "No valid command to process %S%s" source err-msg)))))
diff --git a/lisp/org.el b/lisp/org.el
index 809fd8ba3..1c78c2024 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3326,10 +3326,10 @@ (defcustom org-preview-latex-process-alist
      :image-input-type "dvi"
      :image-output-type "png"
      :image-size-adjust (1.0 . 1.0)
-     :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
-     :image-converter ("dvipng -D %D -T tight -o %O %f")
+     :latex-compiler ("latex -interaction nonstopmode -output-directory %P %F")
+     :image-converter ("dvipng -D %D -T tight -o %O %F")
      :transparent-image-converter
-     ("dvipng -D %D -T tight -bg Transparent -o %O %f"))
+     ("dvipng -D %D -T tight -bg Transparent -o %O %F"))
     (dvisvgm
      :programs ("latex" "dvisvgm")
      :description "dvi > svg"
@@ -3337,7 +3337,7 @@ (defcustom org-preview-latex-process-alist
      :image-input-type "dvi"
      :image-output-type "svg"
      :image-size-adjust (1.7 . 1.5)
-     :latex-compiler ("latex -interaction nonstopmode -output-directory %o %f")
+     :latex-compiler ("latex -interaction nonstopmode -output-directory %P %F")
      :image-converter ("dvisvgm %f --no-fonts --exact-bbox --scale=%S 
--output=%O"))
     (imagemagick
      :programs ("latex" "convert")
@@ -3346,9 +3346,9 @@ (defcustom org-preview-latex-process-alist
      :image-input-type "pdf"
      :image-output-type "png"
      :image-size-adjust (1.0 . 1.0)
-     :latex-compiler ("pdflatex -interaction nonstopmode -output-directory %o 
%f")
+     :latex-compiler ("pdflatex -interaction nonstopmode -output-directory %P 
%F")
      :image-converter
-     ("convert -density %D -trim -antialias %f -quality 100 %O")))
+     ("convert -density %D -trim -antialias %F -quality 100 %O")))
   "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
@@ -3389,9 +3389,11 @@ (defcustom org-preview-latex-process-alist
 
 Place-holders used by `:image-converter' and `:latex-compiler':
 
-  %f    input file name
+  %f    input file name (relative)
+  %F    input file name (absolute)
   %b    base name of input file
-  %o    base directory of input file
+  %o    base directory of input file (relative)
+  %P    base directory of input file (absolute)
   %O    absolute output file name
 
 Place-holders only used by `:image-converter':
-- 
2.44.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]