Build color ramp out of math nodes? I want to use color ramps or RGB curve effects in my node groups. This runs into the problem that the only sockets these nodes have is their input image and factor. This means if I have them in a group, I cannot control the actual ramp/curve stops with inputs from outside the group.

Is it possible to build a custom math node group that would do the same thing as a color ramp or RGB curve, but would allow me access to an equivalent of stops?
Unfortunately there is no way to create a group node exactly like the Color Ramp, where you can add and remove color swatches at will.  To get around this I have created a node with two movable swatches, you can then combine multiple of these nodes together to have the functionality of multiple swatches.



The theory:

The two input colors are plugged directly into a Mix RGB node.  The two Pos inputs need to be sent through a function and plugged into the mix factor.  The position of the first swatch needs to be mapped to $0$ to get just the first color out of the mix node.  The position of the second swatch needs to be mapped to $1$ to get just the second color out of the mix node.



The math:

Here's a graph to visualize what we are trying to do, on the x-axis is the input factor of the color ramp, on the y-axis is the desired output, $a$ and $b$ are the positions of the two swatches.



With some simple algebra we can find the equation of the line to be:

$$
y = \frac{1}{b-a}x + \frac{a}{a-b}
$$

The math nodes below are simply replicating this equation.  The final Add node also has Clamp checked to clamp the output to the interval $[0,1]$, which is what the mix node accepts.