I am trying to emulate this poster which I've found at http://www.brill.com/about/brill-fonts. How could we define different color per script and get a similar glyph poster?

poster at Brill Fonts

1 Answer 1


I am using HanaMinA.ttf for this task as a test case. After downloading and installing the font, I have prepared a TeX file mal-fonts.tex which can be processed by xelatex or lualatex.

% run: xelatex or lualatex mal-fonts.tex

I am generating mal-result.tex file by a standalone Lua script mal-fonts.lua. I've defined several regions (Latin, Extended Latin, Chinese, Japanese etc.) and its color. I am randomly selecting glyphs (function callme) making sure that two sequantial glyphs won't have the same color, or, I am testing a specific string (function testme).

We are running:

texlua mal-fonts.lua
lualatex mal-fonts.tex

We are getting this message at the terminal of a number of the processed glyphs:

Processed glyphs: 19 300

I am enclosing the Lua script and a preview of the PDF file with Latin+Japanese sentence and 300 randomly generated glyphs.

The algorithm for generating glyphs could be improved from regions to specific glyphs in a selected font. We are selecting glyphs without further testing, so a specific glyph could be displayed several times, in theory. The script is working fine if we are just testing strings.

Update: I've implemented that idea from the comment section. So the ligatures are preserved. Well, the example looks all the some but it is due to font and used words. The beginning of the generated file (mal-result.tex) looks like this:

\hfill{\color{green}Hello\ World!\ }\hfill{\color{gray}さようなら}\hfill{\color{green}\ }%

This is the main Lua script (mal-fonts.lua):

-- I am mal-fonts.lua file...
-- I am checking (generated) string character by character and I use different color as defined in sets data table.
-- I am also saving time by randomly choosing glyphs. The glyph doesn't have to be defined in a specific font (that's a possible improvement, e.g. 198 (hex) in HanaMinA.ttf).

math.randomseed(0) -- to be changed

-- Generate a set of glyphs...
function callme(number)
local col=0
local s=""
local last=0
local marker=0

for i=1,number do
  if col>#sets then 
    --whereto:write("%\n") -- to easy reading
    end -- of if col

if #sets==1 then
  realcol=col -- =1
  until last~=realcol -- This is not effective computation, but it is an experiment.
end -- if #sets...

  --realcol -- assures that two glyphs will have different color
  -- col -- colors are repated from 1..n
  glyph=math.random( startnum,endnum  )

  --print(i,col,glyph,string.format("%X",glyph)) -- information about specific glyph
end -- of for i
end -- of function callme

-- Test a string and use a proper color as defined in sets.
function testme(mstring)
io.write(" "..unicode.utf8.len(mstring))
for i=1,unicode.utf8.len(mstring) do
  jkey=1 -- if glyph is not predefined
  for j=1,#sets do
    if value>=tonumber(sets[j][3],16) and value<=tonumber(sets[j][4],16) then jkey=j; break end
  end -- of j
  if glyph==" " then glyph="\\ " end -- \\; making sure that space will be there

  if jkey~=marker then 
    if i>1 then whereto:write("}") end
  end -- end of if jkey
end -- of for i
whereto:write("}") -- closing group with \color
end -- of function testme

io.write("Processed glyphs:")

-- Let's run several tests...
testme("Hello World! さようなら ")
callme(300) -- it calls for testme automatically

-- Close a file and end the script


  • Interesting! Why do you run texlua separately? If you are concerned about reproducibility, you could just store the seed in the document or the .aux file. May 16, 2014 at 21:08
  • @phg The reason is I wanted to have solution also for XeTeX users.
    – Malipivo
    May 16, 2014 at 21:10
  • Now, after checking "ll" in "Hello", I have noticed that I am breaking up kerning pairs as I treat each glyph separately in a group (I focused on typesetting poster), it could be improved for production by not entering a new group if script from the previous glyph is the same. Instead of {\somefont H}{\somefont e}{\somefont l}{\somefont l}{\somefont o} we would get {\somefont Hello}.
    – Malipivo
    May 16, 2014 at 21:31
  • If you are interested in serious approach based on glyph classes for large text blocks, please see tex.stackexchange.com/questions/45331/… (XeTeX) and tex.stackexchange.com/a/21691/48028 (LuaTeX)
    – Malipivo
    May 16, 2014 at 22:12
  • It looks that next fine way for displaying scripts is with the help of the ucharclasses package.
    – Malipivo
    May 18, 2014 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .