1

Why does this code produce an error and how to fix it?

By the way, I use Texmaker in MikTeX.

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\pagestyle{empty}
\usepackage{pst-func}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-2.,-1.5)(2.,2.5)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=0.5,Dy=0.5,ticksize=-2pt 0,subticks=2]{<->}(0,0)(-2.,-1.5)(2.,2.5)
\psplotImp[linewidth=0.4pt](-3.0,-3.0)(3.0,3.0){0.01388742374854553+1.9858243449267068*y^2+3.0*y^3-2.0*y^4-0.0034236125287306907*x^1-0.336756945862064*x^1*y^2-2.0*x^2-2.0*x^2*y^2}
\end{pspicture*}
\end{document}
  • I have no error message. Is this the exact code which produces your error message? – Bernard Dec 20 '16 at 12:10
  • Which error do you get? – Torbjørn T. Dec 20 '16 at 12:16
  • @Torbjørn This is the error: ! Undefined control sequence. \XC@usec@lor ...string \color@ #1#2\endcsname \@@ \fi \space l.9 \psplot [linewidth=0.4pt](-3.0,-3.0)(3.0,3.0){0.01388742374854553+1.9858... The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., '\hobx'), type 'I' and the correct spelling (e.g., 'I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined. – teed Dec 20 '16 at 12:36
  • @Bernard Any idea about the error (see above)? Teokan: Looks like that has something to do with xcolor (a color package, loaded by pstricks), but I don't know why you would get the error. Can you compile \listfiles\documentclass{article} \usepackage{pstricks-add} \pagestyle{empty} \usepackage{pst-func} \begin{document} abc \end{document}, and then add the .log file that is produced to your question? (Click the edit link right above these comments to edit your post.) – Torbjørn T. Dec 20 '16 at 12:41
  • 1
    pstricks needs latex/dvips (usually) – David Carlisle Dec 20 '16 at 12:51
2

With TeXMaker, you can go to the Options -> Configure TeXmaker menu, then

  • either add \usepackage{auto-pst-pdf} to your preamble (after pstricks related packages), and --enable-write18 to the parameters for pdflatex, as in this image:

enter image description here

  • or change the default for Quick build to Latex+dvips+ps2pdf+View Pdf or XeLaTeX+ViewPDF:

enter image description here

| improve this answer | |
1

Your code looks like an exported one from another GUI. Without such a GUI it is much more easier to create what you need:

\documentclass[10pt]{article}
\usepackage{pst-func}
\begin{document}
\psset{algebraic,unit=2}
\begin{pspicture*}(-2.,-1.5)(2.,2.5)
\psaxes[labelFontSize=\scriptstyle,Dx=0.5,
  Dy=0.5,ticksize=-2pt 0,subticks=2]{<->}(0,0)(-2.,-1.5)(2.,2.5)
\psplotImp[linewidth=1pt,stepFactor=0.2,linecolor=red](-3.0,-3.0)(3.0,3.0)%
   {0.0138+1.9858*y^2+3.0*y^3-2.0*y^4-0.0034236*x-0.3367*x*y^2-2.0*x^2-2.0*x^2*y^2}
\end{pspicture*}
\end{document}

Run it with xelatex or latex->dvips->ps2pdf or with loading package auto-pst-pdf and then also with `pdflatex

enter image description here

| improve this answer | |
0

The error message you show in comments is not the first one. the first error reported is

! Undefined control sequence.
<recently read> \c@lor@to@ps 

Unfortunately pstricks still doesn't catch that and give a more helpful error message but the reason is that pdflatex has been used. pstricks needs a PostScript interpreter and so you have to use latex and dvips rather than pdflatex. There are packages to allow limited use with pdflatex, but mostly that works by running (just) the pspicture as a separate document with latex and then including the generated pdf into the main pdflatex processed document.

| improve this answer | |
  • How can I do that? – teed Dec 20 '16 at 12:58
  • @TeokanDuranDemircan instead of typing pdflatex file.tex you need latex file.tex followed by dvpd file.dvi to get postscript then finally ps2pdf file.ps to make PDF That is the sequence of commands, your editor probably has that in a menu somewhere but I do not know texmaker. – David Carlisle Dec 20 '16 at 13:00

Your Answer

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

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