# Accented characters in vscode

**URL:** <https://discourse.julialang.org/t/accented-characters-in-vscode/53234>\
**Category:** General Usage\
**Created:** [January 12, 2021, 4:55pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234 "2021-01-12T16:55:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [January 12, 2021, 4:55pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/1 "2021-01-12T16:55:14Z")

</div>

In VScode, if I type θ \hat tab then the hat comes after the θ but the variable is usable.

θ̂ = 2.0

If instead I type \hat tab θ I get the hat sitting on top of the θ but Julia gives an error.

This issue is not specific to Greek characters: the same happens with x.

Is there a setting in VScode that I could change to make it both look right and not produce an error message? (I’ve looked but failed to find) Thanks!

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 12, 2021, 5:02pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/2 "2021-01-12T17:02:26Z")

</div>

What font are you using? If I type `x \hat` it produces the correct unicode character. This might seem like a font issue to me.

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [January 12, 2021, 5:07pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/3 "2021-01-12T17:07:08Z")

</div>

Thanks! (‘Droid Sans Mono’, ‘monospace’, monospace, ‘Droid Sans Fallback’) which I suspect is the default. I’ll experiment, but what is the font that you are using @affans ?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [January 12, 2021, 5:11pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/4 "2021-01-12T17:11:08Z")

</div>

That definitely is a font issue. I’d recommend giving the excellent [JuliaMono](https://github.com/cormullion/juliamono) a shot. 🙂

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 12, 2021, 5:42pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/5 "2021-01-12T17:42:05Z")

</div>

JuliaMono seems to be a fan favourite, but I use [Cascadia.](https://github.com/microsoft/cascadia-code)

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [January 12, 2021, 6:02pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/6 "2021-01-12T18:02:30Z")

</div>

You might find this useful: [https://mono-math.netlify.app/](https://mono-math.netlify.app/) 🙂 It shows how different monospace fonts compare for math symbols.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 13, 2021, 9:34am UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/7 "2021-01-13T09:34:48Z")

</div>

`θ \hat` should work, but I don’t think `\hat θ` will, because `hat` needs a character to sit on.

You can stack these too, so `x \dot \vec` should work (in the VS Code editor), font permitting.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 13, 2021, 2:08pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/8 "2021-01-13T14:08:32Z")

</div>

> [@Joris\_Pinkse](#):
>
> If instead I type `\hat tab θ` I get the hat sitting on top of the `θ` but Julia gives an error.

Realize that this is not really LaTeX. You are not typing `\hat{\theta}` and having it typeset.

What is actually happening is that tab-completing `\hat` gives you the [Unicode combining character](https://en.wikipedia.org/wiki/Combining_character) [U+0302](https://www.fileformat.info/info/unicode/char/0302/index.htm) (_combining circumflex accent_). The way combining characters work in Unicode is that they **modify the preceding character** , in this cast to put a `^` over the preceding character. So, you have to put the `\hat` **after** the `θ` if you want a `θ` with a hat on top of it. (Though it may not render correctly if your font doesn’t support this combination.)

In addition to not rendering the way you want, putting the `\hat` first is not a valid Julia variable name — [valid variable names](https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names) must not _begin_ with a combining character.

---

<div class="post-metadata">

**Author:** ![akriegman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akriegman/32/30573_2.png) [@akriegman](https://discourse.julialang.org/u/akriegman)\
**Post date:** [November 12, 2021, 4:08pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/9 "2021-11-12T16:08:28Z")

</div>

Hi, I’m a bit late to this conversation, but I still have some questions. I had the same problem as OP with Droid Sans Mono, and I’ll try out some other fonts.

What I don’t understand is why Droid Sans Mono would do this. The Unicode specification is that combining characters combine with the previous character, so why would they ever combine with the next character?

Based on the little testing I’ve done, when you have a greek letter, a combining character, then another character, the middle character combines with the last character, even if it’s also a greek letter. If the first character is an english letter then it will combine properly. I’ve also noticed that punctuation behaves similarly to greek letters in the above examples.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 2:04am UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/10 "2021-11-13T02:04:23Z")

</div>

I think this massive thread provides enough evidence to discourage the use of unicode characters in identifiers in computer code.  
Example?

```julia
julia> function f!(M)
       Μ = [1, 2]
       end
f! (generic function with 1 method)

julia> M = [3, 4]
2-element Vector{Int64}:
 3
 4

julia> println(M)
[3, 4]

julia> f!(M)
2-element Vector{Int64}:
 1
 2

julia> println(M)
[3, 4]

julia>

```

How do you like 'em unicodes now?

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 13, 2021, 10:01am UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/11 "2021-11-13T10:01:23Z")

</div>

lol - But I don’t think this argument is very persuasive. We don’t ban scissors merely because it’s possible to cut yourself with them. Instead we teach and advise how to use things safely, just like we would advise programmers not to use easily-confused capital Greek letters for variable names (such as `Μ`, U+039C) – without at least documenting their folly!

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 13, 2021, 11:10am UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/12 "2021-11-13T11:10:46Z")

</div>

I started investigating this, but got a bit bogged down and wasn’t able to come up with a definitive explanation.

I made this graphic in an attempt to explain what was going on:

 ![t](https://global.discourse-cdn.com/julialang/original/3X/d/8/d82ae66d7e13f22e6e8b0563e0d9880a723a0e11.png)

Basically this works through a number of monospaced fonts and draws the U+0302 combining circumflex accent from each one. The central red cross is essentially the current position or ‘cursor’ - usually the bottom left corner of a typical character. You can see that fonts generally fall into two groups. The first group place the circumflex to the left of the cursor, ie **over the previous glyph** , and the second group position the circumflex to the right, ie over the next glyph. There are a few fonts that appear to do neither. Not shown are some fonts that don’t have this character at all - Anonymous Pro, Roboto Mono, JetBrains, etc…

The numbers are the `X-advance` value of this glyph - which in theory defines the width of the character. For the first group, because the width is 0, the next character appears at the same place - there’s effectively no advance forward. (I think this corresponds to what the Unicode specification says.) In the second group, there _is_ an X-advance value, so these are - in theory at least, not zero-width glyphs. But, to make matters more complicated, the text rendering software (ie your terminal or editor, or the OpenType text-rendering layer) may or may not take notice of the varying X-advance values - the “monospaced context” overrides any positioning instructions.

The problem starts, of course, back when the font is designed. Some font design applications set the width of these combining characters to zero, even though the graphics obviously have some width. Other programs allow these characters to have non-zero widths…

I _think_ the group on the left provides the correct behaviour. But I’m not 100% sure.

Well, I got this far, then kind of gave up. Fonts are tricky… 🤣

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 3:32pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/14 "2021-11-13T15:32:22Z")

</div>

> [@DNF](#):
>
> Anyway, unicode variables are a must in maths-heavy code. It’s absolutely indispensable.

This is patently wrong: there are thousands of mathematical libraries that contain not a single unicode character. What makes them legible (or not) is not the characters, it is the software design.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 3:46pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/16 "2021-11-13T15:46:44Z")

</div>

Again, not impossible. It has been done many times already. BTW: if you say it is crucial to employ unicode, you should be able to point to at least one library that demonstrates this. Can you?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 3:58pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/18 "2021-11-13T15:58:45Z")

