Using unicode "combining right arrow above" to generate vector command
Like the other answer already said, in Unicode the combining characters come after the base characters. Also this is not supported by unicode-math
.
But at least for LuaLaTeX you can add support for U+20D7 as a combining character:
\documentclass{article}
\usepackage{unicode-math}
\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
\begin{document}
$x⃗y$
\end{document}
EDIT: If you want to support all Unicode math accents, you can automate this using the symbol table from unicode-math
:
\documentclass{article}
\usepackage{unicode-math}
\protected\def\afteracc{\directlua{
local nest = tex.nest[tex.nest.ptr]
local last = nest.tail
if not (last and 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, token.scan_int()
nest.head = node.insert_after(node.remove(nest.head, last), nil, acc)
nest.tail = acc
node.flush_node(last)
}}
\AtBeginDocument{
\begingroup
\def\UnicodeMathSymbol#1#2#3#4{%
\ifx#3\mathaccent
\def\mytmpmacro{\afteracc#1 }%
\global\letcharcode#1=\mytmpmacro
\global\mathcode#1="8000
\fi
}
\input{unicode-math-table}
\endgroup
}
\begin{document}
$x̃ŷz̄x⃗y$
\end{document}
In Unicode, a combining mark is associated with the character that precedes it, so you should use $x⃗$
(the content between dollar signs is letter x
followed by U+20D7 COMBINING RIGHT ARROW ABOVE). And you should declare a mathematical font that contains the character.
But it still won’t work, presumably due to limitations in unicode-math, in fonts, or in the LaTeX interpreter(s) you are using. Combining marks are often poorly implemented in fonts (their metrics are wrong, causing the mark to be misplaced) and in rendering software (as we can see here: x⃗ does not look right at all).
The conclusion is that you should use methods like \vec{x}
or, if you can choose the notations used, use bold face for vectors instead of an arrow above. Bold face is the primary notation according to the ISO 80000-2 standard and the only notation described in the US standard (ANSI/IEEE Std 260.3-1993). It is also typographically more robust.