function [] = LatexCodePolynomial(P,indeterminate,fileID)

%

degree = length(P) - 1;
nonzeros = find(P);
n_terms = length(nonzeros);
degrees = degree:(-1):0;

for i = 1:length(nonzeros)
    if (i == 1) && (P(nonzeros(i)) < 0)
        fprintf(fileID,'-');
    end
    fprintf(fileID,'%f',abs(P(nonzeros(i))));
    if degrees(nonzeros(i)) > 0
        fprintf(fileID,'%c',indeterminate);
        if degrees(nonzeros(i)) > 1
            fprintf(fileID,'^{%d}',degrees(nonzeros(i)));
        end
        if i < n_terms
            if P(nonzeros(i + 1)) > 0
                fprintf(fileID,' + ');
            else
                fprintf(fileID,' - ');
            end
        end
    end
end

end