Dave Novo 51 Posted February 9, 2023 Hello, I am trying to use some unicode math symbols as variables to make code more readable. But I cannot seem to find out how to insert unicode characters into my source code. I am using the consolas (the default) font in the editor. I saw on the internet some blogs that in other apps you enter the code value and then Alt+X, but that brings up model maker code explorer menu. Any tips are appreciated. Share this post Link to post
Lajos Juhász 293 Posted February 9, 2023 For me the easiest way is to use the character map copy - paste it into the source. Tested using var Φ: real; begin Φ:=5.8; showmessage(FloatToStr(Φ)); end; Share this post Link to post
programmerdelphi2k 237 Posted February 9, 2023 (edited) have you tried changing the file encode to UTF8 instead of ANSII, before insert the char? Despite being something quite peculiar and perhaps something to create future problems with the use of exotic characters, especially when this can bring inconvenience between platforms and editions of the IDE, since the RAD from time to time crashes due to a malfunction in the Editor of Code. Edited February 9, 2023 by programmerdelphi2k 1 Share this post Link to post
Uwe Raabe 2057 Posted February 9, 2023 (edited) 2 hours ago, Dave Novo said: you enter the code value and then Alt+X, but that brings up model maker code explorer menu. Sorry, but that is caused by just a simple RethinkHokeys call to the main menu. 🤷♂️ Edited February 9, 2023 by Uwe Raabe Share this post Link to post
Anders Melander 1783 Posted February 9, 2023 55 minutes ago, Dave Novo said: you enter the code value and then Alt+X That method only applies to MS Office (Word, Excel, etc). AFAIK this is the only keyboard method that works universally: In the registry, under the HKEY_Current_User/Control Panel/Input Method, set the EnableHexNumpad value to "1" (it's a REG_SZ value in case you need to add it). Press and hold the Alt key. Press the + key on the numeric keypad (I hope you got one 🙂 ). Type the hexadecimal unicode value. Release the Alt key. Share this post Link to post
Rob Truby 4 Posted February 9, 2023 Microsoft PowerToys has a Quick Accent feature that also includes Greek symbols etc. You may find it useful. Share this post Link to post
timfrost 78 Posted February 10, 2023 The PowerToys utility really only does accents and I found it inflexible when I tried (and then abandoned) it. I use Wizkey from https://antibody-software.com/wizkey/ even though it has a small cost (and a free trial). Easy to use either from the keyboard or from a popup menu, which I have set to pop up with two presses of the Control key. This menu is customizable so you can ensure your commonly needed characters are immediately to hand, without having to remember a Unicode value. The menu has an option to show a full char-map for selection also. Of course it works everywhere, not just in the IDE. Share this post Link to post
Fr0sT.Brutal 900 Posted February 10, 2023 (edited) If the set of used chars is short, you can use templates as well (built-in RAD ones or from cnPack or other helper wizard). Edited February 10, 2023 by Fr0sT.Brutal Share this post Link to post
Lars Fosdal 1792 Posted February 10, 2023 Windows standard app CharMap is another option. Share this post Link to post
Dave Novo 51 Posted February 11, 2023 Thank you everyone for all your great ideas! Share this post Link to post
Dave Novo 51 Posted February 18, 2023 As an update to this, I found a lot of success using Live Templates. It is a pain the butt to create all of them, but once they are working, then its is pretty easy. Please see here how to create the live template. An example of one that inserts the alpha symbol is below. Simply type /alpha<space> and you are good to go. <?xml version="1.0" encoding="utf-8" ?> <codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0"> <template name="\alpha" invoke="auto"> <description> inserts the σ symbol based on the latex syntax </description> <author> David Novo-Lake </author> <code language="Delphi" context="methodbody"><![CDATA[σ]]> </code> </template> </codetemplate> 1 Share this post Link to post
dummzeuch 1505 Posted February 18, 2023 That's no alpha symbol in your template, that's a lower case sigma. (Or it's the forum software that broke it.) Care to share those templates? Share this post Link to post
Dave Novo 51 Posted February 20, 2023 ugh. sorry, I was in the middle of creating a whole bunch of templates for different greek letters and was copying and pasting. Just change the \alpha to \sigma. Or replace the sigma symbol inside the CDATA and Description with an alpha. The other thing I found is that the template above will not insert the symbol into a comment. if you change the context to "comments" then it does, although seems to sometimes put it in the wrong spot when inside the comments. It seems to work fine in the method body. Also, inside the comment it is intermittent if it works automatically or you have to press CTRL+J or Ctrl+Space after entering the template name. Below is the alpha template <?xml version="1.0" encoding="utf-8" ?> <codetemplate xmlns="http://schemas.borland.com/Delphi/2005/codetemplates" version="1.0.0"> <template name="\alpha" invoke="auto"> <description> inserts the α symbol based on the latex syntax </description> <author> David Novo-Lake </author> <code language="Delphi" context="comment"><![CDATA[α]]> </code> </template> </codetemplate> Share this post Link to post