special Chemical letters lazarus / 21-General ---------------------------------------------------------------------- flori · 2021-03-12 14:16 Hi! Does anyone know how can I write in label or edit special chemical characters? (atomic weight and atomic number) for example: H+, Ca2+ Thank u ---------------------------------------------------------------------- balazsszekely · 2021-03-12 14:24 @flori QuoteDoes anyone know how can I write in label or edit special chemical characters? (atomic weight and atomic number) for example: H+, Ca2+Did you try ChemText from OPM? After package install, open the chemdemo application. You will see something like in the attachment. ---------------------------------------------------------------------- paweld · 2021-03-12 14:33 or DzHTMLText - html label component: https://github.com/digao- dalpiaz/DzHTMLText and sup and sub html tags ---------------------------------------------------------------------- Handoko · 2021-03-12 14:49 Sub and super scripts can be done easily even without using any third party component. For example: https://forum.lazarus.freepascal.org/index.php/topic,46775.msg333936.h tml#msg333936 ---------------------------------------------------------------------- Kays · 2021-03-12 14:54 Quote from: paweld on March 12, 2021, 03:33:27 pm[…] sup and sub html tagsI’m afraid this won’t be of much use if sub- and supscript is to be rendered. E.g. 0nX2+ shows a horizontal displacement between sub- and supscripts, but it’s supposed to like in the attached picture: ---------------------------------------------------------------------- wp · 2021-03-12 15:39 No, Handoko's code works exactly for this. You only must keep track of the horizontal painting position and restore it to that of the previous character when needed. Of course, you must do all the painting yourself - AFAIK there is not ready-made component for this complex index stuff. I do think, though, that ChemText can be extended to support this. The most difficult part is to conceive a reasonable syntax. How about such a syntax to define your symbol: Code: [Select]'$^0|_nX$_2|^+''$' ... store current horizontal position'|' ... return to stored painting position'^' ... superscript next character'_' ... subscript next characterThe painting occurs in procedure ChemTextOut of unit chemtext.pas, and measuring the text extent is done in ChemTextExtent. I think the parser is pretty straightforward. If you submit a patch I'd be glad to appy it. ---------------------------------------------------------------------- Handoko · 2021-03-12 16:13 Interesting, I like this challenge. Unfortunately I'm busy at this weekend, I'll pass. ---------------------------------------------------------------------- flori · 2021-03-12 16:35 thank you ---------------------------------------------------------------------- winni · 2021-03-12 18:30 Hi! This is a try with UTF-8 glyphs from subscript and superscript codeblock. If that is satisfying you don't need additional software: ⁰    ⁺   X ₙ    ₂ Winni ---------------------------------------------------------------------- wp · 2021-03-12 18:56 Quote from: wp on March 12, 2021, 04:39:40 pmHow about such a syntax to define your symbol: Code: [Select]'$^0|_nX$_2|^2''$' ... store current horizontal position'|' ... return to stored painting position'^' ... superscript next character'_' ... subscript next character Couldn't resist and implemented it myself. To get the new version either install the snapshot from https://sourceforge.net/p/lazarus- ccr/svn/HEAD/tree/components/chemtext/ or install from OPM and replace the file chemtext.pas by this version: https://sourceforge.net/p/lazarus- ccr/svn/HEAD/tree/components/chemtext/source/chemtext.pas Usage: like in the cited text (except for '$' which has been replaced by '@') The ChemLabel's Caption for the formula mentioned a few posts higher is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   ChemLabel1.Caption := '@^0|_nX@_2|^+'; See also: https://wiki.lazarus.freepascal.org/ChemText