[Tex/LaTex] How to convert a LaTeX file with pstricks code to pdf

pdftexpstricks

I am new to LaTeX and was writing an article with MikTeX. But when I insert a pspicture and compile the file into pdf format, the pspicture just does not show up. But if I compile the file into ps, then the figure, which is an external .png file, goes wrong. Seemingly they just cannot be together 🙁 I googled many solutions and tried to import many different packages but still doesn't work out.

The code is given as below:

\documentclass{article}
\usepackage[pdf]{pstricks}
\usepackage{pst-sigsys}
\usepackage{auto-pst-pdf}

\pagestyle{empty}

\begin{document}

\begin{figure}[ht]
    \centering
    \begin{pspicture}(-7.5,-2.5)(7.5,.5)
      \psset{style=RoundCorners,style=Arrow,gratioWh=1.35}
      \pssignal(-7.5,-1){f}{$f(n)$}
      \pssignal(7.5,-1){ff}{$\hat{f}(n)$}
      \dotnode(-6,-1){dot1}
      \pscircleop(6, -1)    {oplus}
      \newcount\cnt

    %--- First and second channels ---
    \cnt=-1
    \psforeach{\ry}{0,-2}{\advance\cnt by 1\relax
    \psfblock(-4.5,\ry){h\the\cnt}{$h_{\the\cnt}(n)$}
    \psdsampler(-2,\ry){ds\the\cnt}{2}
    \ldotsnode(0,\ry){dots\the\cnt}
    \psusampler(2,\ry){us\the\cnt}{2}
    \psfblock(4.5,\ry){g\the\cnt}{$g_{\the\cnt}(n)$}}

    %--- Connecting blocks ---
      \nclist{ncline}{f, dot1}
      \nclist{ncline}{oplus, ff}
      \nclist{ncline}{h0, ds0, dots0, us0, g0}
      \nclist{ncline}{h1, ds1, dots1, us1, g1}
      \ncangle[angleA=90, angleB=180]{dot1}{h0}
      \ncangle[angleA=-90, angleB=180]{dot1}{h1}
      \ncangle[angleB=90]{g0}{oplus}
      \ncangle[angleB=-90]{g1}{oplus}
    \end{pspicture}
\end{figure}

\begin{figure}[ht]
    \centering
    \includegraphics[scale=.5]{./gsample2.png}
\end{figure}

\end{document}

Hope somebody can help me solve the problem. Thanks a lot.

Here I am also giving the log-file. I didn't change the code at all, only passing -escape-shell to compiler.

    This is pdfTeX, Version 3.1415926-1.40.10 (MiKTeX 2.8) (preloaded format=pdflatex 2011.8.7)  20 JAN 2012 14:22
    entering extended mode
    **D:/Documents/LaTeX*file/BlockDiagram.tex
    ("D:/Documents/LaTeX file/BlockDiagram.tex"
    LaTeX2e <2011/06/27>
    Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, german, ngerman, german-x-2009-06-19, ngerm
    an-x-2009-06-19, french, loaded.
    ("C:\Program Files\MiKTeX 2.8\tex\latex\base\article.cls"
    Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
    ("C:\Program Files\MiKTeX 2.8\tex\latex\base\size10.clo"
    File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
    )
    \c@part=\count79
    \c@section=\count80
    \c@subsection=\count81
    \c@subsubsection=\count82
    \c@paragraph=\count83
    \c@subparagraph=\count84
    \c@figure=\count85
    \c@table=\count86
    \abovecaptionskip=\skip41
    \belowcaptionskip=\skip42
    \bibindent=\dimen102
    ) ("C:\Program Files\MiKTeX 2.8\tex\latex\pstricks\pstricks.sty"
    Package: pstricks 2011/10/31 v0.52 LaTeX wrapper for `PSTricks' (RN,HV)

    >>> Loading package auto-pst-pdf <<<
    ("C:\Program Files\MiKTeX 2.8\tex\generic\pstricks\base\pstricks.tex"
    ("C:\Program Files\MiKTeX 2.8\tex\generic\xkeyval\pst-xkey.tex"
    File: pst-xkey.tex 2005/11/25 v1.6 PSTricks specialization of xkeyval (HA)

    ("C:\Program Files\MiKTeX 2.8\tex\latex\xkeyval\xkeyval.sty"
    Package: xkeyval 2008/08/13 v2.6a package option processing (HA)

    ("C:\Program Files\MiKTeX 2.8\tex\generic\xkeyval\xkeyval.tex"
    \XKV@toks=\toks14
    \XKV@tempa@toks=\toks15
    \XKV@depth=\count87
    File: xkeyval.tex 2008/08/13 v2.6a key=value parser (HA)
     ("D:\Documents\LaTeX file\keyval.tex"))))
    ("C:\Program Files\MiKTeX 2.8\tex\generic\pstricks\base\pst-fp.tex" `pst-fp' v0.05, 2010/01/17 (hv)
    \pstFP@xs=\count88
    \pstFP@xia=\count89
    \pstFP@xib=\count90
    \pstFP@xfa=\count91
    \pstFP@xfb=\count92
    \pstFP@rega=\count93
    \pstFP@regb=\count94
    \pstFP@regs=\count95
    \pstFP@times=\count96
    )
    \psLoopIndex=\count97

    `PSTricks' v2.23  <2011/09/04> (tvz)
    \pst@dima=\dimen103
    \pst@dimb=\dimen104
    \pst@dimc=\dimen105
    \pst@dimd=\dimen106
    \pst@dimg=\dimen107
    \pst@dimh=\dimen108
    \pst@dimm=\dimen109
    \pst@dimn=\dimen110
    \pst@dimo=\dimen111
    \pst@dimp=\dimen112
    \pst@hbox=\box26
    \pst@ibox=\box27
    \pst@boxg=\box28
    \pst@cnta=\count98
    \pst@cntb=\count99
    \pst@cntc=\count100
    \pst@cntd=\count101
    \pst@cntg=\count102
    \pst@cnth=\count103
    \pst@cntm=\count104
    \pst@cntn=\count105
    \pst@cnto=\count106
    \pst@cntp=\count107
    \@zero=\count108
    \pst@toks=\toks16
    ("C:\Program Files\MiKTeX 2.8\tex\generic\pstricks\base\pstricks.con")
    \psunit=\dimen113
    \psxunit=\dimen114
    \psyunit=\dimen115
    \pst@C@@rType=\count109
    \pslinewidth=\dimen116
    \psk@startLW=\dimen117
    \psk@endLW=\dimen118
    \pst@customdefs=\toks17
    \pslinearc=\dimen119
    \pst@symbolStep=\dimen120
    \pst@symbolWidth=\dimen121
    \everypsbox=\toks18
    \psframesep=\dimen122
    \pslabelsep=\dimen123
    \pst@shift=\dimen124
    \theoverlaybox=\box29
    )
    File: pstricks.tex 2011/09/04 v2.23 `PSTricks' (tvz,hv)

    ("C:\Program Files\MiKTeX 2.8\tex\generic\pstricks\base\pst-fp.tex")
    File: pst-fp.tex 2011/09/04 v2.23 `PST-fp' (hv)

    ("C:\Program Files\MiKTeX 2.8\tex\latex\xcolor\xcolor.sty"
    Package: xcolor 2007/01/21 v2.11 LaTeX color extensions (UK)
     ("C:\Program Files\MiKTeX 2.8\tex\latex\00miktex\color.cfg"
    File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
    )
    Package xcolor Info: Package option `pdf' ignored on input line 216.
    Package xcolor Info: Driver file: pdftex.def on input line 225.

    ("C:\Program Files\MiKTeX 2.8\tex\latex\pdftex-def\pdftex.def"
    File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX

    ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\infwarerr.sty"
    Package: infwarerr 2010/04/08 v1.3 Providing info/warning/message (HO)
    )
    ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\ltxcmds.sty"
    Package: ltxcmds 2011/04/18 v1.20 LaTeX kernel commands for general use (HO)
    )
    \Gread@gobject=\count110
    )
    Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1337.
    Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1341.
    Package xcolor Info: Model `RGB' extended on input line 1353.
    Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1355.
    Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1356.
    Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1357.
    Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1358.
    Package xcolor Info: Model `Gray' substituted by `gray' on input line 1359.
    Package xcolor Info: Model `wave' substituted by `hsb' on input line 1360.
    ))
    ("C:\Program Files\MiKTeX 2.8\tex\latex\pst-sigsys\pst-sigsys.sty"
    Package: pst-sigsys 2011/03/07 package wrapper for pst-sigsys.tex (fd)

    ("C:\Program Files\MiKTeX 2.8\tex\generic\pst-sigsys\pst-sigsys.tex"
    ("C:\Program Files\MiKTeX 2.8\tex\generic\pst-node\pst-node.tex"  v1.21, 2011/11/21
    \psrow=\count111
    \pscol=\count112
    \psmatrixcnt=\count113
    \psrowsep=\skip43
    \pscolsep=\skip44
    \pst@args=\count114
    \num@pts=\count115
    \pst@argcnt=\count116
    ) `PST-SigSys' v1.4, 2011/03/07 (fd)
    \ss@ticklength=\dimen125
    \ss@signalsep=\dimen126
    \ss@zerowidth=\dimen127
    \ss@zeroradius=\dimen128
    \ss@zeroradiusinc=\dimen129
    \ss@polewidth=\dimen130
    \ss@polelength=\dimen131
    \ss@oplength=\dimen132
    \ss@opwidth=\dimen133
    \ss@opsep=\dimen134
    \ss@ldotssep=\dimen135
    \ss@ldotssize=\dimen136
    \ss@aoffset=\dimen137
    \ss@knoblength=\dimen138
    \ss@knobwidth=\dimen139
    \ss@temp@dimA=\dimen140
    \ss@temp@dimB=\dimen141
    \ss@temp@dimC=\dimen142
    \ss@temp@cnt=\count117
    \ss@calc@dim=\dimen143
    \ss@if@dimA=\dimen144
    \ss@if@dimB=\dimen145
    )
    File: pst-sigsys.tex 2011/03/07 v1.4 `PST-sigsys' (fd)
    ) ("C:\Program Files\MiKTeX 2.8\tex\latex\auto-pst-pdf\auto-pst-pdf.sty"
    Package: auto-pst-pdf 2009/04/26 v0.6 Wrapper for pst-pdf
     ("D:\Documents\LaTeX file\ifpdf.sty"
    Package: ifpdf 2001/06/14 v1.0 Providing \ifpdf (HO)
    Package ifpdf Info: pdfTeX in pdf mode detected on input line 140.
    )
    ("C:\Program Files\MiKTeX 2.8\tex\latex\ifplatform\ifplatform.sty"
    Package: ifplatform 2010/10/22 v0.4 Testing for the operating system

    ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\pdftexcmds.sty"
    Package: pdftexcmds 2011/04/22 v0.16 Utilities of pdfTeX for LuaTeX (HO)

    ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\ifluatex.sty"
    Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
    Package ifluatex Info: LuaTeX not detected.
    )

    LaTeX Warning: You have requested, on input line 187, version
                   `2010/09/13' of package ifpdf,
                   but only version
                   `2001/06/14 v1.0 Providing \ifpdf (HO)'
                   is available.

    Package pdftexcmds Info: LuaTeX not detected.
    Package pdftexcmds Info: \pdf@primitive is available.
    Package pdftexcmds Info: \pdf@ifprimitive is available.
    Package pdftexcmds Info: \pdfdraftmode found.
    ) ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\catchfile.sty"
    Package: catchfile 2011/03/01 v1.6 Catches the contents of a file (HO)

    ("C:\Program Files\MiKTeX 2.8\tex\generic\oberdiek\etexcmds.sty"
    Package: etexcmds 2011/02/16 v1.5 Prefix for e-TeX command names (HO)
    Package etexcmds Info: Could not find \expanded.
    (etexcmds)             That can mean that you are not using pdfTeX 1.50 or
    (etexcmds)             that some package has redefined \expanded.
    (etexcmds)             In the latter case, load this package earlier.
    )))
    \c@app@runs=\count118
    runsystem(echo " ")...executed.

    runsystem(echo "-------------------------------------------------")...executed.

    runsystem(echo "auto-pst-pdf: Auxiliary LaTeX compilation")...executed.

    runsystem(echo "-------------------------------------------------")...executed.

    runsystem(del "BlockDiagram-autopp.log")...executed.

    runsystem(del "BlockDiagram-autopp.aux")...executed.

    runsystem(del "BlockDiagram-autopp.dvi")...executed.

    runsystem(del "BlockDiagram-autopp.ps")...executed.

    runsystem(del "BlockDiagram-autopp.pdf")...executed.

    runsystem(latex -disable-write18 -jobname="BlockDiagram-autopp" -interaction=batchmode  "\let \APPmakepictures \empty \i
    nput  BlockDiagram.tex")...executed.

    runsystem(dvips -Ppdf -o "BlockDiagram-autopp.ps" "BlockDiagram-autopp.dvi")...executed.

    runsystem(ps2pdf  "BlockDiagram-autopp.ps" "BlockDiagram-autopp.pdf")...executed.

    runsystem(pdfcrop  "BlockDiagram-autopp.pdf" "BlockDiagram-pics.pdf")...executed.



    Package auto-pst-pdf Warning: 
        Creation of BlockDiagram-pics.pdf failed.
    This warning occured on input line 124.


    Package auto-pst-pdf Warning: 
        Could not create BlockDiagram-pics.pdf. Auxiliary files not deleted.
    This warning occured on input line 124.

    runsystem(echo "-------------------------------------------------")...executed.

    runsystem(echo "auto-pst-pdf: End auxiliary LaTeX compilation")...executed.

    runsystem(echo "-------------------------------------------------")...executed.

    ("C:\Program Files\MiKTeX 2.8\tex\latex\pst-pdf\pst-pdf.sty"
    Package: pst-pdf 2008/10/09 v1.1v PS graphics for pdfLaTeX (RN,HjG)
    \c@pspicture=\count119

    ("C:\Program Files\MiKTeX 2.8\tex\latex\graphics\graphicx.sty"
    Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)

    ("C:\Program Files\MiKTeX 2.8\tex\latex\graphics\graphics.sty"
    Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
     ("C:\Program Files\MiKTeX 2.8\tex\latex\graphics\trig.sty"
    Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
    ) ("C:\Program Files\MiKTeX 2.8\tex\latex\00miktex\graphics.cfg"
    File: graphics.cfg 2007/01/18 v1.5 graphics configuration of teTeX/TeXLive
    )
    Package graphics Info: Driver file: pdftex.def on input line 91.
    )
    \Gin@req@height=\dimen146
    \Gin@req@width=\dimen147
    )
    Package pst-pdf Info: MODE: 1 (pdfTeX mode) on input line 214.
    \ppf@output=\toks19

    ("C:\Program Files\MiKTeX 2.8\tex\latex\preview\preview.sty"
    Package: preview 2010/02/14 11.86 (AUCTeX/preview-latex)
    \pr@snippet=\count120
    \pr@box=\box30
    \pr@output=\toks20
    ) ("C:\Program Files\MiKTeX 2.8\tex\latex\graphics\dvips.def"
    File: dvips.def 1999/02/16 v3.0i Driver-dependant file (DPC,SPQR)
    ) ("C:\Program Files\MiKTeX 2.8\tex\latex\environ\environ.sty"
    Package: environ 2008/06/18 v0.2 A new way to define environments
    \@emptytoks=\toks21
    \@envbody=\toks22
    ))) ("D:\Documents\LaTeX file\BlockDiagram.aux")
    LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 8.
    LaTeX Font Info:    ... okay on input line 8.
    LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 8.
    LaTeX Font Info:    ... okay on input line 8.
    LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 8.
    LaTeX Font Info:    ... okay on input line 8.
    LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 8.
    LaTeX Font Info:    ... okay on input line 8.
    LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 8.
    LaTeX Font Info:    ... okay on input line 8.
    LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 8.
    LaTeX Font Info:    ... okay on input line 8.

    ("C:\Program Files\MiKTeX 2.8\tex\context\base\supp-pdf.mkii"
    [Loading MPS to PDF converter (version 2006.09.02).]
    \scratchcounter=\count121
    \scratchdimen=\dimen148
    \scratchbox=\box31
    \nofMPsegments=\count122
    \nofMParguments=\count123
    \everyMPshowfont=\toks23
    \MPscratchCnt=\count124
    \MPscratchDim=\dimen149
    \MPnumerator=\count125
    \makeMPintoPDFobject=\count126
    \everyMPtoPDFconversion=\toks24
    )
    Preview: Fontsize 10pt
    Preview: PDFoutput 1

    Package pst-pdf Warning: pspicture No. 1 undefined.

    <./gsample2.png, id=1, 422.32782pt x 316.18124pt>
    File: ./gsample2.png Graphic file (type png)
     <use ./gsample2.png>
    Package pdftex.def Info: ./gsample2.png used on input line 41.
    (pdftex.def)             Requested size: 211.16339pt x 158.09023pt.


    Package pst-pdf Warning: File `BlockDiagram-pics.pdf' not found.
    (pst-pdf)                Use the following commands to create it:
    (pst-pdf)                ---------------------------------------------------- 
    (pst-pdf)                latex BlockDiagram.tex
    (pst-pdf)                dvips -o BlockDiagram-pics.ps BlockDiagram.dvi
    (pst-pdf)                ps2pdf BlockDiagram-pics.ps
    (pst-pdf)                ---------------------------------------------------- .

    [1


    Non-PDF special ignored!
    Non-PDF special ignored!
    Non-PDF special ignored! <D:/Documents/LaTeX file/gsample2.png (PNG copy)>] ("D:\Documents\LaTeX file\BlockDiagram.aux")
     ) 
    Here is how much of TeX's memory you used:
     4278 strings out of 495285
     57808 string characters out of 3180547
     141368 words of memory out of 3000000
     7442 multiletter control sequences out of 15000+200000
     3640 words of font info for 14 fonts, out of 3000000 for 9000
     14 hyphenation exceptions out of 8191
     39i,7n,38p,600b,332s stack positions out of 5000i,500n,10000p,200000b,50000s

    Output written on BlockDiagram.pdf (1 page, 10107 bytes).
    PDF statistics:
     7 PDF objects out of 1000 (max. 8388607)
     0 named destinations out of 1000 (max. 500000)
     6 words of extra memory for PDF output out of 10000 (max. 10000000)

Best Answer

The code you have compiles as it is. However, if you want to compile the code to PDF, it is easier to use pdflatex. To use pstricks with pdflatex you should use the -shell-escape option when compiling your document. Consequently, you should call the compiler like this:

pdflatex -shell-escape file.tex  % on windows or linux

And your example shows: Example

Note that if you are using an IDE to write your document, most of them provide options to customize the way they call each command. You should be able to change it accordingly.