Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

So, at school (outside the US) our teacher has given us this type of chemical notation:

notation

Where Ar is the relative atomic mass, Z atomic number, p protons, n neutrons. Example:

enter image description here

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}
share|improve this question
    
The only difficulty there is to put a prescript (\prescript from mathtools package, for instance, would work), and to draw the circle around an element (tikz package would do). There are lots of answers here in this site for doing so. However, may be you want an easy way to type that automatically… perhaps adding more info to the question would help. What input would you expect? A minimal compilable example would be great to invite us to help. –  Manuel Jul 18 at 10:59
2  
Welcome to TeX.SX! I can't find any question in your post. This is not a "do it for me" homepage. Where are you having problems, what have you tried. Where is your example code? –  LaRiFaRi Jul 18 at 10:59
    
Welcome to TeX.SX! Have you tried looking at ctan.org/topic/chemistry ? –  Andrew Swann Jul 18 at 11:01
2  
@user2563892 : if three comments ask you to provide a MWE (an example code), I think you should interpret it as there is a need for that, at least to show us your good will to solve your problem. We won't solve it for you, you know, just provide some hints and directions for further studies. –  Clément Jul 18 at 11:32
1  
For the nuclides see Chemistry package for typesetting nuclide. Also maybe interesting: the bohr provides \atomicnumber{<element>} (e.g. \atomicnumber{F} gives 9) –  cgnieder Jul 18 at 13:52

2 Answers 2

up vote 4 down vote accepted

An answer to the edited question: \atomicnumer 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 element F this is \@bohr@atom@number@f, for Ne 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

\lowercase{\the\numexpr#2-\csname @bohr@atom@number@#1\endcsname\relax}

or

\lowercase{\the\numexpr#2-\@nameuse{@bohr@atom@number@#1}\relax}

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 with anchor=base as option to the node.

\documentclass[a4paper]{article}
\usepackage{chemformula}% the package that provides `\ch` and which is loaded by `chemmacros'
\usepackage{bohr}
\usepackage{tikz}

\newcommand*\mychemistry[2]{%
  \ch{^{#2}_{\atomicnumber{#1}}#1}
  \tikz[baseline]{
    \node[anchor=base,shape=circle,draw,inner sep=2pt]
    {+\atomicnumber{#1}};
  }
  (%
    \atomicnumber{#1} p,
    \lowercase{\the\numexpr#2-\csname @bohr@atom@number@#1\endcsname\relax}
      n%
  )%
}
\begin{document}
\mychemistry{O}{18}
\end{document}

enter image description here

BTW: if you use chemmacros already you can also easily output protons as p+ and neutrons as n0:

\documentclass[a4paper]{article}
\usepackage{chemmacros}
\usepackage{bohr}
\usepackage{tikz}

\newcommand*\mychemistry[2]{%
  \ch{^{#2}_{\atomicnumber{#1}}#1}
  \tikz[baseline]{
    \node[anchor=base,shape=circle,draw,inner sep=2pt]
    {+\atomicnumber{#1}};
  }
  (%
    \atomicnumber{#1} \prt, % <<<<<<<<<
    \lowercase{\the\numexpr#2-\csname @bohr@atom@number@#1\endcsname\relax}
      \ntr % <<<<<<<<<
  )%
}
\begin{document}
\mychemistry{O}{18}
\end{document}

enter image description here

\prt actually just is the equivalent of \chcpd{p+} and \ntr is \chcpd{n^0} so chemmacros isn't really needed and chemformula would suffice.

share|improve this answer
    
Thank you very much, I was a little angry yesterday, but learning is always help. –  user2563892 Jul 19 at 5:47
    
Also, why do you put percent signs, aren't they comments? –  user2563892 Jul 19 at 5:49
    
Ends of lines are treated like spaces. If I don't want them to cause spurious spaces in the result I need to hide them by commenting them out. There's a question about this somewhere on this site... –  cgnieder Jul 19 at 7:13
    
    
@user2563892 I added some explanations to my answer –  cgnieder Jul 19 at 15:24

Is that what you want? I define a \chemelt command, with a very simple syntax: enter the comma-separated list of the element symbol, the atomic number and the atomic mass (in that order). It requires loading pstricks (for the circle box), with pdfoption to compile with pdfLaTeX, xparse (for the simple syntax) and mathtools (for the prescript command).

    \documentclass[a4paper,12pt, pdf]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc} %
    \usepackage{lmodern} 

    \usepackage{pst-node}
    \newcounter{neutron}
    \usepackage{mathtools}
    \usepackage{xparse}

    \DeclareDocumentCommand{\chemelt}{>{\SplitArgument{2}{,}}m}
    {\chemeltaux#1}
    \NewDocumentCommand{\chemeltaux}{mmm}{\setcounter{neutron}{\numexpr#3-#2\relax}\def\C{\pscirclebox{+8}} \ensuremath{\mathrm{\prescript{#3}{#2}#1}}\raisebox{-0.25\height}{\scriptsize\pscirclebox[framesep = 1pt, linewidth = 0.6pt]{+#2} (#2p,\theneutron n)}}

    \begin{document}

    \chemelt{O, 8,16}\\

    \chemelt{F, 9,19}

    \end{document} 

enter image description here

share|improve this answer
    
In fact, op told in a (moderately polite) comment that he already found a solution. –  Clément Jul 18 at 13:38
1  
Thank you very much for the time and work, but as Clement already mentioned, I've found a solution. Again, thanks, at least someone decided to help an absolute noob. :) –  user2563892 Jul 18 at 13:47
    
What is the \def\C{\pscirclebox{+8}} there for? –  cgnieder Jul 18 at 17:44
    
@cgnieder: For nothing. It's a remnant of a first attempt. Thanks for pointing it. I cleaned the code. –  Bernard Jul 18 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.