Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

With LuaTeX, how do I get a list of OTF features supported by the current font in use printed?

For example, with otfinfo, I can get a list of OTF features by otfinfo -f font_file_name. Can I do anything similar with LuaTeX?

The goal is to produce such a list for each font I tested. For example, I would like to have such a macro,

\def\listfontfeatures{
 \directlua{... some lua code to list font features to a string, say ff ...}
 \directlua{tex.print(ff)}
}

And use it like the following,

Times Ten LT Std: \fontspec{Times Ten LT Std} \listfontfeatures \par
Palatino LT Std:  \fontspec{Palatino LT Std}  \listfontfeatures \par
Minion Pro:       \fontspec{Minion Pro}       \listfontfeatures \par
share|improve this question
    
I don't have time to write an answer, but fontspec has function \fontspec_if_feature:nTF - it uses expl syntax - and it should be possible, to iterate over list of features with this function, both in lualatex and xelatex –  michal.h21 Aug 17 '11 at 13:38
add comment

4 Answers 4

up vote 10 down vote accepted

You can use fontspec function \fontspec_if_feature:nTF. It will work in both xelatex and lualatex

\documentclass{article}
\usepackage{fontspec,etoolbox,expl3}
\setmainfont{Cambria}
\def\fontfeatures{abvf, abvm, abvs, aalt, akhn, nalt, halt, afrc, valt, vhal, blwf, blwm, blws, cpsp, c2pc, c2sc, case, cpct, cv01-, cv99, cjct, cfar, calt, clig, cswh, curs, dnom, dlig, dist, expt, falt, frac, fwid, ccmp, haln, half, hwid, hngl, hist, hlig, hkna, hojo, init, isol, ital, jp04, jp78, jp83, jp90, jalt, kern, lnum, ljmo, lfbd, ltra, ltrm, locl, mark, mset, mkmk, mgrk, medi, med2, nlck, nukt, numr, onum, opbd, size, ordn, ornm, pcap, pref, pres, psts, pstf, palt, vpal, pnum, pkna, pwid, qwid, rand, rkrf, rphf, rlig, rtbd, rtla, rtlm, ruby, sinf, smpl, zero, smcp, liga, salt, ss01, ss02, ss03, ss04, ss05, ss06, ss07, ss08, ss09, ss10, ss11, ss12, ss13, ss14, ss15, ss16, ss17, ss18, ss19, ss20, subs, sups, swsh, tnum, fina, fin2, fin3, twid, titl, trad, tnam, tjmo, unic, vatu, vert, vrt2, vkna, vkrn, vjmo}
% see http://en.wikipedia.org/wiki/OpenType_feature_tag_list#OpenType_Typographic_Features for their list 
\ExplSyntaxOn
\newcommand\listfontfeatures{%
\renewcommand*{\do}[1]{
\fontspec_if_feature:nTF {##1}{##1,\ }{}
}
\expandafter\docsvlist\expandafter{\fontfeatures}
}
\ExplSyntaxOff
\begin{document}
\listfontfeatures
\end{document}
share|improve this answer
1  
@doncherry you are right, there was no space between features, I fixed the code and it should allow to break the lines now –  michal.h21 Oct 7 '12 at 17:39
add comment

This should list all features in the current font, it can even be extended to list supported scripts and languages for every feature:

\documentclass{article}
\usepackage{fontspec}

\begin{document}
\newcommand\listfontfeatures{%
\directlua{
local id   = font.current()
local font = fonts.identifiers[id]
local data = font.shared.otfdata
if data then
  local features = data.luatex.features
  for i,_ in next, features do
    for f,_ in next, features[i] do
      %print(f, table.serialize(features[i][f]))
      tex.sprint(-1, f.." ")
    end
  end
end
}}

\fontspec{TeX Gyre Pagella} \listfontfeatures
\end{document}
share|improve this answer
    
Thanks very much for the answer. However I still have a small question. I searched the LuaTeX manual and it seems that the shared key and otfdata are not defined by LuaTeX. So I greped my texmf-dist try to find out where otfdata are defined, and it seems they are from luaotfload. I am right now reading the source, but do you know if there are any user friendly documents for it and other things defined there? –  Yan Zhou Aug 17 '11 at 19:50
    
There aren't, sorry. Much of that code is derived from ConTeXt and Hans Hagan (main ConTeXt developer) does not consider it stable yet, it will be documented once the interface is stabilised. –  Khaled Hosny Aug 17 '11 at 21:38
    
Em, I tried to read the source documentation of ConTeXt and found out that most are merely code without doc. However, I managed to serialize the table and print it to terminal. Though not perfect, but it still give a rough idea about everything there. –  Yan Zhou Aug 18 '11 at 10:40
add comment

You can use the ConTeXt script mtxrun to get this information:

$mtxrun --script fonts --info --list --name --pattern="*Cambria*"

mtx-fonts       |
mtx-fonts       | mapping : cambriaitalic
mtx-fonts       | fontname: cambriaitalic
mtx-fonts       | fullname: cambriaitalic
mtx-fonts       | filename: cambriai.ttf
mtx-fonts       | family  : cambria
mtx-fonts       | weight  : normal
mtx-fonts       | style   : italic
mtx-fonts       | width   : normal
mtx-fonts       | variant : normal
mtx-fonts       | subfont : 
mtx-fonts       | fweight : conflict: book
mtx-fonts       |
mtx-fonts       | gpos features:
mtx-fonts       |
mtx-fonts       | feature  script   languages
mtx-fonts       |
mtx-fonts       | kern     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       |
mtx-fonts       | gsub features:
mtx-fonts       |
mtx-fonts       | feature  script   languages
mtx-fonts       |
mtx-fonts       | c2sc     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | calt     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | case     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | ccmp     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | dnom     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | frac     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | liga     latn     dflt rom trk
mtx-fonts       | lnum     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | locl     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     rom     
mtx-fonts       | numr     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | onum     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | ordn     latn     dflt rom trk
mtx-fonts       | pnum     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | salt     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | sinf     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | smcp     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | sups     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk
mtx-fonts       | tnum     cyrl     dflt srb
mtx-fonts       |          grek     dflt    
mtx-fonts       |          latn     dflt rom trk

See $TEXMF/scripts/context/lua/mtx-fonts.lua for the lua code that implements this.

share|improve this answer
    
Thanks for the answer. But what I want is to get these information into a TeX file and output to PDF. In addition, I would like it to find what is the font's currently in use at a point of the tex source file. If only to get information on terminal, I can also use otfinfo, like I said in the question. –  Yan Zhou Aug 17 '11 at 19:42
    
The code in mtx-fonts.lua should also work inside a \startluacode ... \stopluacode (or the equivalent LaTeX) environment. It is a simple matter of change a few print statements to tex.print to get the output in PDF. –  Aditya Aug 17 '11 at 21:11
add comment

On Linux it is simple and I suppose that Windows has a similiar command

voss@shania:~/.fonts/Junicode> otfinfo -f Junicode.ttf 
c2sc    Small Capitals From Capitals
calt    Contextual Alternates
case    Case-Sensitive Forms
ccmp    Glyph Composition/Decomposition
dlig    Discretionary Ligatures
fina    Terminal Forms
frac    Fractions
hist    Historical Forms
hlig    Historical Ligatures
kern    Kerning
liga    Standard Ligatures
mark    Mark Positioning
mgrk    Mathematical Greek
mkmk    Mark to Mark Positioning
onum    Oldstyle Figures
rtlm    <unknown feature>
salt    Stylistic Alternates
smcp    Small Capitals
ss01    Stylistic Set 1
ss02    Stylistic Set 2
ss04    Stylistic Set 4
ss05    Stylistic Set 5
ss06    Stylistic Set 6
ss07    Stylistic Set 7
ss08    Stylistic Set 8
ss09    Stylistic Set 9
ss14    Stylistic Set 14
ss15    Stylistic Set 15
ss18    Stylistic Set 18
ss19    Stylistic Set 19
ss20    Stylistic Set 20
subs    Subscript
sups    Superscript
swsh    Swash
share|improve this answer
1  
otfinfo is available for windows from lcdf.org/type –  maetra Nov 14 '12 at 12:17
    
What I need is add the features list to a latex file which list fonts directly. Of course I know I can query it from otfinfo from a terminal –  Yan Zhou Nov 14 '12 at 13:12
    
you can run otfinfo fontname > file.tmp from inside LaTeX and then read it with \input{file.tmp} –  Herbert Nov 14 '12 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.