4

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 ??"
3
  • 1
    auto-pst-pdf compiles the image separately and has no idea of the labels
    – user31729
    Commented Sep 10, 2015 at 13:06
  • 1
    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
    Commented Sep 10, 2015 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
    Commented Sep 10, 2015 at 13:46

2 Answers 2

6

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}

enter image description here

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

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

enter image description here

1
  • Or xelatex directly. Commented Sep 10, 2015 at 13:27

You must log in to answer this question.

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