# Why does this not compile in LaTeX PDF mode?

The following, just compile when I do XeLaTeX mode. You can modify so I can build PDF LaTeX mode?

\documentclass[pstricks,border=15pt,12pt]{standalone}

\usepackage{pst-plot}

\begin{document}

\pslegend[rt]
{
\color{blue}\rule{5mm}{1mm} & \color{blue}$f(x)=e^x$

\color{red}\rule{5mm}{1mm} & \color{red}$f(x)=\ln(x)$
}
\begin{psgraph}[algebraic]{->}(0,0)(-3,-3)(7,7){12cm}{!}

\psplot[linecolor=blue]{-2.5}{2.5}{2^x}

\psplot[linecolor=red]{2 -2.5 exp}{2 2.5 exp}{log(x)/log(2)}

\psplot[linestyle=dashed]{-2}{6}{x}

\end{psgraph}

\end{document}

• Have you looked at pdftricks?
– cfr
Jun 15 '15 at 21:53

You can compile directly via pdflatex provided: 1) you add the pdf option to the document class (it says to pstricks to load auto-pst-pdf; the pstricks option isn't useful, as the package is loaded by pst-plot; 2) you enclose the pstricks code in a postscript environment (there seems to be some problems with the psgraph environment); 3) you launch pdflatex with the -shell-escape switch (for TeX Live and Mac TeX), or --enable-write18 (for MiKTeX):

\documentclass[pdf,border=15pt,12pt]{standalone}

\usepackage{pst-plot}

\begin{document}

\begin{postscript}
\pslegend[rt]
{
\color{blue}\rule{5mm}{1mm} & \color{blue}$f(x)=e^x$
\color{red}\rule{5mm}{1mm} & \color{red}$f(x)=\ln(x)$
}
\begin{psgraph}[algebraic]{->}(0,0)(-3,-3)(7,7){12cm}{!}
\psplot[linecolor=blue]{-2.5}{2.5}{2^x}
\psplot[linecolor=red]{2 -2.5 exp}{2 2.5 exp}{log(x)/log(2)}
\psplot[linestyle=dashed]{-2}{6}{x}
\end{psgraph}
\end{postscript}

\end{document}


The TikZ version of the diagram using package pgfplots, which is based on TikZ. Then pdfTeX in PDF mode can also be used to compile the document.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-3,
xmax=6.5,
ymin=-3,
ymax=6.5,
xlabel={$x$},
ylabel={$y$},
xtick={-3, ..., 6},
ytick={-3, ..., 6},
axis x line=middle,
axis y line=middle,
every axis x label/.append style={at={(axis cs:6.5, 0)}, right},
every axis y label/.append style={at={(axis cs:0, 6.5)}, above},
width=10cm,
height=10cm,
]
\addlegendentry{$f(x) = e^x$}
\addlegendentry{$f(x) = \ln(x)$}