2

I am looking for working PSTricks example code that would run using pdflatex or TexShop on a MacBook Pro laptop. For example, the PSTricks code that I copied from

https://tug.org/PSTricks/main.cgi?file=pst-plot/pst-plotDemo#intro

specifically the code pst-plot8Demo.tex plotting two sin waves, and given below,

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-20,-1.25)(200,1.25)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

produces the same error using TexShop or pdflatex, namely (pdflatex run error shown below)

***************************************************************
[JohnComputer:] john% pdflatex pst-plotDemo8.tex

This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2022/dev) (preloaded format=pdflatex)

 restricted \write18 enabled.

entering extended mode

(./pst-plotDemo8.tex

LaTeX2e <2021-11-15>

L3 programming layer <2021-11-22>

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrartcl.cls

Document Class: scrartcl 2021/11/13 v3.35 KOMA-Script document class (article)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrkbase.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrbase.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlfile.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlfile-hook.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlogo.sty)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/keyval.sty)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/tocbasic.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/typearea.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsmath.sty

For additional information on amsmath, use the `?' option.

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amstext.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsgen.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsbsy.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsopn.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/pst-plot/pst-plot.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/pstricks/pstricks.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/iftex/iftex.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/xcolor/xcolor.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-cfg/color.cfg)

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-def/pdftex.def))

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/pst-xkey.tex

(/usr/local/texlive/2021/texmf-dist/tex/latex/xkeyval/xkeyval.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/xkeyval.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/xkvutils.tex))))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pst-fp.tex

`pst-fp' v0.06, 2020/11/20 (hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te

x

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li

sts.tex))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c

ode.tex))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex

Loading pgffor.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex

)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.

tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic

.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo

nometric.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando

m.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa

rison.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.

code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round

.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.

code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ

erarithmetics.code.tex)))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)

))

`PSTricks' v3.11  <2021/09/27> (tvz,hv)

--- We are running latex or xelatex ---

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.con)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-color.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-arrows.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-dots.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.con))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pst-fp.tex

`pst-fp' v0.06, 2020/11/20 (hv)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/xkeyval/pst-xkey.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/multido/multido.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/multido/multido.tex

 v1.42, 2010/05/14 <tvz>))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-plot/pst-plot.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-tools/pst-tools.tex

`PST-tools' v0.12, 2021/09/23 (hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks-add/pstricks-add.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-node/pst-node.tex

 v1.42a, 2020/04/01)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-arrow/pst-arrow.tex

`pst-arrow' v0.05, 2021/11/16 (dr,hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-3d/pst-3d.tex

`PST-3d' v1.11, 2010/02/14 (tvz))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-math/pst-math.tex

`pst-math' v0.64 , (CJ,hv)) `pstricks-add' v3.91, 2021/09/25 (dr,hv))

 v1.93, 2021/09/23 (tvz,hv)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)

(./pst-plotDemo8.aux)

(/usr/local/texlive/2021/texmf-dist/tex/context/base/mkii/supp-pdf.mkii

[Loading MPS to PDF converter (version 2006.09.02).]

)

! Undefined control sequence.

\c@lor@to@ps ->\PSTricks 

                         _Not_Configured_For_This_Format

l.9   \psplot

             {0}{180}{x sin}

? 

Many examples that I have downloaded and tried have produced the same error message.

I understand from extensive googling that there apparently is an issue with the pdf output for pstricks. However, I am unable to resolve the issue. After several hours or google/research/trying different things, I give up.

Incidently it is worth mentioning that my ultimate goal is to use Inkscape to output tex code for inclusion in a larger LaTex document. Inkscape is a graphics program and outputs pstricks code.

Thank you in advance for any assistance.

6
  • Welcome to TeX.SE!
    – Zarko
    Dec 5, 2021 at 19:32
  • does this help? tex.stackexchange.com/a/8415/15036
    – Thruston
    Dec 5, 2021 at 19:38
  • the example you give works on my mac if I do latex to produce an old fashioned .dvi file, then dvipdf to produce a .pdf from that. Normally I would use xelatex which does this is one step, but I get a different error from that at the moment.
    – Thruston
    Dec 5, 2021 at 19:40
  • you need to run latex not pdflatex (and then dvips + ps2pdf if you want a pdf). You could also try lualatex, on a current system it can handle some pstricks. Dec 5, 2021 at 19:44
  • pstricks requires a postscript interpreter so is basically incompatible with pdflatex. inkscape will save to pdf which you can directly include in pdflatex Dec 5, 2021 at 20:06

3 Answers 3

3

Run it with lualatex:

% !TEX program = lualatex
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-30,-1.3)(210,1.4)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

enter image description here

0
2

The example works with pdflatex when using the auto-pst-pdf package and compiled with the shell-escape compiler flag.

In the background this package calls latex+dvips on the relevant PSTricks code, but as a user you just need a single pdflatex run.

MWE:

\documentclass{scrartcl}
\usepackage{auto-pst-pdf}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-20,-1.25)(200,1.25)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

Result:

enter image description here

3
  • it's true but kind of weird as it only works by calling latex/dvips/ps2pdf in the background and then including the pdf. so the OP could hav eused latex/dvips/ps2pdf directly and not needed shell-escape and pdflatex at all. (I know that is exactly what you said, I'm not disagreeing with the answer:-) Dec 5, 2021 at 20:15
  • @DavidCarlisle one difference is that auto-pst-pdf makes and compiles temporary files only for the pstricks parts, and the rest of the document is still compiled by pdflatex itself. So if you have any functionality that works with pdflatex but not with latex+dvips+ps2pdf then this could be the better option.
    – Marijn
    Dec 5, 2021 at 20:21
  • yes agreed, it's just that in this example "the rest of the document" is er.. a bit minimal Dec 5, 2021 at 20:30
1

Pstricks doesn't work directly with pdflatex. You can use latex->dvips->ps2pdf or xelatex directly but, if you are using a recent version of Ghostscript you'll need to use ps2pdf or xelatex configured to work with that newer Ghostscript. If you have the latest version of TeXShop, 4.68, there are spcial engines for latex->dvips->ps2pdf and xelatex are are properly configured. They are called latexTR and xelatexTR but are not activated by default. To activate them copy latexTR.engine and xelatexTR.engine from the ~/Library/TeXShop/Engines/Inactive/GhostscriptTransparencyEngines folder three levels up, to ~/Library/TeXShop/Engines and restart TeXShop. The en use them place the line % !TEX program = latexTR at the top of your Source document for using the latexTR engine or % !TEX program = xelatexTR there for using the xelatexTR engine. Then typeset the document using the Typeset->Typeset (Cmd-T) menu command.

To quickly open the ~/Library/TeXShop folder you can use the TeXShop->Open ~/Library/TeXShop menu command.

2
  • you can also use luatex in recent releases (xetex/xdvipdfmx has some issues with changes in recent ghostscript) Dec 5, 2021 at 20:29
  • For this example lualatex works fine. However you must force the use of an update (by Herbert Voss) to pst-geometrictools.tex if tthere is any transparency. Dec 5, 2021 at 20:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .