So, at school (outside the US) our teacher has given us this type of chemical notation:
Where Ar is the relative atomic mass, Z atomic number, p protons, n neutrons.
Example:
UPDATE: I want to make a macro out of it, but there's a porblem with \atomicnumber, I think it returns a string instead of an integer or something:
\documentclass[a4paper]{article}
\usepackage{chemmacros}
\usepackage{bohr}
\usepackage{tikz}
\newcounter{neutron}
\newcommand{\mychemistry}[2]{\setcounter{neutron}{\numexpr#2-\atomicnumber{#1}\relax}\ch{^{#2}\atomicnumber{#1}#1}\tikz[baseline=(char.base)]{ \node[shape=circle,draw,inner sep=2pt] (char) {+\atomicnumber{#1}};}(\atomicnumber{#1} p,\theneutron n)}
\begin{document}
\mychemistry{O}{18}
\end{document}
Best Answer
Edit 2015-12-14 – adapt to use
elements
packageThe idea is the same as in the original answer, see below. The
bohr
package doesn't provide\atomicnumber
any more. It is now provided by theelements
package. The latter also provides\saveatomicnumber<cs>{<element>}
which makes the macro a little bit easier:and then
for the number of neutrons.
Earlier answer using the
bohr
packageAn answer to the edited question:
\atomicnumber
is not expandable and as a consequence not usable in\numexpr ... \relax
. However, if you're certain that you only input the element symbol and never the element name you can use the internal command. For the elementF
this is\@bohr@atom@number@f
, forNe
it's\@bohr@atom@number@ne
and so on.In order to use it with uppercase atomic symbols as input you need to
\lowercase{...}
the input.\lowercase
again is not expandable but you can simply surround the\setcounter
part with it. Actually, the counter isn't even needed since it is only used to determine the number of neutrons. It is possible to use\numexpr
directly by preceding it with\the
. In order to build the needed macro name we can use the primitives\csname...\endcsname
or LaTeX's wrapper\@nameuse{...}
, both of which are expandable. In the command this would then be something like\csname @bohr@atom@number@#1\endcsname
or\@nameuse{@bohr@atom@number@#1}
.Putting this together you can get the number of neutrons with
or
Adapting you example, I added indentation and comment chars where needed but I also left a space between the different parts since it looked more readable to me this way. I also omitted to name the
\node
since alignment with the baseline can also be achieved withanchor=base
as option to the node.BTW: if you use
chemmacros
already you can also easily output protons as p+ and neutrons as n0:\prt
actually just is the equivalent of\chcpd{p+}
and\ntr
is\chcpd{n^0}
sochemmacros
isn't really needed andchemformula
would suffice.