The crucial piece of information to understand this error is the line in the .log
before the actual error message starts. It reads
(./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[12pt]{
article}
?
! Emergency stop.
...
l.1 \documentclass[12pt]{
article}
The document may only declare one class.
The (./pstricks.tex
means that TeX has opened a file called ./pstricks.tex
(i.e. a file in the same directory as your main TeX file called pstricks.tex
). As soon as that file is loaded the error occurs in the \documentclass
in line 1.
A part of the code of the package pstricks
lives in a file called pstricks.tex
and that file is loaded by the package. (pstricks.sty
has the line \input{pstricks}%
, which reads pstricks.tex
.)
The way TeX loads files means that files in your current working directory are given preference over files installed by your TeX distribution. In general that is a very useful feature because you can easily override some things locally without changing system files.
But in this case that means that a totally unrelated file called pstricks.tex
in the document directory is loaded instead of the package code in pstricks.tex
.
The easiest way to avoid that is by renaming your local file to something other than pstricks.tex
. In general you should avoid giving files the same name as a class or package, but you can never be entirely sure which names are problematic as packages could load additional .tex
files with different names. The only way to be sure is by checking the .log
thoroughly if similar issues occur.
Note that the error might have been much more cryptic and might have occurred at a different stage if your pstricks.tex
had not contained a \documentclass
, for example if it had been only a chapter of your paper that you load in a bigger document with \input
or \include
.
This is what Johannes_B hinted at in his comment
Do NOT call your document article.tex
Though, incidentally, acrticle.tex
would have probably been fine, since article.cls
does not attempt to load article.tex
.
A similar issue was discussed a few days ago in the German goLaTeX forum https://golatex.de/markdown-in-latex-einbinden-t21651.html where the issue appeared with the markdown
package, which loads markdown.tex
, when a user called their document Markdown.tex
(on a Windows system, which is case insensitive).
.log
file of the LaTeX run on that file? If it is too long to be shared here, you can upload it to a text-sharing website like pastebin.com.log
file should tell us which file is problematic. And even if this was not the cause of the error, the.log
file can give us vital information about what went wrong because it will contain the full error message with line numbers.pstricks.tex
in the same folder as this file. Butpstricks
is the name of a package you load. TeX picks up the wrong file and chaos ensues. Renamepstricks.tex
and you should be good.