I would like to write a script for doing my biochemistry homework that utilizes variable substitution. For example, I could create a base molecule using ChemFig with an X on it, then substitute that X for the appropriate group.
\documentclass[graphicx,longbibliography,notitlepage]{revtex4-1}
\usepackage{chemfig}
\newcommand{\X}{}
\newcommand{\propyl}{\chemfig{CH_3-[:30]-[:-30]\X}}
\begin{document}
%if input=propane:
\renewcommand{\X}{CH_3}
\propyl\\ %substitute 'CH_3' for X
%if input=propanol
\renewcommand{\X}{-[:30]OH}
\propyl %substitute '-[:30]OH' for X
\end{document}
Then, if the input was propane the 'X' would be replaced with 'CH_3', if the input was propanol, the X would be replaced with '-[:30]OH'. However, instead of making a new branch with the OH, it just displays the -[:30]OH
Is something like that possible with latex/chemfig? I looked at some variable substitution things on here, but didn't seem to be quite close enough to what I'm looking for. Sorry for not providing more code for it, but I don't even know if it's possible. If it is, if someone could point me in the right direction, that'd be great (don't need to write my code for me). Thanks!