[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: auto-coding-function for LaTeX

From: Arne Jørgensen
Subject: Re: auto-coding-function for LaTeX
Date: Fri, 12 Nov 2004 07:44:56 +0100
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

Reiner Steib <address@hidden> writes:

> On Fri, Nov 12 2004, Arne Jørgensen wrote:
>> It could look like this: [...]
> I have added some other coding systems available in Emacs

None of the coding systems you added are present in my Emacs. So why
add them? To make it easier for a user to customized when/if they are
added? Or are they present in your Emacs?

> and I tried to improve the code and doc-strings. WDYT?


Since the function no longer is supposed to be in `auto-coding-alist'
I think the name of the alist should be changed though. Maybe
`latex-inputenc-coding-alist' or something.

--8<---------------cut here---------------start------------->8---
(defcustom latex-inputenc-coding-alist
  '(("ansinew" . windows-1252) ; MS Windows ANSI encoding, extension of Latin-1
    ("applemac" . mac-roman)
    ("ascii" . us-ascii)
    ("cp1250" . cp1250) ; MS Windows encoding, codepage 1250
    ("cp1252" . windows-1252) ; synonym of ansinew
    ("cp437de" . cp437) ; IBM code page 437 (German version): 225 is \ss
    ("cp437" . cp437) ; IBM code page 437: 225 is \beta
    ("cp850" . cp850) ; IBM code page 850
    ("cp852" . cp852) ; IBM code page 852
    ("cp865" . cp865) ; IBM code page 865
    ;; The DECMultinational charaterset used by the OpenVMS system
    ;; ("decmulti" . undecided)
    ("latin1" . iso-8859-1)
    ("latin2" . iso-8859-2)
    ("latin3" . iso-8859-3)
    ("latin4" . iso-8859-4)
    ("latin5" . iso-8859-5)
    ("latin9" . iso-8859-15)
    ;; ("next" . undecided) ; The Next encoding
    ("utf8" . utf-8))
  "Mapping from encoding names used by \"inputenc.sty\" to Emacs coding systems.
Used by the function `latex-find-file-coding-system'."
  :group 'mule
  :type '(alist :key-type (string :tag "LaTeX input encoding")
                :value-type (coding-system :tag "Coding system")))

(defun latex-find-file-coding-system (arg)
"Determine the encoding of a LaTeX buffer if it uses \"inputenc.sty\".

This function is intended to be added to `file-coding-system-alist'.

The mapping from LaTeX's \"inputenc.sty\" encoding names to Emacs
coding system names is determined from `latex-auto-coding-alist'."
  (when (re-search-forward "\\usepackage\\[\\(.*\\)\\]{inputenc}" 1000 t)
    (let* ((match (match-string 1))
           (inputenc-match (cdr (assoc match latex-inputenc-coding-alist)))
           (sym (intern match)))
      (when inputenc-match (setq sym inputenc-match))
      (when (coding-system-p sym)

(add-to-list 'file-coding-system-alist
             '("\\.tex\\|\\.ltx\\'" . latex-find-file-coding-system))
--8<---------------cut here---------------end--------------->8---

By the way. The re-search-forward searches until position 1000.
Should that number be customizable? The functions in
`auto-coding-alist' get an argument of 249 for number of positions to
search, but I think that is not enough for LaTeX files.

Kind regards,
Arne Jørgensen
Gammel Kongevej 7, 1. th., DK-1610 Copenhagen V, Denmark
mobile: +45 21 65 01 13
email: address@hidden, <http://arnested.dk/>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]