2

This question already has an answer here:

I am new to PStricks. My miktek library has pstricks package installed.

As I ran this code

\documentclass{article}
  \usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{pstricks}

\begin{document}
\begin{pspicture}(5,5)
\psline(1,1)(5,1)(1,4)(1,1)
\pscircle[linestyle=dotted](3,2.5){2.5}
\pscircle[fillstyle=solid,fillcolor=lightgray](2,2){1}
\end{pspicture} 
\end{document}

it is giving me an error saying undefined control sequence.

Here is full version of error:

! Undefined control sequence.
<recently read> \c@lor@to@ps
l.9 \psline(
1,1)(5,1)(1,4)(1,1)
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.
! Undefined control sequence.
\XC@usec@lor ...string \color@ #1#2\endcsname \@@
\fi \space
l.9 \psline(
1,1)(5,1)(1,4)(1,1)
The control sequence at the end of the top line
of your error message was never \def'ed. 

marked as duplicate by Joseph Wright Jan 3 '18 at 9:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • you need to use latex not pdflatex (also you could update pstricks as the current versions give a (slightly) better error message. – David Carlisle Nov 24 '17 at 21:14
  • run the document with xelatex! – user2478 Nov 25 '17 at 12:49
2

You can use pdflatex to compile files with pstricks code, but as the .pdf format (a subset of postscript) has no computing engine for the computations required by postscript, it has to outsource these computations. This is done through the auto-pst-pdf package.

It will work under the condition that you launch pdflatex with the --enable-write18 switch under MiKTeX, or -shell-escape under TeX Live or MacTeX.

I took the opportunity to slightly shorten and improve your code:

\documentclass{article}
  \usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{pstricks}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{pspicture}(5,5)
\pspolygon[linejoin = 1](1,1)(5,1)(1,4)
\pscircle[linestyle=dotted](3,2.5){2.5}
\pscircle[fillstyle=solid,fillcolor=lightgray](2,2){1}
\end{pspicture}

\end{document} 

enter image description here

  • It is saying write 18 is not enabled? What should I do. I am using texmaker. – Bhaskar Vashishth Nov 24 '17 at 22:33
  • @BhaskarVashishth: Go to the menu Options > Configure Texmaker, TeX commands tab, write in the pdflatex line: pdflatex -synctex=1 --enable-write18 -interaction=nonstopmode %.tex. – Bernard Nov 24 '17 at 23:05

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