# chemfig: \definesubmol with a variable

Using the chemfig package, I'd like to define a structural element with a variable part. I haven't seen variables being used with \definesubmol. And \newcommand seems to work only with very simple substitutions:

\documentclass{standalone}
\usepackage{chemfig}
\begin{document}
\definesubmol\A{(-[,-0.3,,,draw=none]1)}
\definesubmol\B{(-[,-0.3,,,draw=none]2)}
\definesubmol\C{(-[,-0.3,,,draw=none]3)}
\definesubmol\D{(-[,-0.3,,,draw=none]4)}

\newcommand\BLUE[1]{\textcolor{blue}{#1}}
\newcommand\X[1]{(-[,-0.3,,,draw=none]{#1})}

\chemfig{*6((!\A)-(!\B)-(!\C)-\BLUE{N}(!\D)---)}
\chemfig{*6((!\A)-(!\B)-(!\C)-\BLUE{N}(!\D)-\X{5}--)}
\end{document}


Compiled with xelatex:

In the above example, how could I define a better command \X ?

Right now, \definesubmol defines macro-submol without argument. The future version 1.4, available here and officialy released soon, allows arguments.

\documentclass{article}
\usepackage{chemfig}
\begin{document}
Version of chemfig: \CFver

With submol-macro:
\definesubmol\X1{-[,-0.3,,,draw=none]#1}
\newcommand*\BLUE[1]{\textcolor{blue}{#1}}
\chemfig{*6((!\X A)-(!\X B)-(!\X C)-\BLUE{N}(!\X D)---)}% or \chemfig{*6((!\X{A})-(!\X{B})-(!\X{C})-\BLUE{N}(!\X{D})---)}

With submol-name:
\definesubmol X1{-[,-0.3,,,draw=none]#1}
\chemfig{*6((!XA)-(!XB)-(!XC)-\BLUE{N}(!XD)---)}% or \chemfig{*6((!X{A})-(!X{B})-(!X{C})-\BLUE{N}(!X{D})---)}
\end{document}


Well, as \definesubmol does not allow for additional arguments, you need to solve it differently. For example like this:

\documentclass{standalone}
\usepackage{chemfig}

\begin{document}
\definesubmol\A{(-[,-0.3,,,draw=none]1)}
\definesubmol\B{(-[,-0.3,,,draw=none]2)}
\definesubmol\C{(-[,-0.3,,,draw=none]3)}
\definesubmol\D{(-[,-0.3,,,draw=none]4)}

\definesubmol\X{-[,-0.3,,,draw=none]}

\newcommand\BLUE[1]{\textcolor{blue}{#1}}

\chemfig{*6((!\A)-(!\B)-(!\C)-\BLUE{N}(!\D)---)}
\chemfig{*6((!\A)-(!\B)-(!\C)-\BLUE{N}(!\D)-(!\X5)--)}

\end{document}


But I guess, this approach is not easily applied in every case ...