[luatex] First question: Retrieve *family* name of a font / the three main families

Knut Petersen Knut_Petersen at t-online.de
Fri Jan 19 13:38:15 CET 2018


Am 19.01.2018 um 09:37 schrieb Urs Liska:
> I'm contributing to a LuaLaTeX package (https://github.com/jperon/lyluatex) that uses an external program (LilyPond) to generate images to be included in the LaTeX document. I need to pass the used fonts to LilyPond, and I didn't manage to retrieve the necessary information in Lua.
>
> What I need is
>
> a) which families are currently set as roman, sans and mono fonts
> b) the "family" name of these. [...]

So you want to teach lilypond to use the fonts latex uses.

In a similar project I use this code fragment to get information about the current TeX font and to pass it to lilypond:

       \else
         {
           \mdseries\@llftmp
           \immediate\write18{
             LANG=c
             FONT=`echo '\fontname\font'
             | sed -e 's/"//g'
             | sed -e 's/\@esc[\@esc([[:print:]]*\@esc)\@esc][[:print:]]*/\@esc1/'`
             ;
             otfinfo --info `kpsewhich $FONT`
             | grep "Full name:"
             | sed -e 's/Full name:[[:blank:]]*\@esc([[:print:]]*\@esc)/\@esc\@esc
               def \@esc\@esc fontfullname\@cbopen\@esc 1\@cbclose/'
             > ourfont.tex}
           \input "ourfont.tex"
           \@imwrtof{\@ht(define lyinlaFontName "\fontfullname")}
           \@imwrtof{\@ht(define lyinlaFontSize (absFontSize \f at size))}
         }
       \fi


\@imwrtof is defined to immediately write to an output file that will be processed by lilypond,
\@esc gives a literal "\",
\@ht gives a literal "#",
\@cbopen gives a literal "{",
\@cbclose gives a  literal "}"

Obviously it does not compile, it requires --shell-escape, and it is not OS-independent. Bt it might be a starting point for you.

The idea of the code is to take \fontname\font,
to process it as shown,
to get the font filename from kpsewhich,
and to use otfinfo to get the needed information.

The output of otfinfo is filtered and written to a TeX file,
that file is read after return from the shell,
and two scheme expression (for fontname and fontsize) are
written to a file that later will be processed by lilypond.

Knut
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/luatex/attachments/20180119/a5a0d9f1/attachment.html>


More information about the luatex mailing list