0

I am using MikTex and Texmaker, and the configurations-LaTeX+dvips+ps2pdf+View PDF. I have the following latex commands:

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}

\begin{document}


\begin{figure}[h]
  \centering
  \begin{pspicture}(4,4.3)
    \rput(3.7,-0.2){\scalebox{1.2}{
       \psdot(1.5,3.5)\rput(1.45,3.75){$v_1$}
       \psdot(-1,2)\rput(-1.3,2){$v_2$}
       \psdot(.5,2.3)\rput(0.9,2.3){$v_3$}
       \psdot(3,1)\rput(3,0.7){$v_4$}
       \psdot(4,2)\rput(4.3,2){$v_5$}
       \psdot(1,0.5)\rput(1,0.2){$v_6$}
       \psline(1.5,3.5)(-1,2)
       \psline(1.5,3.5)(0.5,2.3)
       \psline(1.5,3.5)(3,1)
       \psline(1.5,3.5)(1,0.5)
       \psline(-1,2)(.5,2.3)
       \psline(-1,2)(1,0.5)
       \psline(-1,2)(4,2)
       \psline(3,1)(.5,2.3)
       \psline(4,2)(3,1)
       \psline(-1,2)(1,0.5)
    }
  \end{pspicture}
  \caption{The graph $G_1$}\label{Fig-1}
\end{figure}
}
\end{document}

The figure doesn't appear when I try to run the source file. The following error appears:

!LaTeX Error: Two \documentclass or \documentstyle commands.

However, there is no two \documentclass used as warned. Please help me troubleshoot.

4
  • Here is an error here: $G_1} and there is a missing } after the brace that closes \scalebox. There is an extra } after \end{figure}. Then it compiles for me. What is the intention of that \scalebox?
    – daleif
    Jan 31 at 12:21
  • 2
    is your document called pstricks.tex (don't do that) Jan 31 at 12:26
  • My actual problem seems that \begin{pspicture}...\end{pspicture} is not recognised in my system.
    – gete
    Jan 31 at 12:27
  • 1
    pspicture won't be defined as that error means you never input the pstricks code. Jan 31 at 12:30

3 Answers 3

5

I would guess that your document is called pstricks.tex and your log looks like:

(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/pst-xkey.tex
(/usr/local/texlive/2023/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2023/texmf-dist/tex/generic/xkeyval/xkvutils.tex))))
(./pstricks.tex

! LaTeX Error: Two \documentclass or \documentstyle commands.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.1 \documentclass[11pt]{
                         article}
? 

The problem is that pstricks.sty is a latex wrapper for a plain tex file pstricks.tex so if your document is called pstricks.tex when you have \usepackage{pstricks} it ends up doing \input pstricks.tex and instead of finding the pstricks code, it re-inputs your document and you get the two documentclass error.

Just rename your document file to anything else.

If the document is renamed that part of the log/terminal output is:

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

showing that the real pstricks.tex from texmf-dist/tex/generic/pstricks/pstricks.tex has been loaded.

5
  • I have changed the file name to "Drawpicture". However, new error appears in line 1: ! File ended while scanning use of \pst@makenoteverbbox<inserted text>...
    – gete
    Jan 31 at 12:48
  • 1
    @gete yes you have an incorect } in the code see the other answer. This answer relates to the error shown in the question which is unrelated to any specifc pspicture it occurs during package loading before the document starts. Jan 31 at 13:37
  • There is a test in pstricks.sty for a second \documentclass, but it seems that it no more works ...
    – user187802
    Feb 1 at 15:04
  • @user187802 that sounds familiar..I should check Feb 1 at 16:09
  • @user187802 I see the problem, I'll open an issue at pstricks with a fix Feb 1 at 17:10
2

Grouping was wrongly done, modified MWE is:

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}

\begin{document}


\begin{figure}[h]
  \centering
  \begin{pspicture}(4,4.3)
    \rput(3.7,-0.2){\scalebox{1.2}{
       \psdot(1.5,3.5)\rput(1.45,3.75){$v_1$}
       \psdot(-1,2)\rput(-1.3,2){$v_2$}
       \psdot(.5,2.3)\rput(0.9,2.3){$v_3$}
       \psdot(3,1)\rput(3,0.7){$v_4$}
       \psdot(4,2)\rput(4.3,2){$v_5$}
       \psdot(1,0.5)\rput(1,0.2){$v_6$}
       \psline(1.5,3.5)(-1,2)
       \psline(1.5,3.5)(0.5,2.3)
       \psline(1.5,3.5)(3,1)
       \psline(1.5,3.5)(1,0.5)
       \psline(-1,2)(.5,2.3)
       \psline(-1,2)(1,0.5)
       \psline(-1,2)(4,2)
       \psline(3,1)(.5,2.3)
       \psline(4,2)(3,1)
       \psline(-1,2)(1,0.5)
    }}
  \end{pspicture}
  \caption{The graph $G_1$}\label{Fig-1}
\end{figure}


\end{document}

Output

enter image description here

1
  • 1
    yes that's a later error in the pstricks code, but not responsible for the two documentclass error shown which happens as the package is loaded not related to any specific pspicture Jan 31 at 13:35
1

run with lualatex --shell-escape <your file>. Then it can calculate the frame of the image. And use nodes, makes live easier:

\DocumentMetadata{}
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}

\begin{document}
        
\begin{figure}[!htb]
\centering
\psset{calcframe}
\begin{pspicture}%
\pnodes{v}(0,0)(1.5,3.5)(-1,2)(0.5,2.3)(3,1)(4,2)(1,0.5)
\pspolygon[showpoints](v5)(v4)(v3)(v2)(v1)(v6)(v2)   
\pspolygon[showpoints](v3)(v1)(v4)   
\uput[90](v1){$v_1$}\uput[180](v2){$v_2$}\uput[0](v3){$v_3$}
\uput[-90](v4){$v_4$}\uput[0](v5){$v_5$}\uput[-90](v6){$v_6$}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-1}
\end{figure}
    
\end{document}

enter image description here

You must log in to answer this question.

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