Many biochemical molecules, such as nucleic acids for example, are composed by nature in a hierarchical fashion from a limited number of building blocks. It would be nice to replicate this approach when typesetting these molecules. In the case of DNA and RNA, a natural approach would be:
- Define separate structures for ribose, phosphate and the bases (A,C,G,T,U)
- Derive deoxyribose from ribose
- Create nucleosides by combining ribose or deoxyribose with each of the bases
- Write DNA and RNA molecules as alternations of nucleosides and phosphate.
The chemfig package provides a \definesubmol command that allows for the definition of sub-molecules, which can then be substituted into other molecules. However, the package does not provide a built-in mechanism for making the results of such substitutions available as new sub-molecules. So, the question is how to define a command with the following behavior:
% "\derivesubmol" defines the new #1 submol, obtained by replacing all the
% occurrences of "#3" by "#4" in the code of #2 submol
% arguments: #1 = new submol name, #2 = old submol name,
% #3 = old substring, #4 = new substring
\newcommand*\derivesubmol[4]{% ...
This description is taken from the code that the package author of chemfig has provided to me by email. An example of his code in action is provided in the answer that I supply below.
To indicate that this question is, indeed, a question, let me add: ???
