public static string GetTeXFactorForm(RationalPolynomial p) { var q = new RationalPolynomial(p.Coefficients); string answer = string.Empty; var roots = GetRationalRoots(q.MakePolynomial()); foreach (var root in roots) { while (q.At(root) == 0) { answer += "\\left( x" + (-root).ToSignedTeXString() + "\\right)"; q.DivideBySolution(root); } } answer += (q.Degree == 0 && q[0] == 1) ? string.Empty : "\\left( " + q.ToString() + "\\right)"; return(answer); }