Graphics, Figures & TablesPST/PSTricks not working at all

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
adrienm
Posts: 1
Joined: Mon Sep 14, 2020 10:19 am

PST/PSTricks not working at all

Post by adrienm »

Hi !

I'm using MiKTeX compiler and Visual Studio Code as my editor. I tried to plot a function using PSTricks but I always get fatal errors even when copying the exact same code as written on my manual book (LaTeX for teachers, Ellipses). So I create a empty document and add some code found on the web ([url="https://tug.org/PSTricks/pst-plot/Examples-exa/fixPoint0.pdf"]this pdf[/url]) to try understand what's going wrong but it fails too. Here's the code I use from the pdf linked before :

Code: Select all

\documentclass[11pt]{article}

% Packages
\usepackage[utf8]{inputenc}    % support for accents
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}   % doc language
\usepackage{lmodern}
\usepackage[a4paper]{geometry} % marges
\usepackage{amssymb}
\usepackage{amsmath}           % Text into equation
\usepackage{pstricks-add}

\begin{document}

\psset{unit=2cm}
\begin{pspicture}(-2.5,-1.5)(2.5,2.5)
    \psaxes{->}(0,0)(-2.5,-1.5)(2.5,2.5)
    \psplot[linewidth=1.5pt,algebraic]{-2.5}{+2.5}{(2*x+4)/(2+x^2)}
    \psline[linestyle=dashed](-1.5,-1.5)(2.5,2.5)
    \def\function{ xVal dup add 4 add xVal dup mul 2 add div }%
    \pstVerb{ /xVal -1 def }% start value
    \multido{\nA=0+1}{10}{%
        \psline[linestyle=dotted](! xVal 0 )(! xVal xVal)
        \psline[linecolor=red](! xVal xVal )(! xVal \function )
        \psline[linecolor=red](! xVal \function )(! \function\space dup)
        \pstVerb{ /xVal \function\space def}
    }
\end{pspicture}

\end{document}
On the \psplot, \psline and \def\function commands I get the following errors :

Code: Select all

Undefined control sequence.
\c@lor@to@ps ->\PSTricks 
Undefined control sequence.
\XC@usec@lor ...string \color@ #1#2\endcsname \@@
Every other example of PST code I use gives me the same errors. I don't understand what's going wrong and why it works for everyone and not me... Can you help me please !
Thanks !

PS : When I delete everything in the pspicture environment except from the \psaxes line, I got something strange : numbers are displayed but no line nor arrow at all !

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

PST/PSTricks not working at all

Post by Johannes_B »

You have to use LaTeX in dvi mode, or use XeLaTeX.

You cannot use pdfLaTeX to generate a pdf directly if you want to work with pstricks.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply