2

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. 

1 Answers1

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

Bernard
  • 271,350
  • 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