TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm relative new using PStricks and I don't know exactly how to draw a tangens of y=f(x) at a given point of the curve. I know, by simple mathematics that can be done by constructing the associate differential triangle at the point, [(x,y), dx, dy]. But, I think that PStricks should have a "easy-way" to do it automatically. Please, can you help me?

share|improve this question
Welcome! Do you mean tangent? – Marco Daniel Aug 18 '12 at 14:58
yes, that comes from Deutsch – Miguel Toledo González Aug 18 '12 at 15:03
up vote 13 down vote accepted

Pstricks consist of several packages. The basic on is pstricks.

A complete list of all available packages with a small description is given at tug.org/PStricks

To plot a function the package pst-plot is recommended. It provides the command \psplot.

Plotting a tangent of given function can easily be done be the command \psplotTangent which is provided by the package pstricks-add.

Here an example of the documentation:


\def\F{x RadtoDeg dup dup cos exch 2 mul cos add exch 3 mul cos add}
\def\Fp{x RadtoDeg dup dup sin exch 2 mul sin 2 mul add exch 3 mul sin 3 mul add neg}
\psset{linecolor=red, arrows=<->, arrowscale=2}
\psset{linecolor=magenta, arrows=<->, arrowscale=2}%
\multido{\n=0+1}{8}{\psplotTangent[linecolor=blue, Derive=\Fp]{\n}{1}{\F}}


enter image description here

share|improve this answer
Thanks a lot! That is perfect! – Miguel Toledo González Aug 18 '12 at 15:05
@MiguelToledoGonzález don't forget to accept Marco Daniel's answer (click on the green checkmark to the left). – Gonzalo Medina Aug 18 '12 at 15:11

My answer below adds the infix version to Marco Daniel's answer and provides some easy-to-customize settings as a template.








    ticksize=0 -4pt,

% the same as \sum_{i=1}^{3} \frac{\cos(i x)}{i},
% the third arg represent increment step,
\def\f{Sum(i,1,1,3,cos(i*x)/i)}% is the same as \def\f{cos(x)+cos(2*x)/2+cos(3*x)/3}

% the first derivative of \f


    \pstVerb{/xxx {Pi 4 div} def}%
    \psplotTangent[linecolor=ForestGreen]{xxx}{3}{\f}% tangent line
    \psplotTangent[linecolor=Maroon,Derive={-1/\fp}]{xxx}{3}{\f}% normal line


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.