auctex-devel
[Top][All Lists]
Advanced

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

[AUCTeX-devel] Font completion for fontspec


From: Mosè Giordano
Subject: [AUCTeX-devel] Font completion for fontspec
Date: Sat, 21 Dec 2013 12:20:30 +0100

Hi list,

yesterday I pushed to the AUCTeX repository some new style files,
including fontspec.el.  I'd like to add completion for font names in
this style file to help XeLaTeX and LuaLaTeX users selecting their
fonts.  I've found a couple of ways to get the list of font:
a. read the database file;
b. query the database using `luaotfload-tool'.
The a. option has two drawbacks:
- the database file name has been changed, it was
    $(kpsewhich -var-value TEXMFVAR)/luatex-cache/generic/names/otf-names.lua
  but in the last version of the `luaotfload' bundle it is
    $(kpsewhich -var-value
TEXMFVAR)/luatex-cache/generic/names/luaotfload-names.lua
- the database needs to be created manually if it doesn't exist, using
`mkluatexfontdb'/`luaotfload-tool'.
Conversely, with the b. option
- it's not necessary to know the name of the database file
- the database is automatically created if it doesn't exist.
In addition, the output of
    luaotfload-tool --list=basename
is much easier to parse than reading directly the database, hoping
that the output format won't change in the future.

With `fontspec' package, fonts can be selected by font name or by file
name (see `fontspec' documentation) and using
    luaotfload-tool --list=basename
we can get both.  I suggest to add to `fontspec.el' the following:
--8<---------------cut here---------------start------------->8---
(defvar LaTeX-fontspec-font-list nil
  "List of the fonts accessible to fontspec.")

(defun LaTeX-fontspec-arg-font (optional &optional prompt)
  "Prompt for a font name with completion.
If OPTIONAL is non-nil, insert the resulting value as an optional
argument, otherwise as a mandatory one.  Use PROMPT as the prompt
string.

The font list is retrievied using `luaotfload-tool'."
  (unless LaTeX-fontspec-font-list
    (message "Searching for fonts...")
    (with-temp-buffer
      (shell-command "luaotfload-tool --list=basename" t)
      ;; Search for the font base names and full names, and add them to
      ;; `LaTeX-fontspec-font-list'.  The list is in the form
      ;;     <base name><TAB><full name><TAB><version>
      (while
      (re-search-forward "^\\([^\n\r\t]*\\)\t\\([^\n\r\t]*\\)\t.*$" nil t)
    (add-to-list 'LaTeX-fontspec-font-list (match-string-no-properties 1))
    (add-to-list 'LaTeX-fontspec-font-list
             (match-string-no-properties 2)))))
  (TeX-argument-insert
   (completing-read
    (TeX-argument-prompt optional prompt "Font name")
    LaTeX-fontspec-font-list)
   optional))
--8<---------------cut here---------------end--------------->8---
On my system `luaotfload-tool' founds 1507 fonts and
`LaTeX-fontspec-arg-font' takes half a second to get the complete
list, so it should be quite fast.

What do you think?

Bye,
Mosè



reply via email to

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