# How to use OpenType fonts with plain-LuaTeX?

Is it possible to have OpenType fonts with LuaTeX using the plain format?

I have tried:

``````\font\test="texgyrepagellaregular"\test test\bye
``````

but I get `! Font \test=texgyrepagellaregular not loadable: metric data not found or bad.`.

`mtxrun --script fonts --list --all --pattern=pagella` shows the above font name when I followed the instructions at http://wiki.contextgarden.net/Fonts_in_LuaTeX.

But on actually using the fonts, the page switches to speaking of ConTeXt instead of LuaTeX, which leaves me to wonder if it is possible to use OT-fonts with plain?

## UPDATE

Even though this now works fine for fonts which are located in my home directory (OSX Lion, BasicTeX2012, `luatex-plain`-format constructed as instructed below), I am unable to use fonts which are located in the system directories. So while the above example works (with `texgyrepagellaregular`), as the `mtxrun`-script shows its location as `~/Library/Fonts`, the following doesn't:

``````\font\test="minionproregular"
``````

presumably because `mtxrun` shows its location as `/Library/Fonts` (the same issue seems to be with fonts inside `/System/Library/Fonts`).

Now, I added to my `~/.zshrc`:

``````export OSFONTDIR=/System/Library/Fonts:/Library/Fonts:\$OSFONTDIR
``````

after which I was able to update the fonts database with `mtxrun --script fonts --reload` (following these instructions), and indeed now the `mtxrun` listing does show all of the fonts. It's just that `luatex-plain` doesn't see them.

How can I make `luatex-plain` see the fonts `mtxrun` sees?

-
`mtxrun --script fonts --reload --simple` (luatex-fonts uses its own, very simplistic font names database). –  phg May 16 '13 at 8:06
@phg: Awesome, that worked. Thank you very much! :) –  morbusg May 16 '13 at 8:20

Let me add to the confusion a bit: there are actually two formats for running Plain with LuaTeX! One of them is the format that gets called when you run the command `luatex` from e.g. TeX Live; egreg already posted instructions for it in his answer.

There exists, however, another format called luatex-plain. Since it comes with the font loader built in, it has the advantage of being able to use OpenType fonts without additional packages. Here’s a demo (you’ll need the free Minion Pro fonts from Adobe for the second part):

``````\font\iwonaregular   =file:Iwona-Regular    at 12pt
\font\iwonaitalic    =file:Iwona-Italic     at 12pt
\font\iwonabold      =file:Iwona-Bold       at 12pt
\font\iwonabolditalic=file:Iwona-BoldItalic at 12pt

{\iwonaregular     foo}\par
{\iwonaitalic      bar}\par
{\iwonabold        baz}\par
{\iwonabolditalic  xyzzy}\par

\font\minionproliningfigures =file:MinionPro_Regular         at 12pt
\font\minionprotextfigures   =file:MinionPro_Regular:+onum;  at 12pt
\font\minionprosmallcaps     =file:MinionPro_Regular:+smcp;  at 12pt

{\minionproliningfigures  0123456789abcdef}\par
{\minionprotextfigures    0123456789abcdef}\par
{\minionprosmallcaps      0123456789abcdef}\par %% implicit +onum!

\bye
``````

For more complicated examples see the test file.

luatex-plain is distributed with ConTeXt and available through TeX Live in the directory `texmf-dist/tex/generic/context/luatex/`. (Pro Tip: build the format and then symlink the `luatex` binary to `luatex-plain`, so you don’t have to specify the `--fmt` parameter.)

-
This is really nice to know, Thank you very much! If I'm reading this right, it also includes the `mplib` which then has everything I could hope for. Could you include what needs to be done to build the format and symlink? –  morbusg Mar 29 '13 at 17:03
@morbusg Do you have Context installed or just TL? –  phg Mar 29 '13 at 18:17
Yes, I have ConTeXt installed. –  morbusg Mar 29 '13 at 18:22
1. cd to `\$CONTEXTDIR/tex/texmf-context/tex/generic/context/luatex` and issue `luatex --ini ./luatex-plain.tex`; 2. copy `luatex-plain.fmt` to `\$CONTEXTDIR/tex/texmf-linux-64/web2c/luatex/` (substitute your OS; also you may have to create that dir); 3. run `\$CONTEXTDIR/tex/texmf-linux-64/bin/mktexlsr`; 4. `ln -s `which luatex` ~/bin/luatex-plain`; 5. ready! –  phg Mar 29 '13 at 18:36

LuaTeX has the same font support as pdfTeX, natively. However, using the right Lua code one can extend the font support, which is precisely the job of `luaotfload.lua`. The `luaotfload.sty` file can be loaded also with the Plain LuaTeX format.

Try compiling the following file with `luatex` (note that "Linux Libertine O" is in my system fonts, I used it just by way of example.

``````\input luaotfload.sty
\font\x="texgyrepagella-regular.otf"

\font\liber="Linux Libertine O/I=5:+smcp" at 12pt

\x

abcdef

\liber

abcdef

\bye
``````

-