On 10/30/2024 9:35 PM, Wolfgang Schuster wrote:

\starttexdefinition protected tolerant electrons #=#=

ok, can you check the attached 'module'

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
-----------------------------------------------------------------
%D \module
%D   [       file=m-electrons,
%D        version=2024.10.30,
%D          title=\CONTEXT\ Extra Modules,
%D       subtitle=messing with electrons,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={\CONTEXT\ Development Team}]

% This is a follow up on mails to the list by Jorge and Bruce.

\startmodule [m-electrons]

\unprotect

\installcorenamespace {electrons}

\installcommandhandler \??electrons {electrons} \??electrons

\setupelectrons
  [\c!textstyle=\tfxx,
   \c!distance=.5\strutdp,
   \c!depth=.5\strutdp]

\starttexdefinition tolerant protected electrons[#1]#*#:#=#=
    \dontleavehmode
    \begingroup
    \ifparameter#2\or
      \cdef\currentelectrons{#1}%
    \fi
    \setbox\scratchboxone\hpack\bgroup
      \doloopovermatch {.} {#2} {
        \framed
          [\c!strut=\v!no,
           \c!width=\lineheight,
           \c!height=\lineheight]
          {\useelectronsstyleandcolor\c!style\c!color
           \symbol[electron##1]}
        \hskip-\linewidth
      }
      \unskip
    \egroup
    \ifparameter#3\or
      \setbox\scratchboxtwo\hbox to \wd\scratchboxone\bgroup
         \useelectronsstyleandcolor\c!textstyle\c!textcolor
         \setstrut\strut
         \hss#3\hss
      \egroup
      \setbox\scratchboxone\hpack \bgroup
        \box\scratchboxone
        \hkern-\wd\scratchboxtwo
        \boxymove\scratchboxtwo\dimexpr
           -\htdp\scratchboxtwo
           +\electronsparameter\c!distance
        \relax
        \box\scratchboxtwo
       \egroup
    \fi
    \boxymove\scratchboxone-\electronsparameter\c!depth
    \box\scratchboxone
    \endgroup
\stoptexdefinition

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

\definesymbol[electronB][\m{\darkred \symbol[electronb]}]
\definesymbol[electronD][\m{\darkblue\symbol[electrond]}]

\stopmodule

\protect

\continueifinputfile{m-electrons.mkxl}

\usemodule[scite]

\starttext

\startTEXpage[offset=1cm,width=17cm]

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

Nitrogen: \electrons{b}{} \electrons{B}{} \electrons{uDu}{}

\defineelectrons [nitrogen]
\setupelectrons  [nitrogen] [color=darkgreen]

Nitrogen:
    \electrons[nitrogen]{b}{}
    \electrons[nitrogen]{B}{}
    \electrons[nitrogen]{uDu}{2p}
\stopbuffer

\typebuffer[b][option=TEX]

\getbuffer[b]

\stopTEXpage

\setuplayout[tight]

\typefile[option=TEX]{m-electrons.mkxl}

\stoptext
___________________________________________________________________________________
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