</div>

You claimed it was impossible. You prove it.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 4:08pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/20 "2021-11-13T16:08:49Z")

</div>

Hence it is possible. QED

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 13, 2021, 4:12pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/21 "2021-11-13T16:12:12Z")

</div>

Listen. I guess you’re not that used to tongue-in-cheek hyperbole. I’m clearly being over-the-top and deliberately irrational.

My point is, I’ve written a bunch of mathematical codes without unicode, and it really, really sucks. When I am able to bring in a sprinkling of Greek letters, and maybe some other decorations, it cleans the code up _dramatically_. It’s a real life-saver, it doesn’t just make the code easier to understand, and much more concise, it also reduces typos and bugs, even mathematical errors.

As far as I’m concerned, unicode symbols in computer code is the best invention in the history of the universe, and I won’t let anyone tell me they’re a bad idea.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 13, 2021, 4:16pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/22 "2021-11-13T16:16:57Z")

</div>

I have written a lots of code with math, and I never needed a unicode character.  
Introducing characters which look the same but have different meanings into the code  
is a bad idea, period.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 13, 2021, 4:22pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/23 "2021-11-13T16:22:10Z")

</div>

> [@PetrKryslUCSD](#):
>
> and I never needed a unicode character.

Yes you did, you just didn’t realize it 😉

> [@PetrKryslUCSD](#):
>
> Introducing characters which look the same but have different meanings

Doing that would be terrible. But your example didn’t demonstrate this, probably because you forgot to mutate inside `f!`.

Anyway, just for fun, I’ll prove my assertion.

**Definition:** _Maths-heavy code_ is code that is unreadable without unicode symbols.

It follows that one cannot write readable maths-heavy code without unicode.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 13, 2021, 4:28pm UTC](https://discourse.julialang.org/t/accented-characters-in-vscode/53234/24 "2021-11-13T16:28:14Z")

</div>

This thread was about accented characters.😦

[Next page](https://discourse.julialang.org/t/accented-characters-in-vscode/53234.md?page=2)
