| 1 |
\ifdefined\CFname\else |
| 2 |
\errmessage{Chemfig is not loaded, lewis cannot work}% |
| 3 |
\expandafter\endinput |
| 4 |
\fi |
| 5 |
|
| 6 |
\csname lewisloadonce\endcsname |
| 7 |
\let\lewisloadonce\endinput |
| 8 |
|
| 9 |
\begingroup |
| 10 |
\def\X#1{\catcode\number`#1=\number\catcode`#1\relax} |
| 11 |
\xdef\CFrestorecatcode{\X\[\X\]\X\:\X\(\X\)\X\,\X\-\X\=\X\~\X\!\X\?\X\<\X\>\X\;\X\*\X\|\X\@\X\ \X\_}% |
| 12 |
\endgroup |
| 13 |
|
| 14 |
\catcode`\[12 \catcode`\]12 \catcode`\:12 \catcode`\(12 |
| 15 |
\catcode`\)12 \catcode`\,12 \catcode`\-12 \catcode`\=12 |
| 16 |
\catcode`\~12 \catcode`\!12 \catcode`\?12 \catcode`\<12 |
| 17 |
\catcode`\>12 \catcode`\;12 \catcode`\*12 \catcode`\|12 |
| 18 |
\catcode`\@12 \catcode`\#6 \catcode`\ 10 \catcode`\_11 |
| 19 |
|
| 20 |
\newif\ifCF_lewisoverlay |
| 21 |
\newbox\CF_boxlewis |
| 22 |
|
| 23 |
\defKV[chemfig]{% |
| 24 |
lewis | width = \CF_defifempty\CF_lewiswidthdouble {#1}{0.3ex}, |
| 25 |
lewis sep = \CF_defifempty\CF_lewisoffset {#1}{0.4ex}, |
| 26 |
lewis length = \CF_defifempty\CF_lewislength {#1}{1.5ex}, |
| 27 |
lewis style = \def\CF_lewisstyle {#1}, |
| 28 |
lewis dist = \CF_defifempty\CF_lewisdist {#1}{0.3em}, |
| 29 |
lewis radius = \CF_defifempty\CF_lewisradius {#1}{0.15ex}, |
| 30 |
lewis diag coeff = \CF_defifempty\CF_lewisdiagcoeff {#1}{1} |
| 31 |
} |
| 32 |
\setKVdefault[chemfig]{% |
| 33 |
lewis | width = 0.3ex, |
| 34 |
lewis sep = 0.4ex, |
| 35 |
lewis length = 1.5ex, |
| 36 |
lewis style = {}, |
| 37 |
lewis dist = 0.3em, |
| 38 |
lewis radius = 0.15ex, |
| 39 |
lewis diag coeff = 1 |
| 40 |
} |
| 41 |
|
| 42 |
\def\Lewis{% |
| 43 |
\CF_lewisoverlayfalse |
| 44 |
\CF_testopt\CF_lewisa{}% |
| 45 |
} |
| 46 |
|
| 47 |
\def\lewis{% |
| 48 |
\CF_lewisoverlaytrue |
| 49 |
\CF_testopt\CF_lewisa{}% |
| 50 |
} |
| 51 |
|
| 52 |
\def\CF_lewisa[#1]{% |
| 53 |
\begingroup |
| 54 |
\CF_doifnotempty{#1}{\setchemfig{#1}}% |
| 55 |
\ifCF_lewisoverlay |
| 56 |
\CF_addtomacro\CF_lewisstyle{,overlay}% |
| 57 |
\fi |
| 58 |
\CF_lewisb |
| 59 |
} |
| 60 |
|
| 61 |
\def\CF_lewisb#1{% |
| 62 |
\CF_lewisc#1\_nil |
| 63 |
\endgroup |
| 64 |
} |
| 65 |
|
| 66 |
\def\CF_lewisc#1,#2\_nil{% |
| 67 |
\setbox\CF_boxlewis\hbox{\printatom{#2}}% mettre en dehors de tikzpicture (si \printatom ne passe pas en mode math) |
| 68 |
\CF_ifinsidetikz |
| 69 |
{\pgfinterruptpicture |
| 70 |
\let\CF_atendoflewis\endpgfinterruptpicture |
| 71 |
} |
| 72 |
{\let\CF_atendoflewis\relax |
| 73 |
}% |
| 74 |
\tikzpicture[every node/.style={anchor=base,inner sep=0pt,outer sep=0pt,minimum size=0pt},baseline]% |
| 75 |
\CF_makeother;\CF_makeother:% |
| 76 |
\node(CF_lewis@anchor){}; |
| 77 |
\def\CF_lewisremainpos{#1}% |
| 78 |
\let\CF_lewispreviouspos\empty |
| 79 |
\loop |
| 80 |
\unless\ifx\CF_lewisremainpos\empty |
| 81 |
\edef\CF_lewiscurrentpos{\expandafter\CF_firsttonil\CF_lewisremainpos\_nil}% |
| 82 |
\edef\CF_lewisremainpos{\expandafter\CF_gobarg\CF_lewisremainpos}% |
| 83 |
\pgfmathsetmacro\CF_lewisx{\wd\CF_boxlewis/2+\ifcase\CF_lewiscurrentpos\space1\or1\or0\or-1\or-1\or-1\or0\or1\fi*(\wd\CF_boxlewis/2)}% |
| 84 |
\pgfmathsetmacro\CF_lewisy{\ht\CF_boxlewis/2+\ifcase\CF_lewiscurrentpos\space0\or1\or1\or1\or0\or-1\or-1\or-1\fi*(\ht\CF_boxlewis/2\ifnum\CF_lewiscurrentpos>4 +\dp\CF_boxlewis\fi)}% |
| 85 |
\edef\CF_lewisxoffset{\ifcase\CF_lewiscurrentpos\space1\or0.70711\or0\or-0.70711\or-1\or-0.70711\or0\or0.70711\fi}% |
| 86 |
\edef\CF_lewisyoffset{\ifcase\CF_lewiscurrentpos\space0\or0.70711\or1\or0.70711\or0\or-0.70711\or-1\or-0.70711\fi}% |
| 87 |
\ifodd\CF_lewiscurrentpos\relax |
| 88 |
\pgfmathsetmacro\CF_lewiscurrentoffset{\CF_lewisoffset*\CF_lewisdiagcoeff}%% |
| 89 |
\else |
| 90 |
\let\CF_lewiscurrentoffset\CF_lewisoffset |
| 91 |
\fi |
| 92 |
\if.\expandafter\CF_firsttonil\CF_lewisremainpos\relax\_nil |
| 93 |
\edef\CF_lewisremainpos{\expandafter\CF_gobarg\CF_lewisremainpos}% |
| 94 |
\CF_expafter{\draw[fill,black,}{\CF_lewisstyle]}% |
| 95 |
(\CF_lewisx pt+\CF_lewisxoffset*\CF_lewiscurrentoffset,\CF_lewisy pt+\CF_lewisyoffset*\CF_lewiscurrentoffset)circle(\CF_lewisradius);% |
| 96 |
\else |
| 97 |
\if|\expandafter\CF_firsttonil\CF_lewisremainpos\relax\_nil |
| 98 |
\edef\CF_lewisremainpos{\expandafter\CF_gobarg\CF_lewisremainpos}% |
| 99 |
\pgfmathsetmacro\CF_lewisx{\CF_lewisx pt+\CF_lewisxoffset*\CF_lewiscurrentoffset}% |
| 100 |
\pgfmathsetmacro\CF_lewisy{\CF_lewisy pt+\CF_lewisyoffset*\CF_lewiscurrentoffset}% |
| 101 |
\CF_expafter{\draw[}\CF_lewisstyle]% |
| 102 |
(\CF_lewisx pt+\CF_lewislength*\CF_lewisyoffset/2 pt,\CF_lewisy-\CF_lewislength*\CF_lewisxoffset/2 pt)-- |
| 103 |
(\CF_lewisx pt+\CF_lewislength*\CF_lewisyoffset/2 pt+\CF_lewisxoffset*\CF_lewiswidthdouble,\CF_lewisy-\CF_lewislength*\CF_lewisxoffset/2 pt+\CF_lewisyoffset*\CF_lewiswidthdouble)-- |
| 104 |
(\CF_lewisx pt-\CF_lewislength*\CF_lewisyoffset/2 pt+\CF_lewisxoffset*\CF_lewiswidthdouble,\CF_lewisy+\CF_lewislength*\CF_lewisxoffset/2 pt+\CF_lewisyoffset*\CF_lewiswidthdouble)-- |
| 105 |
(\CF_lewisx pt-\CF_lewislength*\CF_lewisyoffset/2 pt,\CF_lewisy+\CF_lewislength*\CF_lewisxoffset/2 pt)--cycle;% |
| 106 |
\else |
| 107 |
\if:\expandafter\CF_firsttonil\CF_lewisremainpos\relax\_nil |
| 108 |
\edef\CF_lewisremainpos{\expandafter\CF_gobarg\CF_lewisremainpos}% |
| 109 |
\pgfmathsetmacro\CF_lewisx{\CF_lewisx pt+\CF_lewisxoffset*\CF_lewiscurrentoffset}% |
| 110 |
\pgfmathsetmacro\CF_lewisy{\CF_lewisy pt+\CF_lewisyoffset*\CF_lewiscurrentoffset}% |
| 111 |
\CF_expafter{\draw[fill,black,}{\CF_lewisstyle]}% |
| 112 |
(\CF_lewisx pt+\CF_lewisdist*\CF_lewisyoffset/2 pt,\CF_lewisy-\CF_lewisdist*\CF_lewisxoffset/2 pt)circle(\CF_lewisradius)% |
| 113 |
(\CF_lewisx pt-\CF_lewisdist*\CF_lewisyoffset/2 pt,\CF_lewisy+\CF_lewisdist*\CF_lewisxoffset/2 pt)circle(\CF_lewisradius);% |
| 114 |
\else |
| 115 |
\pgfmathsetmacro\CF_lewisx{\CF_lewisx pt+\CF_lewisxoffset*\CF_lewiscurrentoffset}% |
| 116 |
\pgfmathsetmacro\CF_lewisy{\CF_lewisy pt+\CF_lewisyoffset*\CF_lewiscurrentoffset}% |
| 117 |
\CF_expafter{\draw[}\CF_lewisstyle]% |
| 118 |
(\CF_lewisx pt+\CF_lewislength*\CF_lewisyoffset/2 pt,\CF_lewisy-\CF_lewislength*\CF_lewisxoffset/2 pt)--% |
| 119 |
(\CF_lewisx pt-\CF_lewislength*\CF_lewisyoffset/2 pt,\CF_lewisy+\CF_lewislength*\CF_lewisxoffset/2 pt);% |
| 120 |
\fi |
| 121 |
\fi |
| 122 |
\fi |
| 123 |
\repeat |
| 124 |
\node[anchor=base west]at(CF_lewis@anchor){\box\CF_boxlewis};% |
| 125 |
\endtikzpicture |
| 126 |
\CF_atendoflewis |
| 127 |
} |
| 128 |
\CFrestorecatcode |
| 129 |
\endinput |