Based on the following matlab:
% Based on Eqn 11.10 in H&Z ("Symmetric Epipolar Distance")
syms f1 f2 f3 f4 f5 f6 real
syms r s real
syms x y X Y real
% row 3 is parameterised
f7 = r*f1 + s*f4;
f8 = r*f2 + s*f5;
f9 = r*f3 + s*f6;
% build F
F = [f1 f2 f3; f4 f5 f6; f7 f8 f9];
% the symmetric epipolar distance and its analytic jacobian
Fx = F*[x y 1]';
FtX = F'*[X Y 1]';
XFx = [X Y 1] * F * [x y 1]';
d = XFx^2 * (( 1 / (Fx(1)^2 + Fx(2)^2)) + (1 / (FtX(1)^2 + FtX(2)^2)));
J = jacobian(d, [f1 f2 f3 f4 f5 f6 r s]);
% generate code
ccode(d, 'file', 'ccode/f12_epi_value.c')
ccode(J, 'file', 'ccode/f12_epi_jac.c')