Template talk:Chem2/Archive 1
This is an archive of past discussions about Template:Chem2. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
Best chem template IMO
This template is both editor friendly (keyboard input!) and good at output showing. Worth being the top (one and only) chem formula template. CAn we work toward thAT? -DePiep (talk) 20:23, 23 December 2018 (UTC)
How do I insert an asterisk?
I can get an asterisk as superscript with {{chem2|Cp^{*}2Fe}} = "Cp*2Fe". But how do I get an asterisk at normal height, as in "Cp*2Fe"? Neither {{chem2|Cp*2Fe}} = "Cp·2Fe" nor {{chem2|Cp\*2Fe}} = "Cp\*2Fe" seem to work. (Yes, that notation is actually used, e.g. for decamethylferrocene.) --Jorge Stolfi (talk) 12:35, 2 March 2019 (UTC)
- My first thought, nowiki tag, does not work :-(
- {{chem2|Cp<nowiki>*</nowiki>2Fe}} → Cp'"`UNIQ−−nowiki−−00000009QINU`"'2Fe
- -DePiep (talk) 13:06, 2 March 2019 (UTC)
- @Jorge Stolfi: I didn't think about the asterisk when making the module. But now you can use \* for an asterisk. E.g. {{chem2|Cp\*2Fe}} gives Cp*2Fe. Christian75 (talk) 08:43, 3 March 2019 (UTC)
- In the sentence "... nor {{chem2|Cp\*2Fe}} = "Cp\*2Fe" seem to work" two different templates are used: the purple text actually uses
{{Chem}}
not{{Chem2}}
. {{Chem}} fails, {{Chem2}} does not. -DePiep (talk) 11:49, 3 March 2019 (UTC)- OOPS! Sorry for wasting your time. Thanks! --Jorge Stolfi (talk) 12:43, 3 March 2019 (UTC)
- In the sentence "... nor {{chem2|Cp\*2Fe}} = "Cp\*2Fe" seem to work" two different templates are used: the purple text actually uses
Complicated charges
Here is another challenge: [FeCp*2]+/0 (from the decamethylferrocene article). Neither {{chem2|[FeCp\*2](+/0)}} = [FeCp*2](+/0) nor {{chem2|[FeCp\*2]^{+/0}}} = [FeCp*2]^{+/0} seem to work... --Jorge Stolfi (talk) 13:10, 3 March 2019 (UTC)
- @Jorge Stolfi: You can do that with {{chem2|[FeCp\*2]^{+/0}|}} (gives [FeCp*2]+/0) - you have to add the last | otherwise the MediaWiki software can't figure out where the template ends. Or maybe a better solution is something like {{chem2|[FeCp\*2]^{+/0}<!-- end of template -->}}. Christian75 (talk) 14:08, 3 March 2019 (UTC)
- Ah! Thanks for the help!. --Jorge Stolfi (talk) 15:20, 3 March 2019 (UTC)
Bad line breaks
My browser often breaks a formula like CO2 between the "CO" and the 2. Could you insert {{nowrap|...}}
to avoid that?
I would consider an "unbreakable block" to begin between characters X and Y if
- Y is a capital letter, and X is neither a letter, nor a digit that is part of a multiplier -- e.g. before the "C" in "Na2CO3" but not in "Ni2*10CO" or "Ni2SiC3"; or
- Y is a digit that is part of a multiplier, and X is not part of it -- e.g. before the "1" in "Ni2\*10CO".
And I would consider a block to end between X and Y if
- A block begins there; or
- Y is a close parenthesis, close bracket, close brace, or bar that is not parsed as part of a subscript or suercript -- e.g. after the 3 in "Na2(CO3)2", "Na2[CO3]2", "Na2CO3|(2H2O)", but not after the "+" in "Fe(3+)C6N6" or after the "3" in "Fe^{x+3}PO4".
- X is a "\d", "\s", "*", etc.
But I haven't thought much about these rules, you may find better ones. Anyway, the idea then is that you insert {{nowrap|...}}
around each block.
Makes sense? --Jorge Stolfi (talk) 19:28, 8 April 2019 (UTC)
Right arrow
Surely must it be " → " per the original author? Wouldn’t " ⟶ " be better? Incnis Mrsi (talk) 13:58, 27 August 2019 (UTC)
- Or, alternatively,
->
may expand to “→” but-->
to “⟶”. Incnis Mrsi (talk) 14:04, 27 August 2019 (UTC)
\'
The original author for some obscure reason recommended to stuff formulas with apostrophes using {{chem2|…\'
…}}. In fact, U+0027 is a convenient keyboard character but not a typographic device, and certainly not a good substitute for primes. On the other hand there is no need to escape U+0027 ' APOSTROPHE in arguments for templates. Look:
- {{pagelinks|''}} → (edit | talk | history | links | watch | logs)
- {{otheruses|'''}} →
- {{#invoke:String|replace|''|'|/}} → //
- {{#invoke:String|replace|'''|''|“}} → “'
- {{#invoke:String|replace|'''|'|/|2}} → //'
- {{#invoke:String|replace|[[''c'']]|c'|d}} → ''d'
In no case see we any problem with interpretation of U+0027 in the wiki code of the argument; escapes only are needed in the presentation form (found in the source code left of “→”).
Hereby I propose:
'
→ ′''
→ ″'''
→ ‴
I already deleted the \'
thing from documentation, and consequently all its uses may be replaced with either straightforward apostrophes or literal prime characters. Incnis Mrsi (talk) 15:56, 27 August 2019 (UTC)
- If your proposal is to change ''/''' automatically to ″/‴ you have a problem with input like:
{{chem2|C_{''n''}H_{2''n''+2}|}}
which uses wiki markup. The template gives you the option to make a ', but you are not forced to use it. Christian75 (talk) 06:06, 28 August 2019 (UTC)- I got it now. Then it would be wise to insert explicit primes either literally (UTF-8) or using entities. Thanks for the timely warning! Incnis Mrsi (talk) 06:22, 28 August 2019 (UTC)
Unexpected wrapping
Table 1: Incnis Mrsi original post demo (extended by DMacks) | ||
---|---|---|
Incnis Mrsi's original |
Running text |
class= "nowrap" |
DMacks's additions |
||
Please, fix. I’m lazy to investigate because have no privilege to edit many templates on this site. Incnis Mrsi (talk) 19:53, 16 August 2019 (UTC)
- Noting for ping purposes that this is a continuation or more limited case than Jorge Stolfi's thought in #Bad line breaks. DMacks (talk) 16:12, 17 August 2019 (UTC)
- The template here is a wrapper around the real functionality in Module:Chem2. Keeping a chemical formula together is pretty important. But
<div class="nowrap">
around the whole result is not sufficient—see my first additional example. Using<span class="nowrap">
(equivalent to {{nowrap}}), my second example seems better in that regard. But I think we do want to allow breaking at whitespace, as in a chemical equation rather than just a single formula as in my third example. Even {{wbr}} doesn't seem to allow breaking, despite what that template indicates. - It seems heavy-handed to wrap each non-space chunk in the formula with its own
span
. Is there a CSS way to allow breaking only at whitespace (not at other word-breaks)? DMacks (talk) 16:10, 17 August 2019 (UTC)- Why namely CSS? A sane HTML code should be generated, not one full of loopholes for bad wrapping. Normally it’s a bad idea to permit one “word” (compound) to be broken, but for long ones—IMHO for cases even longer than examples below—a very thin space can be inserted in places where wrapping is tolerable. See below examples based on U+2009 space. Incnis Mrsi (talk) 17:04, 17 August 2019 (UTC)
Table 2 | |
---|---|
C2H5 OH
|
|
C2H5 OH
|
|
C2H5 OH
|
|
Attention! It is not {{chem2}}, it is HTML. |
- I agree with OP Incnis Mrsi: there should be a nowrap there. Now re DMacks on processes (lines having -->), I note:
1. Do those formulae really accept a line-break, being spread over multiple reading lines? 2. right now, the nowrap
is more important than the unwanted linebreak DMacks points to. IOW: add the nowrap now, make detailed exceptions later (least harm). -DePiep (talk) 18:59, 17 August 2019 (UTC)
- Wait… I used
class=nowrap
as a debugging device. I don’t think that dependence on this class would be a good solution of this specific problem – see the discussion above. Incnis Mrsi (talk) 19:31, 17 August 2019 (UTC)- Why would using
class=nowrap
in the template not be OK? -DePiep (talk) 19:34, 17 August 2019 (UTC)- Because the stuff should generally admit line breaks. It just may not behave in the present moron
’s way. Incnis Mrsi (talk) 11:10, 23 August 2019 (UTC)- One more judgemental and otherwse useless post by IM. I'm sorry I spend time on this, all one gets is Mr. Emotional's I feelbad and I'll let you know it responses. These weeks I've not met any situation where IM is cooperating to imporove the wiki. -DePiep (talk) 07:06, 24 August 2019 (UTC)
- I develop a fix to module:Chem2 which will group “words” (compounds) under
<span class=nowrap>
. At first, whitespace (such as in2H2 + O2
) and reaction arrows are to serve word terminators, but suggestions about non-obvious loopholes are accepted. Incnis Mrsi (talk) 10:59, 27 August 2019 (UTC)- Sure. (BTW, do you see that you did not reply to either the "emotional" & "judgemental" aspect, nor the "cooperation" detail? At all?) -DePiep (talk) 21:03, 27 August 2019 (UTC)
- Because the stuff should generally admit line breaks. It just may not behave in the present moron
- Why would using
Sandboxing
Made Template:Chem2/sandbox, using Module:Chem2/sandbox (diff) . See Template:Chem2/testcases. -DePiep (talk) 19:47, 17 August 2019 (UTC)
- Does not work well: cannot add the clas=nowrap properly. Pls improve the sandbox. -DePiep (talk) 19:50, 17 August 2019 (UTC)
- I tried adding it at the level of the Template wrapper (not the underlying Module itself). The testcases page is a mess because the sandbox module is broken, but I tested it against this here talkpage and it seemed to fix Table 1. DMacks (talk) 08:17, 24 August 2019 (UTC)
- Looks like an improvement, so I propose we update the template. (BTW, the reason I could not get it working in the module sandbox is that I can't get the tagging code right, in Lua. Someone else might). -DePiep (talk) 12:26, 24 August 2019 (UTC)
- Add: return '<span class="chemf nowrap">' .. formula .. '</span>' to the module itself. Christian75 (talk) 05:45, 28 August 2019 (UTC)
- Applied Module:Chem2/sandbox (with this edit) to {{Chem2/sandbox}}. See /testcases#Line_wrapping: issue seems solved. Long lines that do need linebreak (like reactions): Use separate {{Chems}}'s, add this to /doc. -DePiep (talk) 11:46, 11 September 2019 (UTC)
- I tried adding it at the level of the Template wrapper (not the underlying Module itself). The testcases page is a mess because the sandbox module is broken, but I tested it against this here talkpage and it seemed to fix Table 1. DMacks (talk) 08:17, 24 August 2019 (UTC)
Done Updated the module [1]. -DePiep (talk) 11:51, 11 September 2019 (UTC)
Invalid character in formula!!!!!!
Why does this clause exist? If there is something that the module doesn’t understand, then it should be reproduces verbatim, only adding a tracking category for avoidance of accidental syntax gaffes. Incnis Mrsi (talk) 09:54, 27 August 2019 (UTC)
for t, x in item(f) do
Why this iterator construction? How is this sophistication better than a straight loop? This (t, x) structure only hinders development of extra functionality. Incnis Mrsi (talk) —Preceding undated comment added 14:26, 27 August 2019 (UTC)
why snowman?
Mn2☃+ is Mn2☃+, Mn2(2–) is Mn2−2, Mn2(2☃–) is Mn2(2☃−) ... Si&☃Si is Si&☃Si — Preceding unsigned comment added by 188.92.185.94 (talk) 14:08, 18 May 2020 (UTC)
Distinguish n-dash from hyphen/minus; accept = and ≡
Would you consider treating "–" (n-dash) and "—" (m-dash) as alternatives to "\s"? Note that they are distinct characters than "-" (hyphen, dash) and "−" (minus sign), which of course should retain their current meaning. Also treat "=" as the same as "\d", and "≡" the same as "\t". (Maybe it does this already? But the documentation does not say so.) They would make the source formulas much easier to read, and make the template easier to learn. All the best, --Jorge Stolfi (talk) 13:26, 2 July 2020 (UTC)
Getting uncommon subscripts and superscripts aligned
The call |{{chem2|M^{''x''+}_{''n''}|}}| generates |Mx+n|, and |{{chem2|M_{''n''}^{''x''+}|}}| generates |Mnx+|. How do I get the "n" to line up under the "x+" ? --Jorge Stolfi (talk) 01:57, 13 July 2020 (UTC)
- @Jorge Stolfi: It's not the best method, but if you mean |Mx+n|, |{{chem2|M^{''x''+}\ ''n''}}| works! Might not be the answer you're looking for, but it's functional. TuskDeer (talk) 04:22, 1 September 2020 (UTC)
- @TuskDeer: Sorry, I meant for the subscrpts and superscripts to be vertically aligned, left-justified; like those in O2−
3 (old "chem" template) or O2−3 (with "chem2").
--Jorge Stolfi (talk) 04:29, 1 September 2020 (UTC)- @Jorge Stolfi: I'm sorry! I guess I can't be much help then. Good luck figuring something out. TuskDeer (talk) 04:41, 1 September 2020 (UTC)
- @TuskDeer: Sorry, I meant for the subscrpts and superscripts to be vertically aligned, left-justified; like those in O2−
Problems with formatting coefficients (?)
Not sure if "coefficient" is the right word for what I'm talking about, but for example, here's the formula for cowlesite: CaAl2Si3O10·5-6H2O I can only produce that result by leaving the "5-6" outside of the template because
- {{chem2|CaAl2Si3O10*5-6H2O}} (hyphen, en-dash, or minus) gives CaAl2Si3O10·5−6H2O
- {{chem2|CaAl2Si3O10*{5-6}H2O}} ({} or () ) gives CaAl2Si3O10·{−56}H2O
- {{chem2|CaAl2Si3O10*5\-6H2O}} gives CaAl2Si3O10·5-6H2O
- {{chem2|CaAl2Si3O10*5\-(6H2O)}} gives CaAl2Si3O10·5-(6H2O)
- {{chem2|CaAl2Si3O10*5\-{6H2O}|}} doesn't work
Is there a way to format it that I'm not thinking of? TuskDeer (talk) 03:48, 1 September 2020 (UTC)
- @TuskDeer: I don't think there is a way at the moment. But one way to add it could be to have \x (x is a digit) to print normal numbers. I have made a sandbox version (Module:chem2/sandbox). That means you can write {{chem2/sandbox|CaAl2Si3O10*\5\-\6H2O}} --> CaAl2Si3O10·-H2O. Any comments. Christian75 (talk) 18:09, 1 September 2020 (UTC)
- @Christian75: Just a general comment from a computer scientist: the recipe for good successful software includes a user interface that can be immediately learned by intuition and/or from a few examples and/or from simple experiments. That was the main "secret" of Apple's success. And I don't recall ever having looked at the documentation of the old {{chem|}} template: a couple of examples and experiments told me everything I needed to use it (except that "=" breaks it -- because of the general template mechanism, not of that one specifically).
So, one problem I see with the new chem2 is that its syntax and semantics are a lot more complicated and less intuitive. Could they be simplified somehow? Like,- a formula is a series of segments. Each segment is a 'base' (which may be empty) followed by a 'subscript' and/or a 'superscript' in any order. The last two are typeset in half-size font, stacked and left-aligned. In general a subscript is written {...} and a superscript is written (...), and segments are separated by '|'. However, digits and a sign in a segment after a non-digit are interpreted as a superscript. Digits after a non-digit and without a terminating sign are interpreted as a subscript. Leading digits in a segment are included in the base. Anything that cannot be parsed as a base followed by subscript and/or superscript is taken to be the start of a new segment. Line breaks may be allowed between some segments if the formula is too long. Backslashes can be used to specify that the characters '|=+-−{}()' or digits be treated as letters.
- Please consider also using instead the TeX notation for subscripts and superscipts, namely "BaK_2^+Sr_{23}^{x-}" to get BaK+
2Srx−
23. Many editors will be familiar with it. Possibly with some shortcuts like those above, so that one could write just "BaK2^+Sr23^x-" --Jorge Stolfi (talk) 19:33, 1 September 2020 (UTC)
- @Christian75: Just a general comment from a computer scientist: the recipe for good successful software includes a user interface that can be immediately learned by intuition and/or from a few examples and/or from simple experiments. That was the main "secret" of Apple's success. And I don't recall ever having looked at the documentation of the old {{chem|}} template: a couple of examples and experiments told me everything I needed to use it (except that "=" breaks it -- because of the general template mechanism, not of that one specifically).
Subscripts/superscripts a bit too small?
I love the chem2 template, but I feel that its subscripts and superscripts are a bit too small. Compare the chem2 result:Fe2+2 with old chem: Fe2+
2 and HTML sub/sup: Fe22+. The scripts in the first come out noticeably smaller than in the other two. (Do you see it in our browser, or could it be just me?)
Would you consider increasing the font size to match the old style? It seems that the old size is still small enough to preserve the natural line spacing. The lines in the four columns below are perfectly aligned on my screen:
chem2 | chem | HTML | none |
---|---|---|---|
No one would have believed in the last years of the nineteenth century that this world was being watched keenly and closely by intelligences Fe2+2 greater Fe2+2 than man's and yet Fe2+2 as mortal as his own; that as men busied Fe2+2 themselves Fe2+2 about their various Fe2+2 concerns Fe2+2 they were scrutinised and studied, perhaps Fe2+2 almost as narrowly as Fe2+2 a man with a microscope might scrutinise the transient creatures that swarm and multiply in a drop of water. | No one would have believed in the last years of the nineteenth century that this world was being watched keenly and closely by intelligences Fe2+ 2 greater Fe2+ 2 than man's and yet Fe2+ 2 as mortal as his own; that as men busied Fe2+ 2 themselves Fe2+ 2 about their various Fe2+ 2 concerns Fe2+ 2 they were scrutinised and studied, perhaps Fe2+ 2 almost as narrowly as Fe2+ 2 a man with a microscope might scrutinise the transient creatures that swarm and multiply in a drop of water. |
No one would have believed in the last years of the nineteenth century that this world was being watched keenly and closely by intelligences Fe22+ greater Fe22+ than man's and yet Fe22+ as mortal as his own; that as men busied Fe22+ themselves Fe22+ about their various Fe22+ concerns Fe22+ they were scrutinised and studied, perhaps Fe22+ almost as narrowly as Fe22+ a man with a microscope might scrutinise the transient creatures that swarm and multiply in a drop of water. | No one would have believed in the last years of the nineteenth century that this world was being watched keenly and closely by intelligences greater than man's and yet as mortal as his own; that as men busied themselves about their various concerns they were scrutinised and studied, perhaps almost as narrowly as a man with a microscope might scrutinise the transient creatures that swarm and multiply in a drop of water. |
--Jorge Stolfi (talk) 05:05, 16 April 2019 (UTC)
- Done - font size has been increased to 80%. User:GKFXtalk 22:03, 24 November 2021 (UTC)
Backwards compatibiliy with {{chem}}" subscripts/superscripts
The call {{chem|H|2|O|2}}" gives "H
2O
2" while {{chem2|H|2|O|2}}" gives "H" with no error warning.
Would it be possible to make the "|number" arguments work in {{chem2}} like they do in {{chem}}? That would make it easier to upgrade... (Or at least give a warning if any arguments of the template call are ignored.)--Jorge Stolfi (talk) 13:44, 2 July 2020 (UTC)
- Done @Jorge Stolfi: I have added a preview warning to calling {{chem2|H|2|O}}. User:GKFXtalk 21:19, 24 November 2021 (UTC)
Incorrect nomenclature
According to the IUPAC Red Book, bridging ligands are identified by the greek letter mu, followed by a subscripted number identifying the number of centers it is bonded to. The current chem2 (\m{1}) format forces this to be superscripted. This should be updated to yield the correct nomenclature. — Preceding unsigned comment added by 147.155.82.15 (talk) 16:52, 3 December 2020 (UTC)
- I have just changed it, thanks for the report. Swaare (talk) 16:24, 27 May 2021 (UTC)
Why does this this template emit <br> tags?
If I copy the formatted output of, say, {{chem2|C2H3O2(-)}}
(resulting in C2H3O−2), and paste it into an editor, textbox, etc., I get:
C 2H 3O− 2
This happens because <br>
tags are emitted before each of the numbers. That is semantically incorrect HTML. Why are the <br>
tags being overloaded and used for non-linebreaking display purposes? sbb (talk) 17:29, 8 March 2021 (UTC)
- @Sbb: It outputted <br/> tags because the stacked super/subscript was a copy of Template:Su, which does that. I have re-implemented it with just <span>s and TemplateStyles so there are now no br tags. User:GKFXtalk 22:06, 24 November 2021 (UTC)
font size
This (taken from the section above):
{{chem2|C2H3O2(-)}}
→ C2H3O−2
renders like this:
'"`UNIQ--templatestyles-0000007B-QINU`"'<span class="chemf nowrap">C<sub class="template-chem2-sub">2</sub>H<sub class="template-chem2-sub">3</sub>O<span class="template-chem2-su"><span>−</span><span>2</span></span></span>
MOS:SMALL says that text should not be smaller that 85% of the default font size so style attributes specifying font-size:70%
are in violation of that restriction.
—Trappist the monk (talk) 21:46, 18 September 2021 (UTC)
- I don't read MOS:SMALL to absolutely restrict any text from being smaller than 85%. I see it as limiting the size of baseline text. Super- and subscripted text is almost always less than 85% of the baseline text. For instance, according to Subscript and superscript, HTML is "usually reduced to around 75% original size", and LaTeX appears to use ~70%. I know that common.css uses 85% for
<sup>
and<sub>
, but for math and formulae, those sizes are way too big. Visually, {{chem2}} appears closer to {{chem}}'s sup/subscript size, and roughly similar to<math>
LaTeX. Also, {{su}} (Module:Su) uses 80% by default. — sbb (talk) 04:51, 19 September 2021 (UTC) - I also think that the current size is too small. If there are {{chem2}} and plain
<sub>...</sub>
on the same page the difference is quite obvious. I would say 80% is fine. The other values in that style will need adjusting down as they are specified in ems which are relative to the font size. User:GKFXtalk 20:30, 24 November 2021 (UTC)- Done Font size bumped to 80% to match Template:Chem. User:GKFXtalk 22:06, 24 November 2021 (UTC)
- Why does [[Sulfate|{{chem2|SO4(2-)}}]] (output: SO2−4) works here, but not on an empty page (see [2]), or a page without any other chem2? (it worked before the recent changes) Christian75 (talk) 13:56, 25 November 2021 (UTC)
- @GKFX: Any idea? Christian75 (talk) 07:08, 26 November 2021 (UTC)
- @Christian75: Looks like a known bug, phab:T200704. Use the link parameter instead if this is a problem on an actual page: SO2−4. User:GKFXtalk 07:50, 26 November 2021 (UTC)
- Thanks. I was just surprised it didn't work, and could not see why... But an old bug... Christian75 (talk) 21:40, 28 November 2021 (UTC)
- @Christian75: Looks like a known bug, phab:T200704. Use the link parameter instead if this is a problem on an actual page: SO2−4. User:GKFXtalk 07:50, 26 November 2021 (UTC)
- Done Font size bumped to 80% to match Template:Chem. User:GKFXtalk 22:06, 24 November 2021 (UTC)
Changes of 24 and 28 November
Multiple articles appear in Category:CS1 errors: invisible characters because there is a 'templatestyles stripmarker' in the code. DrKay (talk) 08:50, 4 December 2021 (UTC)
- @DrKay: This template is already explicitly documented as not being suitable for use in citation templates. Is it really necessary to avoid the use of templatestyles rather than e.g. removing it from the citations? User:GKFXtalk 11:57, 12 December 2021 (UTC)
- I'm happy to remove it from citations. DrKay (talk) 12:00, 12 December 2021 (UTC)
An exploration of this template's handling of Template:Chemical formula syntax
Since it's been proposed that {{Chemical formula}}
be deleted, with the existence of this template proffered as evidence why it's not really needed, I wanted to explore how {{chem2}}
would handle existing {{Chemical formula}}
transclusion syntax, if they were redirected to this template.
{{Chemical formula|H|2|O}}
produces: H2O{{Chemical formula|H|2|S|O|4}}
produces: H2SO4{{Chemical formula|H2O}}
produces: H2O{{Chemical formula|Ca|SO4}}
produces: CaSO4
{{Chem2|H|2|O}}
produces: H{{Chem2|H|2|S|O|4}}
produces: H{{Chem2|H2O}}
produces: H2O{{Chem2|Ca|SO4}}
produces: Ca
...So the answer is, not well at all. That's too bad, it would've made the decision easy. Template:Chem2 is implemented by Module:chem2, which could certainly be taught to understand Template:Chemical formula syntax, but that would require a Lua programmer willing to invest the time. FeRDNYC (talk) 01:10, 5 January 2022 (UTC)
- @FeRDNYC: I've gone through the sandbox and adapted it so
{{chem2/sandbox|[[Ca]][[SO4]]}}
→ CaSO4, similar to the {{chemical formula}} template but more in the style of chem2 (everything in one parameter). The more common element-like symbols from that template are supported by the auto-link mode:{{chem2/sandbox|Ph2CHCH3|auto=1}}
→ Ph2CHCH3, but not the more obscure ones which are probably best done manually. I'll move that functionality over to the main template if no objections; I would expect the backward-compatiblity impact to be small if any. User:GKFXtalk 20:34, 5 January 2022 (UTC)- It looks fine: The tellurol group should be removed - I guess it would never be used (TeH not Teh). The R group links to disambiguation page. The link should be changed to substituent . You can already make wikilinks inside the chem2 template, e.g.
{{chem2|[[Aniline|C6H5NH2]] + [[phosphate|PO4(3-)]]}}
→ C6H5NH2 + PO3−4. Christian75 (talk) 16:48, 7 January 2022 (UTC) - And "OH" has two meanings in formulas. In Mg(OH)2 it is a hydroxide but in CH3CH2OH it's a hydroxy group. Christian75 (talk) 19:12, 8 January 2022 (UTC)
- Yeah, that's a dubious one, I think it should be removed due to the ambiguity. User:GKFXtalk 20:04, 8 January 2022 (UTC)
- @GKFX: That sounds fine, and certainly added functionality can't hurt, but I'm not sure anything other than exact syntax parity is really useful for the task at hand (expediently deprecating
{{Chemical formula}}
). - If
{{chem2}}
had the ability to accept{{Chemical formula}}
transclusions unmodified — IOW, not "more in the style of" anything — then Template:Chemical formula could be replaced with a redirect to Template:chem2 and we're done. But if, OTOH, all of the existing{{Chemical formula}}
transclusions have to be visited and modified, either manually or semi-automatically, then ideally they would be rewritten to make full use of{{chem2}}
's preferred/best-supported syntax. - Or are there difficulties inherent in translating from
{{Chemical formula}}
syntax to{{chem2}}
syntax, that are avoided with your hybrid syntax? If the path from{{Chemical formula|syntax}}
to{{chem2|hybrid syntax}}
is more straightforward/automatable than the path to{{chem2|standard syntax}}
then certainly it would help relieve the burden of switching templates to go the hybrid route. FeRDNYC (talk) 03:54, 11 January 2022 (UTC) - The other thing is... it also strikes me that it should be pretty easy to make
{{chem2}}
support {{tlx}Chemical formula}} syntax, specifically because{{chem2}}
only takes more than a single (unnamed) parameter in very rare cases that are easy to test for, and never ever takes more than two unnamed parameters. At least, not as far as I can tell. We can use that to our advantage. - If
{{chem2}}
is ever passed more than two unnamed parameters, or even a non-empty second unnamed parameter, that can be taken to mean that it should interpret the arguments as{{Chemical formula|atom1|num_atom1|atom2|num_atom2|...}}
syntax. - If we turned off the empty-arg-removal functionality of
getArgs()
, adding that logic becomes as simple as testing for a non-emptyargs[2]
, or anargs[3]
with any value other thannil
, and applying{{Chemical formula}}
-style parsing. IOW, something akin to...
- It looks fine: The tellurol group should be removed - I guess it would never be used (TeH not Teh). The R group links to disambiguation page. The link should be changed to substituent . You can already make wikilinks inside the chem2 template, e.g.
function p.chem(frame) local args = getArgs(frame, { removeBlanks = false }) return p._chem(args) end function p._chem(args) local itersrc = nil if args[2] and (args[2] != '' or args[3]) then itersrc = argiter(args) else itersrc = item(f) end for t, x in itersrc do -- and then the function proceeds normally function argiter(args) local i = 1 return function () local n = i * 2 i = i + 1 local t, x = nil, nil if not args[n] then return t, x end t = T_ATOM x = args[n] if args[n + 1] then x = x .. args[n + 1]; end return t, x end end
- That's just a quick sketch, and assumes that a new state flag
T_ATOM
would be added to thep._chem
processing, to trigger special handling of{{Chemical formula}}
-style atom args. (Which it reassembles from separated atom|# args to a combinedatom#
— would that be correct in all cases?) - At a minimum
T_ATOM
could trigger a forced, always-enabled version of the autolinking behavior that doesn't depend on anauto=truthy
parameter being passed to the template. Other than that it'd probably be 90% the same asT_ELEM
, looks like. FeRDNYC (talk) 04:01, 11 January 2022 (UTC)- I would much rather go through the articles myself and review them individually – I don't think it will take me long to do 80 pages. One of the reasons for deleting the template is to remove the awkward syntax with lots of vertical bars; adding that syntax to chem2 would only perpetuate it. Also, in many cases, links on every element aren't necessary and were only added because that's what the template did, so it would be an opportunity to get rid of them. E.g. something like
- breaks WP:OVERLINK so it's worth looking at those pages. User:GKFXtalk 18:39, 11 January 2022 (UTC)
- To me, looks like: (1) find solution for the predefined groups (add to Chem2?); (2) replace in all articles with {{Chem2}}; (3) delete.
- I see no advantage in keeping this template alive, esp not next to Chem2 with different input options. Oh and then there are a dozen other more chem formula templates with their own /doc to familiarize with (see Category:Chemistry formatting and function templates (23)). -DePiep (talk) 10:22, 13 January 2022 (UTC)
- To be clear: better try to prevent different input form requirements for ~similar situations. -DePiep (talk) 11:32, 13 January 2022 (UTC)
- That's just a quick sketch, and assumes that a new state flag
Background information
- Template:Chemical formula § Predefined options (groups, molecules, special symbols) -- The 39 predefined codes
- Template:Chem2 § Predefined (11+18=29) * (B-set links in there to be checked, like COOH)
- Template:Chemical formula/testcases § Predefined (39)
- Template:Chemical formula/testcases § Elements (118)
- Note: {{Chemical_formula/atom}}: probably #switch:..|#default= is an error situation (input not recognised or defined) and c/should be tracked. (Or handled when transforming into {{Chem2}}). -DePiep (talk) 09:27, 13 January 2022 (UTC)
- Note: {{Chemical_formula/atom}} does
#lc:
all input code (symbols). This is not needed. Worse: could produce hidden errors. I propose to require proper cased input only. (i.e., do not lc the input). Be clear in /doc how predefined formula (-casing) should be entered. -DePiep (talk) 09:32, 13 January 2022 (UTC)
- Note: /doc § Predefined
pls someone take a look at the second set ("B"): the linking is not correct (COOH ?)solved, use input like|1=ABC[[COOH]]XYZ
). -DePiep (talk) 15:05, 13 January 2022 (UTC)
Change _autodoc
{{#invoke:chem2|_autodoc}}
adds wikitables with all codes (overview of recognised symbols & groups). See Template:Chem2/testcases § autodoc. It also adds two ===-level sectionheaders.
I propose that the layout parts (section headers, introduction text) is removed from the autodoc (module function). Better this could be formatted in the /doc page itself. (TBH, I do not even understand the [[COOH]]
'explanation' as given). -DePiep (talk) 18:41, 13 January 2022 (UTC)
Also, personally I would split the true element symbols (H, Hg) and the generic element symbols (R, X) into different tables. -DePiep (talk) 19:09, 13 January 2022 (UTC)