emacs-orgmode
[Top][All Lists]
Advanced

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

Re: fontsets


From: Juan Manuel Macías
Subject: Re: fontsets
Date: Tue, 12 Jul 2022 11:37:34 +0000

Stefan Nobis writes:

> Hmmm... maybe add optional extra config/output option to the fontset,
> like so:
>
> ┌────
> │ ;; Fonts
> │ ((myfonta . ((pdflatex . "etc.") (lualatex ...) (html ...) ...))
> │  (myfontb ...)
> │  ...)
> │ ;; Fontsets
> │ ((myfontset .
> │   ((sans . myfonta)
> │    (serif . myfontb)
> │    (mono . myfontc)
> │    (extra . ((lualatex . "\\defaultfontfeatures{Scale=MatchLowercase}")
> │              (html "some CSS...")...))
> │    ...))
> │  ...)
> └────
>
> This way it may be possible to build a fontset library of fonts that
> blend well together, including some necessary fine-tuning.

I think it's a good idea. And I definitely like Timothy's idea of
fontsets, but I still think that LuaLaTeX and XelaTeX should be unified
in some way.

Perhaps one or two default fontsets could be added.

It was commented in some previous message about the possibility of
checking if a font is present in the system. To add some extra
information, TeX live 2022 includes a lua script, luafindfont, which
runs luaotfload in the background. It is very useful because, in
addition to system fonts, it also returns results from TeX live fonts. I
use this script via helm, and I wrote this to extract a list of
candidates:

#+begin_src emacs-lisp
(defun build-luafindfont-candidates-list (candidate)
  (interactive)
  (let* ((query (shell-command-to-string (concat "luafindfont " candidate)))
         (str (with-temp-buffer
                (insert query)
                (goto-char (point-min))
                (let ((from
                       (save-excursion
                         (re-search-forward "1\\." nil t)
                         (beginning-of-line)
                         (point)))
                      (to
                       (save-excursion
                         (goto-char (point-max))
                         (point))))
                  (save-restriction
                    (narrow-to-region from to)
                    (buffer-string)))))
         (str-clean (split-string
                      (with-temp-buffer
                        (insert str)
                        (replace "[[:digit:]]+\\.\s+" "")
                        (replace "\\(.+\\)\\(\\.otf\\|\\.ttf\\)\s+" "")
                        (replace "\s+" " -- ")
                        (buffer-string)) "\n" t)))
    (setq luafindfont-list (mapcar 'identity
                                           str-clean))))
#+end_src

On the other hand, fontspec includes the \IfFontExistsTF command.
According to the fontspec documentation:

------
\IfFontExistsTF{⟨font name⟩}{⟨true branch⟩}{⟨false branch⟩}

The conditional \IfFontExistsTF is provided to test whether the ⟨font name⟩ 
exists or
is loadable. If it is, the ⟨true branch⟩ code is executed; otherwise, the 
⟨false branch⟩ code is.
This command can be slow since the engine may resort to scanning the filesystem 
for a
missing font. Nonetheless, it has been a popular request for users who wish to 
define ‘fallback
fonts’ for their documents for greater portability.

In this command, the syntax for the ⟨font name⟩ is a restricted/simplified 
version of the
font loading syntax used for \fontspec and so on. Fonts to be loaded by 
filename are detected
by the presence of an appropriate extension (.otf, etc.), and paths should be 
included inline.

E.g.:
\IfFontExistsTF{cmr10}{T}{F}
\IfFontExistsTF{Times New Roman}{T}{F}
\IfFontExistsTF{texgyrepagella-regular.otf}{T}{F}
\IfFontExistsTF{/Users/will/Library/Fonts/CODE2000.TTF}{T}{F}
-------

Best regards,

Juan Manuel 





reply via email to

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