all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [BUG] LaTeX preview should use a subdirectory in /tmp
@ 2024-03-25 10:40 Max Nikulin
  2024-03-25 11:40 ` Ihor Radchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Max Nikulin @ 2024-03-25 10:40 UTC (permalink / raw)
  To: emacs-orgmode

This is a follow-up to recent changes related to LaTeX preview.

This feature should not write temporary files to /tmp directly, some 
subdirectory should be created for this purpose. The idea is to mitigate 
consequences if a user opens a file from a compromised or a malicious 
source and gets /tmp flooded with a crowd of files. It is easier to 
delete single directory than to spent time trying to figure out what 
files are necessary for other applications and what ones are generated 
by LaTeX code.

P.S. I do not mind double level structure: all temporary Org mode files 
(babel, etc.) are created in single (per Emacs process) directory in tmp 
and each task creates its own subdirectory there.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-03-25 10:40 [BUG] LaTeX preview should use a subdirectory in /tmp Max Nikulin
@ 2024-03-25 11:40 ` Ihor Radchenko
  2024-03-25 12:49   ` Max Nikulin
  0 siblings, 1 reply; 16+ messages in thread
From: Ihor Radchenko @ 2024-03-25 11:40 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

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

Max Nikulin <manikulin@gmail.com> writes:

> This feature should not write temporary files to /tmp directly, some 
> subdirectory should be created for this purpose. The idea is to mitigate 
> consequences if a user opens a file from a compromised or a malicious 
> source and gets /tmp flooded with a crowd of files. It is easier to 
> delete single directory than to spent time trying to figure out what 
> files are necessary for other applications and what ones are generated 
> by LaTeX code.

See the attached tentative patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-create-formula-image-Keep-temporary-LaTeX-files-.patch --]
[-- Type: text/x-patch, Size: 1206 bytes --]

From df4d827d98063ee665d71906f358ca08ad4d0023 Mon Sep 17 00:00:00 2001
Message-ID: <df4d827d98063ee665d71906f358ca08ad4d0023.1711366791.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Mon, 25 Mar 2024 14:38:42 +0300
Subject: [PATCH] org-create-formula-image: Keep temporary LaTeX files in
 subfir of /tmp

* lisp/org.el (org-create-formula-image): When compiling formula
images, keep temporary LaTeX logs in a subdirectory of
`temporary-file-directory' instead of littering the top-level /tmp.

Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/utrkah$4s0$1@ciao.gmane.io
---
 lisp/org.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index f0f85822f..0793b72d6 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16361,7 +16361,7 @@ (defun org-create-formula-image
 	       org-format-latex-header
 	       'snippet)))
 	 (latex-compiler (plist-get processing-info :latex-compiler))
-	 (tmpdir temporary-file-directory)
+	 (tmpdir (concat temporary-file-directory "orgtex/"))
 	 (texfilebase (make-temp-name
 		       (expand-file-name "orgtex" tmpdir)))
 	 (texfile (concat texfilebase ".tex"))
-- 
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>

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-03-25 11:40 ` Ihor Radchenko
@ 2024-03-25 12:49   ` Max Nikulin
  2024-03-26 11:29     ` Max Nikulin
  0 siblings, 1 reply; 16+ messages in thread
From: Max Nikulin @ 2024-03-25 12:49 UTC (permalink / raw)
  To: emacs-orgmode

On 25/03/2024 18:40, Ihor Radchenko wrote:
> Max Nikulin writes:
>> This feature should not write temporary files to /tmp directly
> 
> See the attached tentative patch.

Thanks for prompt reaction.

> +++ b/lisp/org.el
> @@ -16361,7 +16361,7 @@ (defun org-create-formula-image
>  	       org-format-latex-header
>  	       'snippet)))
>  	 (latex-compiler (plist-get processing-info :latex-compiler))
> -	 (tmpdir temporary-file-directory)
> +	 (tmpdir (concat temporary-file-directory "orgtex/"))
>  	 (texfilebase (make-temp-name
>  		       (expand-file-name "orgtex" tmpdir)))

Since directory name already contains "org", it may be shortened to just 
"tex"

>  	 (texfile (concat texfilebase ".tex"))

I would use `make-temp-file' to create TEXFILE and would derive 
TEXFILEBASE from it. In general it is safer.

To create directory I expect a call of a function similar to the 
following one. Perhaps it exists already somewhere.

(defun org-ensure-tmp-dir (dir-symbol prefix)
   (let ((dir (symbol-value dir-symbol)))
     ;; Temporary directory has not been cleaned.
     (or (and dir (file-directory-p dir) dir)
	(setf (symbol-value dir-symbol)
	      (make-temp-file (or prefix "orgtmp-") 'dir)))))

(defvar org-tex-tmpdir nil)

Usage example: (org-ensure-tmp-dir 'org-tex-tmpdir "orgtex-")

Fixed directory name is not friendly for multi-user systems and 
predictable name in /tmp might be a source of security issues.



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-03-25 12:49   ` Max Nikulin
@ 2024-03-26 11:29     ` Max Nikulin
  0 siblings, 0 replies; 16+ messages in thread
From: Max Nikulin @ 2024-03-26 11:29 UTC (permalink / raw)
  To: emacs-orgmode

On 25/03/2024 19:49, Max Nikulin wrote:

> (defun org-ensure-tmp-dir (dir-symbol prefix)
>    (let ((dir (symbol-value dir-symbol)))
>      ;; Temporary directory has not been cleaned.
>      (or (and dir (file-directory-p dir) dir)

`if' should be used instead of `or' here.

>      (setf (symbol-value dir-symbol)
>            (make-temp-file (or prefix "orgtmp-") 'dir)))))
> 
> (defvar org-tex-tmpdir nil)
> 
> Usage example: (org-ensure-tmp-dir 'org-tex-tmpdir "orgtex-")

I do not like that the function may be called with different 
`temporary-file-directory' and I can not figure out how to adjust API to 
handle such case. On the other hand I am unsure if it is a realistic 
case when this function is called with alternating 
`temporary-file-directory'.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
@ 2024-04-17 15:12 copropriete27ruemoret
  0 siblings, 0 replies; 16+ messages in thread
From: copropriete27ruemoret @ 2024-04-17 15:12 UTC (permalink / raw)
  To: manikulin, emacs-orgmode

On 25/03/2024 19:49, Max Nikulin wrote:

> > (defun org-ensure-tmp-dir (dir-symbol prefix)
> >    (let ((dir (symbol-value dir-symbol)))
> >      ;; Temporary directory has not been cleaned.
> >      (or (and dir (file-directory-p dir) dir)
>
>
>`if' should be used instead of `or' here.
>
>
>
>>
>>     (setf (symbol-value dir-symbol)
>>           (make-temp-file (or prefix "orgtmp-") 'dir)))))
>> 
>> (defvar org-tex-tmpdir nil)
>> 
>> Usage example: (org-ensure-tmp-dir 'org-tex-tmpdir "orgtex-")

> I do not like that the function may be called with different `temporary-file-directory' and I can not figure out how to adjust API to handle such case. On the other hand I am unsure if it is a realistic case when this function is called with alternating `temporary-file-directory'.  

I have a case where the current way of forcing the temporary directory to me `/tmp` is wrong. Running emacs on Ubuntu **under WSL2**,, exporting latex snippets to ODT *as images* fails : the `.dvi` files are correctly compiled and placed in `/tmp{, but the convert program tries to read them in `../../../../tmp/`, which is indeed `/tmp` in a "normal" filesystem but **is not** in WSL, where the root (`/`) is in fact a mounted tree.

Admittedly, this is a corner case, but it turned out to be necessary (exporting via mathml gave unsatisfying results).


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
@ 2024-04-17 15:21 Emmanuel Charpentier
  2024-04-17 16:48 ` Ihor Radchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Emmanuel Charpentier @ 2024-04-17 15:21 UTC (permalink / raw)
  To: manikulin, emacs-orgmode

On 25/03/2024 19:49, Max Nikulin wrote:

> > (defun org-ensure-tmp-dir (dir-symbol prefix)
> >    (let ((dir (symbol-value dir-symbol)))
> >      ;; Temporary directory has not been cleaned.
> >      (or (and dir (file-directory-p dir) dir)
>
>
>`if' should be used instead of `or' here.
>
>
>
>>
>>     (setf (symbol-value dir-symbol)
>>           (make-temp-file (or prefix "orgtmp-") 'dir)))))
>> 
>> (defvar org-tex-tmpdir nil)
>> 
>> Usage example: (org-ensure-tmp-dir 'org-tex-tmpdir "orgtex-")

> I do not like that the function may be called with
different `temporary-file-directory' and I can not figure out how to
adjust API to handle such case. On the other hand I am unsure if it is
a realistic case when this function is called with
alternating `temporary-file-directory'.  

I have a case where the current way of forcing the temporary directory
to me `/tmp` is wrong. Running emacs on Ubuntu **under WSL2**,,
exporting latex snippets to ODT *as images* fails : the `.dvi` files
are correctly compiled and placed in `/tmp{, but the convert program
tries to read them in `../../../../tmp/`, which is indeed `/tmp` in a
"normal" filesystem but **is not** in WSL, where the root (`/`) is in
fact a mounted tree.

Admittedly, this is a corner case, but it turned out to be necessary
(exporting via mathml gave unsatisfying results).




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-17 15:21 Emmanuel Charpentier
@ 2024-04-17 16:48 ` Ihor Radchenko
  2024-04-17 20:04   ` Emmanuel Charpentier
  0 siblings, 1 reply; 16+ messages in thread
From: Ihor Radchenko @ 2024-04-17 16:48 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: manikulin, emacs-orgmode

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

> I have a case where the current way of forcing the temporary directory
> to me `/tmp` is wrong. Running emacs on Ubuntu **under WSL2**,,
> exporting latex snippets to ODT *as images* fails : the `.dvi` files
> are correctly compiled and placed in `/tmp{, but the convert program
> tries to read them in `../../../../tmp/`, which is indeed `/tmp` in a
> "normal" filesystem but **is not** in WSL, where the root (`/`) is in
> fact a mounted tree.
>
> Admittedly, this is a corner case, but it turned out to be necessary
> (exporting via mathml gave unsatisfying results).

It looks like is a different bug. (probably even in Emacs, when
calculating relative path)

Assuming that your `org-preview-latex-default-process' is using the
default value of 'dvipng, does it help if you change the image convertor
command to use absolute path?

(plist-put (alist-get 'dvipng org-preview-latex-process-alist)
	   :image-converter
           '("dvipng -D %D -T tight -o %O %F"))

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-17 16:48 ` Ihor Radchenko
@ 2024-04-17 20:04   ` Emmanuel Charpentier
  2024-04-17 20:18     ` Ihor Radchenko
  2024-05-02 10:30     ` Ihor Radchenko
  0 siblings, 2 replies; 16+ messages in thread
From: Emmanuel Charpentier @ 2024-04-17 20:04 UTC (permalink / raw)
  To: Ihor Radchenko, emacs-orgmode

Le mercredi 17 avril 2024 à 16:48 +0000, Ihor Radchenko a écrit :
> Emmanuel Charpentier <emm.charpentier@free.fr> writes:
> 
> > I have a case where the current way of forcing the temporary
> > directory
> > to me `/tmp` is wrong. Running emacs on Ubuntu **under WSL2**,,
> > exporting latex snippets to ODT *as images* fails : the `.dvi`
> > files
> > are correctly compiled and placed in `/tmp{, but the convert
> > program
> > tries to read them in `../../../../tmp/`, which is indeed `/tmp` in
> > a
> > "normal" filesystem but **is not** in WSL, where the root (`/`) is
> > in
> > fact a mounted tree.
> > 
> > Admittedly, this is a corner case, but it turned out to be
> > necessary
> > (exporting via mathml gave unsatisfying results).
> 
> It looks like is a different bug. (probably even in Emacs, when
> calculating relative path)

That might also be an idiosyncratic bug of WSL2' implementation of the
virtual machine filesystem...
> 
> Assuming that your `org-preview-latex-default-process' is using the
> default value of 'dvipng, does it help if you change the image
> convertor
> command to use absolute path?

I didn't know that one could do that : the placeholders are not well
documented...

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

Couldn't the output directory of the :latex-compiler element being
hardcoded to, say, the curerent directory or a subdirectory thereof,
and ditto for the input directory of :image-converter ?

Sincerely,




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-17 20:04   ` Emmanuel Charpentier
@ 2024-04-17 20:18     ` Ihor Radchenko
  2024-04-17 20:41       ` Emmanuel Charpentier
  2024-05-02 10:30     ` Ihor Radchenko
  1 sibling, 1 reply; 16+ messages in thread
From: Ihor Radchenko @ 2024-04-17 20:18 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: emacs-orgmode

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

>> Assuming that your `org-preview-latex-default-process' is using the
>> default value of 'dvipng, does it help if you change the image
>> convertor
>> command to use absolute path?
>
> I didn't know that one could do that : the placeholders are not well
> documented...

Yeah. This particular option is missing from the docstring of
`org-preview-latex-process-alist'.

>> (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...
>
> Couldn't the output directory of the :latex-compiler element being
> hardcoded to, say, the curerent directory or a subdirectory thereof,
> and ditto for the input directory of :image-converter ?

What if you do M-x trace-function <RET> org-compile-file-commands <RET>
and run the preview.
Then, a buffer should appear listing the command expansions used during
the preview process. May you then share that buffer?

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  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
  0 siblings, 2 replies; 16+ messages in thread
From: Emmanuel Charpentier @ 2024-04-17 20:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Le mercredi 17 avril 2024 à 20:18 +0000, Ihor Radchenko a écrit :
> Emmanuel Charpentier <emm.charpentier@free.fr> writes:

[ Snip... ]


> What if you do M-x trace-function <RET> org-compile-file-commands

No such function : I just have  org-compile-file , which I traced.

> <RET>
> and run the preview.
> Then, a buffer should appear listing the command expansions used
> during
> the preview process. May you then share that buffer?

Here it comes :

Buffer "Trace output" :

*****
======================================================================
1 -> (org-compile-file "/tmp/orgtexD0afvR.tex" ("latex -interaction
nonstopmode -output-directory %o %f") "dvi" "Please adjust `dvipng'
part of `org-preview-latex-process-alist'." #<buffer *Org Preview LaTeX
Output*>)
1 <- org-compile-file: "/tmp/orgtexD0afvR.dvi"
======================================================================
1 -> (org-compile-file "/tmp/orgtexD0afvR.dvi" ("dvipng -D %D -T tight
-bg Transparent -o %O %f") "png" "Please adjust `dvipng' part of `org-
preview-latex-process-alist'." #<buffer *Org Preview LaTeX Output*>
((68 . "140.0") (83 . "1.0")))
1 <- org-compile-file: !non-local\ exit!
*****

Buffer "*Org Preview LaTeX Output*" :

*****
../../../../../tmp/orgtexD0afvR.dvi: No such file or directory
This is dvipng 1.15 Copyright 2002-2015 Jan-Ake Larsson
*****

HTH,




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-17 20:41       ` Emmanuel Charpentier
@ 2024-04-18 12:23         ` Emmanuel Charpentier
  2024-04-19 11:56         ` Ihor Radchenko
  1 sibling, 0 replies; 16+ messages in thread
From: Emmanuel Charpentier @ 2024-04-18 12:23 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

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

Le mercredi 17 avril 2024 à 22:41 +0200, Emmanuel Charpentier a écrit :
[ Snip... ]
A couple more data points :
 * The problem I described happens when I run `emacs` on files
   belonging in a Windows tree, symlinked to the Linux tree. Running
   `emacs` on files outside this symlinked tree works OK.
   This suggests that it might be worth testing trhese exports from
   network directories.
   
 * Trying this with the current Org from the git directory succesfully
   builds the images but fails at inserting them in the `.odt` file
   (Org mistakenly inserts the "file:" string in the name of the needed
   image file).

 * Trying `dvisvgm` fails because Org does not recognize this as a
   valid format and insists on `verbatim`.

HTH,


[-- Attachment #2: Type: text/html, Size: 1192 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  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
  1 sibling, 1 reply; 16+ messages in thread
From: Ihor Radchenko @ 2024-04-19 11:56 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: emacs-orgmode

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

>> What if you do M-x trace-function <RET> org-compile-file-commands
>
> No such function : I just have  org-compile-file , which I traced.

May you try the development branch of Org mode (main)?

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-19 11:56         ` Ihor Radchenko
@ 2024-04-19 15:00           ` emm.charpentier
  2024-04-20 12:49             ` Max Nikulin
  0 siblings, 1 reply; 16+ messages in thread
From: emm.charpentier @ 2024-04-19 15:00 UTC (permalink / raw)
  To: Ihor Radchenko, emacs-orgmode

I can M-x trace-function org-compile-file-commands (whic now appears in the auocompletions) but, curiously, I *dp* **not** get a ttace output buffer.

Exporting still fails with :
========================================================
org-babel-exp process emacs-lisp at position 194...
Formatting LaTeX using dvipng
Creating LaTeX Image 1...
Creating LaTeX Image 2...
Embedding /home/charpent/WinFiles/Temporaire/Org/file:ltximg/EssaiSnippetsLaTeX_2923a1941c0e63eab69544afa1be2ec0d95a01c4.png as Images/0001.png...
condition-case: OpenDocument export failed: Opening input file: No such file or directory, /home/charpent/WinFiles/Temporaire/Org/file:ltximg/EssaiSnippetsLaTeX_2923a1941c0e63eab69544afa1be2ec0d95a01c4.png
Making completion list...
Quit [8 times]
========================================================
in the *Messages* buffer.

I am at loss..

--
Emmanuel Charpentier


----- Mail original -----
> De: "Ihor Radchenko" <yantar92@posteo.net>
> À: "Emmanuel Charpentier" <emm.charpentier@free.fr>
> Cc: emacs-orgmode@gnu.org
> Envoyé: Vendredi 19 Avril 2024 13:56:52
> Objet: Re: [BUG] LaTeX preview should use a subdirectory in /tmp
> 
> Emmanuel Charpentier <emm.charpentier@free.fr> writes:
> 
> >> What if you do M-x trace-function <RET> org-compile-file-commands
> >
> > No such function : I just have  org-compile-file , which I traced.
> 
> May you try the development branch of Org mode (main)?
> 
> --
> 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>
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-19 15:00           ` emm.charpentier
@ 2024-04-20 12:49             ` Max Nikulin
  0 siblings, 0 replies; 16+ messages in thread
From: Max Nikulin @ 2024-04-20 12:49 UTC (permalink / raw)
  To: emm.charpentier, emacs-orgmode

On 19/04/2024 22:00, emm.charpentier@free.fr wrote:
> Embedding /home/charpent/WinFiles/Temporaire/Org/file:ltximg/EssaiSnippetsLaTeX_2923a1941c0e63eab69544afa1be2ec0d95a01c4.png as Images/0001.png...

See

Ihor Radchenko. Re: strange export problem with a file: link. Sat, 20 
Apr 2024 12:25:56 +0000.
https://list.orgmode.org/87cyqkmd9n.fsf@localhost



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-04-17 20:04   ` Emmanuel Charpentier
  2024-04-17 20:18     ` Ihor Radchenko
@ 2024-05-02 10:30     ` Ihor Radchenko
  2024-07-03 11:23       ` Ihor Radchenko
  1 sibling, 1 reply; 16+ messages in thread
From: Ihor Radchenko @ 2024-05-02 10:30 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: emacs-orgmode

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

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [BUG] LaTeX preview should use a subdirectory in /tmp
  2024-05-02 10:30     ` Ihor Radchenko
@ 2024-07-03 11:23       ` Ihor Radchenko
  0 siblings, 0 replies; 16+ messages in thread
From: Ihor Radchenko @ 2024-07-03 11:23 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

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

No response after 2 months.
Since I do not have a reproducer, I cannot confirm that the patch is an
improvement. So, not merging.

Canceled.

If anyone else is experiencing the same problem, feel free to jump in to
revive the thread.

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


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-07-03 11:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-25 10:40 [BUG] LaTeX preview should use a subdirectory in /tmp Max Nikulin
2024-03-25 11:40 ` Ihor Radchenko
2024-03-25 12:49   ` Max Nikulin
2024-03-26 11:29     ` Max Nikulin
  -- strict thread matches above, loose matches on Subject: below --
2024-04-17 15:12 copropriete27ruemoret
2024-04-17 15:21 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
2024-07-03 11:23       ` Ihor Radchenko

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.