On 10/30/2024 1:21 AM, Bruce Horrocks wrote:


On 29 Oct 2024, at 23:22, Hans Hagen <j.ha...@xs4all.nl> wrote:

On 10/29/2024 11:33 PM, Jorge Manuel wrote:
Hello everyone,
I’m searching for an efficient way to represent electronic configurations in 
subshell and orbital notation within ConTeXt. I found similar examples 
discussed on StackExchange, which you can see here:
Atomic electronic configuration with small boxes <https:// 
tex.stackexchange.com/questions/372581/atomic-electronic-configuration- 
with-small-boxes/372598#372598>: https://tex.stackexchange.com/ 
questions/372581/atomic-electronic-configuration-with-small- boxes/372598#372598 
<https://tex.stackexchange.com/questions/372581/ 
atomic-electronic-configuration-with-small-boxes/372598#372598>
Box and arrow notation of writing electron configuration
https://tex.stackexchange.com/questions/616989/box-and-arrow-notation- 
of-writing-electron-configuration <https://tex.stackexchange.com/ 
questions/616989/box-and-arrow-notation-of-writing-electron-configuration>
Ideally, I’d like to use a package similar to atoms.sty for this purpose. Does 
anyone know of a straightforward approach to achieve this in ConTeXt?
Thank you very much for any guidance or examples!

It's no problem to come up with something as this kind of stuff is rather trivial but (as 
always with these things in context) the question is "what is the nicest 
interface?".

\definesymbol[electronu][\m{\upharpoonleft}]
\definesymbol[electrond][\m{\downharpoonright}]
\definesymbol[electronb][\m{\upharpoonleft\downharpoonright}]

\starttexdefinition protected electrons#1
    \dontleavehmode
    \doloopovermatch {.} {#1} {
        \inframed
          [width=\lineheight,height=\lineheight]
          {\symbol[electron##1]}
        \hskip-\linewidth
    }
    \unskip
\stoptexdefinition

\electrons{bddb}

\electrons{uddbuud}

Don't look at other packages, just think about what is best and most natural 
for the field, reading the source, and intreface wise fits into context (looks 
ok in the source, not like some hack). The above is just an example. We can 
always make clever parsers in lua but we need specs and examples first. Like, 
do you want to color specific electrons? Maybe this is enough:

\definesymbol[electronB][\m{\red \symbol[electronb]}]
\definesymbol[electronD][\m{\blue\symbol[electrond]}]

\electrons{uddBbuDd}

Hans


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

Also, as per the images in the StackExchange question, try adding this to the 
previous example:

%% start %%
Nitrogen: \vbox to \lineheight{\placeontopofeachother{\electrons{b}}{\tfx 1s}}
          \vbox to \lineheight{\placeontopofeachother{\electrons{b}}{\tfx 2s}}
          \vbox to \lineheight{\placeontopofeachother{\electrons{uuu}}{\tfx 2p}}
%% end %%

As Hans says, a parser is relatively easy, so the above can be made much less 
verbose if the layout is suitable. I think the message is: you don’t need to 
blindly copy \subshells if there is something easier to enter with less chance 
of error.

Good! So the next step now is:

\starttexdefinition protected electrons#1#2
    \dontleavehmode
    \ifparameter#2\or
      \vbox to \lineheight
      \bgroup % 1
      \placeontopofeachother
      \bgroup % 2
    \fi
    \dontleavehmode
    \doloopovermatch {.} {#1} {
        \inframed
          [width=\lineheight,
           height=\lineheight]
          {\symbol[electron##1]}
        \hskip-\linewidth
    }
    \ifparameter#2\or
      \egroup % 2
      \bgroup % 3
         \tfx
         \setstrut
         \strut
         #2
      \egroup % 3
      \egroup % 1
    \fi
    \unskip
\stoptexdefinition

Nitrogen: \electrons{b}{1s} \electrons{b}{2s} \electrons{uuu}{2p}

which is still relative simple.

Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to