Subject: Re: bug#25322: preview-latex coding system problem with Japanese LaTeX

From: Ikumi Keita <[email-masked]>
Date: Fri, 19 May 2017 21:42:58 +0900

Hi Mosè, thanks for your reply!

>>>>> Mosè Giordano <[email-masked]> writes:

> I only read the patch, didn't actually try it, but I'm confident you
> did it ;-)  I didn't see anything clearly wrong.  I have only a
> request: do you think it's possible to add a test for this fix?

OK, I'll try.  Maybe it takes a week or so.  I'll also wait for possible
comments from others to arrive during that.

And I found another issue and made a patch which might be incorporated
as well.
Preview-latex on xemacs on w32 does not work except when
`preview-image-type' is set to `dvipng'.  It fails to call ghostscript
correctly and ghostscript signals error without generating any image
files.  The attached patch fixes this.  How do you think about this one?

[Background of the patch]
Preview-latex constructs path names like
"circ.prv/tmpkWCzEN/preview.dsc" and tries to pass them to ghostscript.
However, functions of xemacs on w32 uses backslash as path separator by
default when the return value is a file name, and
`preview-ps-quote-filename' is confused by this feature:

(defun preview-ps-quote-filename (str &optional nonrel)
  "Make a PostScript string from filename STR.
The file name is first made relative unless
NONREL is not NIL."
  (unless nonrel (setq str (file-relative-name str)))
  (let ((index 0))
    (while (setq index (string-match "[\\()]" str index))
      (setq str (replace-match "\\\\\\&" t nil str)
	    index (+ 2 index)))
    (concat "(" str ")")))

Here, `file-relative-name' converts slashes contained in `str' to
backslashes, each of which is duplicated by the while loop after it.  As
a result, the path names actually passed to ghostscript become like
"circ.prv\\tmpkWCzEN\\preview.dsc".  That's the reason ghostscript
signals error.

The behavior of w32 xemacs functions with respect to path separator
mentioned above is controlled by binding a suitable value to
`directory-sep-char', so the attatched patch takes care of that.  With
this change, preview-latex does work as expected, at least for the
xemacs 21.5 binary I found and installed on my machine.

I tried applying the previous patch, and to my delight, it makes
preview-latex to cooperate with Japanese LaTeX on w32 xemacs, too.

Regards,
Ikumi Keita

diff --git a/prv-xemacs.el b/prv-xemacs.el
--- a/prv-xemacs.el
+++ b/prv-xemacs.el
@@ -743,6 +743,12 @@
 				(nth 1 image)
 				(nth 2 image)))))
 
+(if (eq system-type 'windows-nt)
+    (defadvice preview-ps-quote-filename (around path-sep-to-slash)
+      "Make path separator to slash so that the function will not be confused."
+      (let ((directory-sep-char ?/))
+	ad-do-it)))
+
 (provide 'prv-xemacs)
 
 ;;; Local variables: