As Marcel Krüger has shown in his answer

Using unicode "combining right arrow above" to generate vector command

it is possible to use the “combining right arrow above” as the \vec command. This improves the readability in the source extremly. I have some documents with so much vectors.

I copied the answer and tried it. No problem. But I would like to use this solution in Plain LuaTeX, but there the letters do not get accented at all allthough I have not modified the code. What is wrong here?


% Plain LuaTeX
\input luaotfload.sty

\font\fourteenmath="latinmodern-math.otf:mode=base;script=math" at 14.4 pt

\protected\def\vec{\Umathaccent fixed"0"1"20D7 }

$$ \vec xy $$% Works.

    local nest = tex.nest[tex.nest.ptr]
    local last = nest.tail
    if not last or not last.id == 18 then
    error'I can only put accents on simple noads.'
    if last.sub or last.sup then
    error'If you want accents on a superscript or subscript, please use braces.'
    local acc = node.new(21, 1)
    acc.nucleus = last.nucleus
    last.nucleus = nil
    acc.accent = node.new(23)
    acc.accent.fam, acc.accent.char = 0, 0x20D7
    print(last, nest.head)
    nest.head = node.insert_after(node.remove(nest.head, last), nil, acc)
    nest.tail = acc

$$ x⃗y $$ % x does not get accented.


The Lua code has to be aware which font the accent is supposed to come from. Using the unicode-math package this isn't that important because all math families are basically the same, but in your case the latinmodermath-regular.otf font is "only" loaded in family 1. The important line is

acc.accent.fam, acc.accent.char = 0, 0x20D7

This sets fam, the mathematical family, to 0 and char, the slot in the font, to 0x20D7. You loaded the font in family 1, so you need

acc.accent.fam, acc.accent.char = 1, 0x20D7

instead. Then you get

enter image description here

  • What a mistake... Sorry for wasting your time, but I am a beginner in lua. – user125730 Jan 17 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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