# Using unicode “combining right arrow above” to generate vector command

This question originated from a confusion created by some Linux systems where, for some software (editor and browser) the combining unicode characters appear to apply to the right (instead of to the left like the documented convention). So it could be a "localized" issue (well, localized to all Linux systems). In fact this bug looks like a useful feature because it allows straight conversion for the typesetter commands. Still answers and notes about unicode math with accents are greatly appreciated.

The unicode-math list of symbol describes "combining right arrow above" (⃗ or ⃗x) as translated into \vec in Section 7.

How is one supposed to use this feature of unicode-math?

In this example I don't get the arrow above the $x$:

\documentclass{article}
\usepackage{unicode-math}
\begin{document}
$⃗x$ %this line contains the unicode arrow and the x character (in case your browser doesn't show it).
\end{document}


(The compilation with lualatex and xelatex shows simply x with no arrow)

This is strange because unicode-math works for other things like superindexes, etc.

EDIT: For those having trouble seeing the unicode characters, here it is an screenshot of my editor (gedit), my browser shows basically the same:

EDIT 2: This is how @Jukka answer looks like in my browser:

screenshot:

For example, so far, I find that <arrow>x renders the arrow over the x in Gedit 3.10 and Firefox 28.0 and the arrow before the x for TeXworks and Google Chrome.

• Interestingly for me in firefox it is drawn on the character before the x. – Chris H Apr 14 '14 at 9:27
• In Firefox Linux the arrow shows above the x. Maybe depends on the font. This is the precise symbol fileformat.info/info/unicode/char/20d7/index.htm. – alfC Apr 14 '14 at 9:29
• Generally speaking it's best to avoid such combining characters in typeset work and let the typesetter position the vector arrow. Not least because then you will get consistent behaviour if the base is not just a single letter. – David Carlisle Apr 14 '14 at 9:29
• But that transformation is hard in tex as a combining character comes after the base and a tex accent command has to come before, so you would need to make every character such as x look ahead to see if it is followed by a combining character. which is possible but will break some things and be slow, and just telling people not to do that seems like a better option (although I don't maintain unicode-math so it isn't my decision) – David Carlisle Apr 14 '14 at 9:34
• copy the text from your posted code $⃗x$ %this to the first text block at people.w3.org/rishida/tools/conversion and hit convert you see the code points displayed as 0024 0020 20D7 0078 0024 0020 0025 0074 0068 0069 0073 so the second character is U+0020 ie a space. – David Carlisle Apr 14 '14 at 20:28

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.

• Ha, ha, ha, you say "as we can see here ... does not look right at all". It does look right in my browser!! I'll add the screen shot in my question. For some reason my browser and my editor seem to work such that the combining character affects to the right. – alfC Apr 14 '14 at 15:51
• I found this in the Wikipedia entry which confirms what you say "In Unicode, diacritics are always added after the main character, so it is possible to add several diacritics to the same character, although as of 2010, few applications support correct rendering of such combinations.". However my applications behave as is if the opposite where true. And, if I believe that it makes it very friendly for the typesetter to transform the combining character into commands. – alfC Apr 14 '14 at 15:56
• To confirm, as you say, the arrow after the letter still doesn't produce the vector in the resulting PDF. – alfC Apr 14 '14 at 16:01
• After all the confusion about the order (TeXworks works as everybody describes). Does "combining character" works in you unicode-math and typesetter? Mine are XeTeX 3.1415926-2.6-0.9999.3 (TeX Live 2014/dev) This is LuaTeX, Version beta-0.76.0-2013122811 (TeX Live 2014/dev) (rev 4627). Fedora 20. – alfC Apr 14 '14 at 23:46

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
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.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̃ŷz̄x⃗y$
\end{document}


• I have to play with this now. – alfC Oct 22 '18 at 14:42
• Would (Can) one need to do this for every accent symbol? e.g. double arrow, tilde, dot, dotdot? – alfC Oct 22 '18 at 15:16
• @alfC See the edit. For some LuaTeX versions this can trigger a LuaTeX bug. – Marcel Krüger Oct 22 '18 at 20:07