1

So I'm trying to create my own style package for drawing simple lewis structures. I want to do a \newcommand type of thing that has the option for me to not only put in the atoms, but also an option for bonds as well (<, =, -, or >). How can I accomplish this? I tried just replacing the bond designation symbol by {#4} but it did not work of course. Please let me know.

\documentclass[tikz,border=3mm]{standalone}

\usepackage{chemfig,chemmacros}
\chemsetup{modules=all}

\newcommand{\Linear}[4]{\chemfig{{#1}
            ( {#4}[:180] {#2})
            ( -[:0] {#3})}}

\begin{document}

\chemfig{C
    ( =[:180] O)
    ( <[:0] O)}

\Linear{C}{O}{O}{=}

\end{document}

1 Answer 1

0

You just need to remove some braces. In more detail, you put all the arguments #1, #2, #3 and #4 into braces, but you should not do that.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{chemfig,chemmacros}
\chemsetup{modules=all}

\newcommand{\Linear}[4]{\chemfig{#1
            ( #4[:180] #2)
            ( -[:0] #3)}}

\begin{document}

\chemfig{C
    ( =[:180] O)
    ( <[:0] O)}

\Linear{C}{O}{O}{=}

\end{document}

enter image description here

1
  • It's perfect! thank you!
    – Dave124
    Mar 7, 2020 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .