gpoore / minted

minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.
1.74k stars 124 forks source link

Conflict with auto-pst-pdf #237

Open tscmacdonald opened 5 years ago

tscmacdonald commented 5 years ago

There appears to be a conflict between minted and the auto-pst-pdf package when using the PdfLaTeX engine with -shell-escape. For example, here is a working MWE to produce a PDF containing some figure fig.eps when executed with pdflatex --shell-escape:

\documentclass{report}
\usepackage{graphicx}
\usepackage{auto-pst-pdf}

\begin{document}
Start of the document.

\begin{figure}
\includegraphics{fig.eps}
\end{figure}
\end{document}

Adding a minted section to this document breaks auto-pst-pdf, with the resulting PDF containing a valid Minted section but no graphics:

\documentclass{report}
\usepackage{minted}
\usepackage{graphicx}
\usepackage{auto-pst-pdf}
\begin{document}
Start of the document.
\begin{figure}
\includegraphics{fig.eps}
\end{figure}

\begin{minted}{python}
def helloworld:
    print("Hello World")
\end{minted}
\end{document}

Here is the error shown in the output during the attempted auto-pst-pdf auxiliary compilation:

"-------------------------------------------------"
"auto-pst-pdf: Auxiliary LaTeX compilation"
"-------------------------------------------------"
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (MiKTeX 2.9.6210 64-bit)
entering extended mode

Package auto-pst-pdf Warning:
    Creation of tex-autopp.dvi failed.
This warning occured on input line 124.

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

"-------------------------------------------------"
"auto-pst-pdf: End auxiliary LaTeX compilation"
"-------------------------------------------------"

I'm not sure what the conflict is here, but auto-pst-pdf is a standard and highly important package for documents including both vector and raster graphics. This conflict seems to have existed for some time: here is a StackExchange question from 2012 on the subject.

Is a fix for this issue possible? If not, I would suggest adding mention of the incompatibility to Minted's documentation at a minimum.

muzimuzhi commented 5 years ago

Using the accepted answer to the TeX-SX question you mentioned, your mwe works fine. Try this:

\documentclass{report}
\usepackage{ifpdf}
\usepackage{graphicx}
\usepackage{auto-pst-pdf}

\ifpdf
  \usepackage{minted}
\fi
\begin{document}
Start of the document.
\begin{figure}
\includegraphics{fig.eps}
\end{figure}

\ifpdf
  \begin{minted}{python}
  def helloworld:
    print("Hello World")
  \end{minted}
\fi
\end{document}

Does this also works for you?

PS: If you just need to insert an eps file, loading graphics is enough. It will automatically convert eps to pdf, with the help of latex package epstopdf and command line tool ghostscript.

tscmacdonald commented 5 years ago

@muzimuzhi That works for me, but it's still a slightly clumsy workaround that would be good to see addressed at the package level (or at least documentation level). As to just loading the eps directly, the only reason I'm using eps graphics is to make use of pstricks for on-the-fly renumbering and editing, which doesn't seem to work when directly calling pdflatex without auto-pst-pdf.

gpoore commented 5 years ago

@tscmacdonald The ultimate problem here is that auto-pst-pdf is incompatible with all other packages that require -shell-escape, including minted, auto-pst-pdf runs latex one or more times on a document to handle the PostScript, and it runs latex without -shell-escape. Then minted (or any other package requiring -shell-escape) raises an error about the lack of -shell-escape, which prevents figures from being generated.

From the minted side, the only thing that can really be done is to use \ifpdf, as @muzimuzhi suggested. This should generally work, but because it prevents minted from loading, it causes errors during the separate latex run that auto-pst-pdf initiates since the minted environments and commands are not defined. While those errors apparently don't prevent successful compilation in many cases, I expect that there are some edge cases where they would.

I can add a note about using \ifpdf with auto-pst-pdf to the minted FAQ. However, this might be more useful in the auto-pst-pdf manual, since it is a more general problem with packages that need -shell-escape.

From the auto-pst-pdf side, if latex were run with -shell-escape, that would probably resolve the issues with minted and most other packages that need -shell-escape. However, it's possible that some other packages using -shell-escape do so in a way that would interfere with auto-pst-pdf, so that may not really be a general solution. Another option, at least for minted, would be for auto-pst-pdf to set draft mode for the separate latex run. In that case, minted doesn't need -shell-escape.