bug#81606: Mojibake with UTF-8 file names
Eli Zaretskii <[email protected]>
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
> From: Arash Esbati <[email protected]> > Cc: [email protected], [email protected] > Date: Sun, 16 Aug 2026 13:26:08 +0200 > > Eli Zaretskii <[email protected]> writes: > > > So this can only work if the encoding of the main file's name is > > easily determined from its byte sequence. The patch below tries to > > do the best we can. It is still not 100% reliable: if the default > > locale's encoding is not UTF-8, there are chances it will still not > > work. But I don't think there's a solution in that case, except by > > providing the \inputencoding directive or the coding: cookie. > > I think the above is a safe assumption. This is an excerpt from LaTeX > news for release 2018-04-01: > > UTF-8: the new default input encoding > [...] > With this release, the default encoding for LaTeX files has been > changed from the ``fall through raw'' encoding to UTF-8 if used with > classic TeX or pdfTeX. The implementation is essentially the same as > the existing UTF-8 support from \usepackage[utf8]{inputenc}. The > LuaTeX and XeTeX engines always supported the UTF-8 encoding as their > native (and only) input encoding, so with these engines inputenc was > always a no-op. > > This means that with new documents one can assume UTF-8 input and it > is no longer required to always specify > \usepackage[utf8]{inputenc}. But if this line is present it will not > hurt either. [...] > > Only documents that have been stored in a legacy encoding and used > accented letters from the keyboard without loading inputenc (relying > on the similarities between the input used and the T1 font encoding) > are affected. > > These documents will now generate an error that they contain invalid > UTF-8 sequences. [...] > > Possible alternatives are reencoding the file to UTF-8 using a tool > (such as recode or iconv or an editor) or adding the line > \usepackage[<encoding>]{inputenc} > to the preamble specifying the <encoding> that fits the file encoding. > > IIUC, LaTeX users with old documents are now forced to touch their > files, and with your patch below, it should cover most cases, I think. Once again: if the default encoding is not UTF-8, what I suggest is not reliable enough. For example, on MS-Windows it doesn't always work, unless I invoke prefer-coding-system first to prefer UTF-8. I don't know how widely the above convention is accepted nowadays, but if it's wide enough, perhaps replace 'undecided' with 'utf-8' in the decode-coding-string call. > > Here's the patch I can suggest: > > > > diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el > > index 6e0cde6..1e0f8e7 100644 > > --- a/lisp/international/latexenc.el > > +++ b/lisp/international/latexenc.el > > @@ -160,6 +160,8 @@ latexenc-find-file-coding-system > > (stringp TeX-master) > > TeX-master) > > (bound-and-true-p tex-main-file))))) > > + ;; Decode the main file name as best as we can... > > + (setq file (decode-coding-string file 'undecided)) > > (dolist (ext `("" ,(if (boundp 'TeX-default-extension) > > (concat "." TeX-default-extension) > > "") > > Thanks, I tested it and it works. So should I install the above, or should I install the utf-8 variant? I'm not a user of AUCTeX and don't edit LaTeX files, so I cannot reason about this myself.