I am trying to write a document for my students to practice on quadratic functions. Using a form, the student can enter the coefficients of the quadratic functions and is then given the discriminant (and later the roots of the function).

I think it would be great if the graph of the function could be traced on the pdf. Is there a way to do this? How can the form transfer values to the tikzpicture environment?

Here is my MWE:





function doCalculation()
  {var disc=0.0 + (this.getField("valb").value)*(this.getField("valb").value)

function doDrawing()




Please enter the coefficients of the quadratic function $f(x)=ax^2+bx+c$

\vskip 5mm

\TextField[name=vala,width=2em, bordercolor={0.650 .790 .94}]{Coefficient a: }
\TextField[name=valb,width=2em, bordercolor={0.650 .790 .94}]{Coefficient b:}
\TextField[name=valc,width=2em, bordercolor={0.650 .790 .94}]{Coefficient c:}

\vskip 5mm

\PushButton[name=start,onclick={doCalculation();},bordercolor={0.650 .790 .94}{Compute!} 

\vskip 5mm

Discriminant: \TextField[name=valdisc,width=4em,readonly=true]{}

\vskip 10mm

\PushButton[name=start,onclick={doDrawing();},bordercolor={0.650 .790 .94}]{Draw!} 

\vskip 5mm

\begin{axis}[title=Parabola, axis lines=left, xlabel={$x$},ylabel={$y$},ymin=-3, ymax=3,minor y tick num=1,]
\addplot[blue, domain=-\coefb/(2*\coefa)-3:-\coefb/(2*\coefa)+3, samples=1000]



I am trying to tell the functions \coefa, \coefb and \coefc to take the values given by the user in the form. An alternative version not using tikz is also welcomed.

Is it possible to do it? I am afraid it is not possible since it may mean re-compiling the tex file in order to get the picture. But, for the computation of discriminant, the result "magically" appears without any compilation. I am totally ignorant on how forms work in Latex...

Edit: As explained in the comments, the answer will depend on the viewer. You can assume the viewer is Acrobat Reader, since it is free and ubiquitous. If there is a solution that works with another viewer, I am also interested in it.

  • 3
    You aren't using TeX to do the calculation, though. You are using the PDF viewer. (And it will work in some PDF viewers and fail to work in others for just this reason. So make sure your students know they need to use an appropriate viewer.) Unless the viewer can also plot functions on-the-fly, you are not going to be able to do this with having access to something else to do the plotting (TeX or whatever). That is, you can't set up in advance for the PDF viewer to have access to the facilities offered by the compiler unless the compiler will be available. Sorry, I'm not explaining well. – cfr Oct 8 '14 at 2:39
  • @cfr: thank for the explanation on how forms work. It makes things clear to me. Do you know a free reader that can plot on-the-fly? I don't understand the second part. Is there a way to make the compiler available? – Taladris Oct 8 '14 at 2:53
  • 3
    I think as you have put it, it is not possible to update the plot itself since there is no pgfplots engine is present at the time of recomputation. It compiles only once. But if you are feeling adventurous there is the clickable library that uses insdljs too. You can delve into that code to make the curve also a dynamic object. – percusse Oct 8 '14 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.