[Interest] Preventing ^2 from being converted to a superscript 2

Ben Haller bhaller at mac.com
Sat Jul 25 08:05:43 CEST 2026


Hi Thiago (and I think this will reply to Max as well),

OK, so.  I'm only used to American keyboards on macOS, in which context 
(as far as I can tell) this concept of "dead keys" doesn't exist, so I'm 
unfamiliar with this territory.  What I'm familiar with is the other 
kind of method you describe, "pressing <Compose> <asciicircum> and a 
number", and I'm fine with that – then the intent of the user to produce 
these special characters is clear, and whatever happens next is their 
responsibility.  :->

I ought to have mentioned that this came up in France.  I was teaching a 
workshop to 30 French students, and out of those thirty, maybe 4 or 5 of 
them had this same problem.  They didn't understand what was happening, 
and they came to me asking for help -- "how do I type x^2, it keeps 
giving me a superscripted 2!" -- and I was mystified.  None of them had 
any idea why it was happening, and none of them had chosen this keyboard 
functionality intentionally. Eventually, by trial and error, we 
discovered together that (in your notation) <dead_circumflex> followed 
by a space, or I think also pressing <dead_circumflex> again, would 
provide <asciicircum>.  They wanted to turn this keyboard layout feature 
off, so that they could type code normally, and I didn't know how they 
could do that (and I still don't).

So, Thiago, you asked "Why do you want to interfere with other users' 
ability to type "O(n²)" in a comment?".  I have no desire to interfere 
with their ability to do that.  But the problem is that, unlike the 
"<Compose> <asciicircum>" method, the users here did not _intend_ to get 
a <dead_circumflex> instead of an <asciicircum>; it was happening to 
them against their will, and neither they nor I knew how to fix it (and 
even once we discovered a fix, it was annoying and inconvenient for them).

So OK, user error; they don't know their own keyboard layout, they don't 
understand their own operating system, their fault.  But weighing 
between "interfere with other users' ability to type "O(n²)" in a 
comment" and "make it so clueless users can type "x^2" in their code 
without getting lost in a rabbit hole they don't understand", the latter 
seems clearly preferable; I would happily flip that switch if I could.  
The user who is well-informed enough to understand all this and actually 
want to type O(n²) in a comment will presumably know to do <Compose> 
<asciicircum> to get what they want.

But I guess it sounds like there's nothing I can (reasonably) do about 
this anyway, so the discussion is somewhat moot.  :-<  I guess I just 
don't like the fundamental concept of "dead keys", because it seems like 
it just confuses novice users by doing magical things that they don't 
know how to turn off.  Oh well.

Thanks for the replies; I understand the problem better now, and thus 
can explain it to my users better, even if I (and they) don't like it.

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


On 7/25/26 3:21 AM, Thiago Macieira wrote:
> On Friday, 24 July 2026 12:45:07 Pacific Daylight Time Ben Haller via Interest
> wrote:
>> In the language being edited, ^ is the exponentiation operator, so the
>> user wants to type "x^2" and have that mean "x squared" in the language
>> on question.  An issue recently arose where some of my users on Linux
>> would type the "^2" and it would be turned into a superscripted 2 (!).
> Cannot reproduce in the widgetgallery example, Qt 6.13, Wayland and X11
> (XWayland), using no special input method.
>
> Are you sure your users are using the asciicircum key, not a dead_circumflex?
> Have them run xev and press the key. If it prints:
>
> KeyPress event, serial 39, synthetic NO, window 0x1200001,
>      root 0x43a, subw 0x0, time 130046808, (2009,-1014), root:(3839,76),
>      state 0x91, keycode 15 (keysym 0x5e, asciicircum), same_screen YES,
>
> Then we have to investigate. What input method are they using?
>
> If it prints
>
> KeyPress event, serial 39, synthetic NO, window 0x1200001,
>      root 0x43a, subw 0x0, time 130081096, (2009,-1014), root:(3839,76),
>      state 0x11, keycode 15 (keysym 0xfe52, dead_circumflex), same_screen YES,
>
> Then it's expected because it's a dead key. If you don't want it to affect the
> next key, press space.. <dead_circumflex> followed by a number will produce
> superscripts: ¹²³⁴⁵⁶⁷⁸⁹⁰. There are also ⁽ and ⁾. The same can be accomplished
> by pressing <Compose> <asciicircum> and a number. Likewise,
> <Compose>,<underscore> followed by a number will produce subscripts:
> ₁₂₃₄₅₆₇₈₉₀₍₎.
>
>> My question: how can I customize my QPlainTextEdit subclass to prevent
>> this?
> It's not QPlainTextEdit's doing. This happens much deeper. If the user is
> using an input method, then the translation happens there. You'll have to work
> out with the input methods (all of them).
>
> If there is no input method, it might be inside Qt: deep inside the XCB plugin
> (for X11) and Wayland plugin (for Wayland) that translate the sequence of keys
> to a symbol. They are obeying the xkb keyboard and Composition rules. If you
> REALLY want to do this, you'll need to patch the libraries and recompile.
>
>>   I'd also like to not interfere with typing of accented
>> characters, emojis, etc.; I just want to prevent this specific feature
>> from activating in my code view, because the '^' character is
>> significant and I don't want it to be re-interpreted by the OS
> Why do you want to interfere with other users' ability to type "O(n²)" in a
> comment?
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest



More information about the Interest mailing list