4

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?

MWE:

% Plain LuaTeX
\input luaotfload.sty

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

\Umathcode`x="7"1`x
\Umathcode`y="7"1`y
\protected\def\vec{\Umathaccent fixed"0"1"20D7 }

$$ \vec xy $$% Works.

\mathcode"20D7="8000
\def\aftervec{\directlua{
    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.'
    end
    if last.sub or last.sup then
    error'If you want accents on a superscript or subscript, please use braces.'
    end
    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
    node.flush_node(last)
    }}
\letcharcode"20D7=\aftervec

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

\bye
7

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.