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

Urs Liska lists at openlilylib.org
Fri Jan 19 14:37:00 CET 2018


Hi Knut,


Am 19.01.2018 um 13:38 schrieb Knut Petersen:
> 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.

Yes, it's awesome when included scores use the same fonts as the 
surrounding text.
>
> 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, 

That's not an issue, the lyluatex package needs that anyway to start 
LilyPond.

> and it is not OS-independent. 

That's probably true.

> 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.
>

I can do that with little effort in the Lua layer (I'm working in anyway):

  * get the absolute filename from the font object.
  * run otfinfo -a with that filename

This should be straightforward to implement but hard to make OS 
independent. While I personally don't care about that I vividly recall 
that in an earlier life I felt strongly offended by the attitude "YOU 
made the mistake of using Windows, so don't complain now" ...

otfinfo seems to be available on Windows and even included in 
http://w32tex.org/ ,  but I'm not sure if that will be an acceptable 
dependency. Of course I can start with implementing it for Linux and 
make the option be limited to that.


But still I can't really believe that Lua can tell me the 
postscriptname, "fullname", filename, but not the family.

Does anybody know if that's a deliberate limitation?

Urs


> Knut

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


More information about the luatex mailing list