I am curious if it is possible to evaluate an integral using the xfp package using tex language?

\fpeval{\int_{-1}^{1}\frac{1}{\sqrt{1 - x^2}}dx}}

Just throwing out the idea. I know I can easily do this by python/Matlab/mathematica/calculator/hand but I love LaTeX.

  • 1
    No, xfp doesn't do that. You have to solve the integral analytically yourself, then you can feed xfp the remaining arithmetics for it to give you the final value Apr 15, 2021 at 20:11
  • 1
    fp eval just evaluates a single floating point expressions but you also have loops and conditionals so you could implement a numerical approximation to the interval Apr 15, 2021 at 20:11
  • Awesome! Thanks for the quick answers. Again, this is all hypothetical speaking. Apr 15, 2021 at 20:14

2 Answers 2


Modulo coding errors this is a 6 step simpsons rule numeric approximation (not coded very efficiently as the end points of each step are evaluated twice)

l3fp could get a more accurate result than this if coded more carefully, but this is enough for this morning:-)

\def\fx#1{(1/(sqrt(1 - (#1)^2)))}
\def\simp#1#2#3{((((#2)-(#1))/6)*(#3{#1}+ 4*#3{(#1+(#2))/2} + #3{#2}))}



Which isn't quite the same as this:

enter image description here


Here is a solution based on the pst-ode package. The integrand is symmetrical about x=0, so integration can be started at 0 and the result is multiplied by 2.

enter image description here

Typeset with pdflatex --shell-escape:


%%%%%%%%%%%%%%%%%%%%%%% solve ODE in auxiliary document %%%%%%%%%%%%%%%%%%%%%%%%

% arguments:
%   algebraicAll --> all arguments in algebraic notation
%   saveData     --> also write result into file `result.dat'
%   `result'     --> PostScript variable that takes result
%   2*y[0]       --> output format in `result' and `result.dat'
%   0, 1         --> integration interval t_0, t_e
%   2            --> number of saved output points t_0, t_e
%   0            --> initial value
%   1/sqrt(...)  --> right-hand side of ODE 
  1 / sqrt(1-t^2)
dummy text

\immediate\write18{latex solve}
\immediate\write18{dvips solve}
\immediate\write18{ps2pdf -dNOSAFER solve.ps}

\immediate\read\resfile to \dummy  % read and throw away initial value
\immediate\read\resfile to \result % read definite integral value


  \int_{-1}^{1} \frac{1}{\sqrt{1 - x^2}} dx \approx \result


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .