The CustomFactor, originally created by Fan Jiang, has been available in GTSAM for a while: if you have a residual in mind not available in the “standard” GTSAM factors, CustomFactor is often the fastest way to build a factor without writing an entire new factor class.