emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Emmanuel Charpentier <emm.charpentier@free.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: [BUG] LaTeX preview should use a subdirectory in /tmp
Date: Thu, 02 May 2024 10:30:14 +0000	[thread overview]
Message-ID: <87edakbj61.fsf@localhost> (raw)
In-Reply-To: <59096bd365ccf1cb3ec2b45b0f2ecb5c508ded34.camel@free.fr>

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-preview-latex-process-alist-Work-around-relative.patch --]
[-- Type: text/x-patch, Size: 5568 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
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>

  parent reply	other threads:[~2024-05-02 10:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 15:21 [BUG] LaTeX preview should use a subdirectory in /tmp Emmanuel Charpentier
2024-04-17 16:48 ` Ihor Radchenko
2024-04-17 20:04   ` Emmanuel Charpentier
2024-04-17 20:18     ` Ihor Radchenko
2024-04-17 20:41       ` Emmanuel Charpentier
2024-04-18 12:23         ` Emmanuel Charpentier
2024-04-19 11:56         ` Ihor Radchenko
2024-04-19 15:00           ` emm.charpentier
2024-04-20 12:49             ` Max Nikulin
2024-05-02 10:30     ` Ihor Radchenko [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-04-17 15:12 copropriete27ruemoret
2024-03-25 10:40 Max Nikulin
2024-03-25 11:40 ` Ihor Radchenko
2024-03-25 12:49   ` Max Nikulin
2024-03-26 11:29     ` Max Nikulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edakbj61.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=emm.charpentier@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).