# References are not recognized inside psmatrix

In a psmatrix environment, labels are not recognized. Here is a MWE:

\documentclass[]{article}
\usepackage[crop=on]{auto-pst-pdf}
\usepackage{pst-node}

\begin{document}
\section{First \label{sec:first}}
\begin{figure}
\caption{this is a figure \label{fig:first}}
\end{figure}

See Figure \ref{fig:first} in Section \ref{sec:first}.
\begin{psmatrix}[colsep=0cm,rowsep=0mm]
Did you see Figure \ref{fig:first} in Section \ref{sec:first}?

\end{psmatrix}

\end{document}


Prints:

 "See Figure 1 in Section 1".
"Did you see Figure ?? in Section ??"

• auto-pst-pdf compiles the image separately and has no idea of the labels – user31729 Sep 10 '15 at 13:06
• AFAIK anything pstricks done this way is written to and external file and compiled on its own. Thus it has no connection to the original file and thus cannot resolve references that refer to the original file. – daleif Sep 10 '15 at 13:06
• auto-pst-pdf runs the document with latex. Getting correct labels two runs of latex are needed. After that, the created image has the right label. – user2478 Sep 10 '15 at 13:46

You need the runs=2 option to auto-pst-pdf -- In this case the external compilation will do the references correctly (It's in the manual ;-))

\documentclass[]{article}
\usepackage[crop=on,runs=2]{auto-pst-pdf}
\usepackage{pst-node}

\begin{document}
\section{First \label{sec:first}}
\begin{figure}
\caption{this is a figure \label{fig:first}}
\end{figure}

See Figure \ref{fig:first} in Section \ref{sec:first}.
\begin{psmatrix}[colsep=0cm,rowsep=0mm]
Did you see Figure \ref{fig:first} in Section \ref{sec:first}?

\end{psmatrix}

\end{document}


• +1 despite the fact that you clearly cheated by looking in a manual:-) – David Carlisle Sep 10 '15 at 13:10
• @DavidCarlisle: sometimes I cheat, after you scolded other users for them not looking into manuals :-P – user31729 Sep 10 '15 at 13:12

If ypu use pdflatex the pstricks fragment is handled as an external file, however if you use

latex, dvips, ps2pdf

then it works in one file and you get