1

I faced a problem when pdflatex launched from Emacs couldn't compile files whose name contained Russian characters. The same code worked on Linux, so I suspected that something is wrong with encoding of file name. OS: Windows XP, file system encoding is cp-1251, Emacs: 24.5.1.

I created 2 files:

  • D:/Russia.tex
  • D:/Россия.tex

Then I tried this:

;works fine, produces Russia.pdf
(shell-command "pdflatex D:/Russia.tex")

;doesn't work. TeX error: I can't find file `D:/Россия.tex'
(shell-command "pdflatex D:/Россия.tex")

Then I tried to convert the Russian name to cp-1251:

;This works, but hard-coded 'cp1251 is bad
(setq file-name (encode-coding-string "D:/Россия.tex" 'cp1251))
(shell-command (concat "pdflatex " file-name))

This code has 1 defect - the file system encoding is hard-coded. Encoding and I/O page says that there is a variable file-name-coding-system --- "specifies the coding system to use for encoding file names". But it is nil for me.

Also the fact that utf-8 code doesn't work is weird as the page says:

On Windows 2000 and later, Emacs by default uses Unicode APIs to pass file names to the OS, so the value of file-name-coding-system is largely ignored. Lisp applications that need to encode or decode file names on the Lisp level should use utf-8 coding-system when system-type is windows-nt; the conversion of UTF-8 encoded file names to the encoding appropriate for communicating with the OS is performed internally by Emacs.

Maybe this note about utf-8 is not applicable to shell-command? How to get the encoding of the file system?

3
  • 1
    I have a similar problem on Windows 10... but only affects me when I try, at example, open a file with portuguese accents on daemon mode, so then invalid characters are used. If I open the emacs without a daemon running, just it works... so weird. Sep 24, 2017 at 20:10
  • @ManoelVilela It could be easy to fix if we knew, how to get the file system encoding in Emacs. Windows doesn't change: I though Win7 and further have utf-8 file system.
    – user4035
    Sep 25, 2017 at 10:50
  • I solved explicitly setting the file-name-coding-system to latin-1. Setting to utf-8 just doesn't works on Windows 10 here. And If I not set explicitly, doesn't works neither because I set the preference-coding system to utf-8 and seems that the emacs choose this encoding after that. My setup now was fixed by this partial file of my init scripts: github.com/ryukinix/dotfiles/blob/master/.emacs.d/personal/… Sep 25, 2017 at 22:37

2 Answers 2

3

For windows in ru environment I have the following:

(setq default-process-coding-system '(utf-8-dos . cp1251-dos))

It let's me process files in russian from emacs using external shell invocations AND I can also use grep, ripgrep and friends to search for russian text.

1
  • Ahha, I'll try it.
    – user4035
    Dec 13, 2017 at 13:29
1

In ~/.emacs we set the variable with fs encoding:

(defvar *fs-encoding* 'cp1251)

When we need to get the encoded file name, we use function get-file-name:

(defun get-file-name (file-name)
  "get file name of the buffer, encode if necessary"
    (when *fs-encoding*
      (shell-quote-argument (encode-coding-string file-name *fs-encoding*)))
    )

(setq file-name (get-file-name "D:/Россия.tex"))
(shell-command (concat "pdflatex " file-name))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.