Zum Inhalt springen

Introduction

Historically, one of the easiest ways to use PSTricks on Overleaf was via the XeLaTeX compiler—i.e., set your project’s compiler to XeLaTeX. In September 2021, the developer of PSTricks announced that LuaLaTeX could now be used to compile documents containing PSTricks code—providing users with another convenient solution.

As discussed on the PSTricks web page, LuaLaTeX can take a long time to compile extremely complex PSTricks examples, particularly those requiring extensive calculations. LuaLaTeX’s extended compilation time can occasionally trigger an Overleaf compile timeout.

Examples

The following examples can all be opened directly in Overleaf and use the XeLaTeX compiler; you can switch to using LuaLaTeX when the code is opened in Overleaf. All examples were initially published only in the Overleaf Gallery but are now reproduced here to show PSTricks code within this article’s text. They were sourced (reproduced) from the site http://www.thelazymathematician.com/p/pstricks-examples.html which, at the time of writing, no longer seems accessible.

Example 1: Plotting points

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{article}
\usepackage{pst-all}	%call the pstricks package
\begin{document}
\begin{pspicture}(-1,-1)(5,5)	
\psaxes{->}(0,0)(-0.5,-0.5)(4.5,4.5)[$x$,0][$y$, 90]	%creates axes
\psdot(2,1)	%plots the point (2,1)
\uput[0](2,1){$A$}	%labels the point (2,1) as A
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

PStricks plotting points in LaTeX on Overleaf

Example 2: Graphing an interval

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{article}
\usepackage{pst-all}	%call the pstricks package
\begin{document}	
\psset{xunit=0.5cm, yunit=0.5cm, yAxis=false}	%scales the picture, removes the y-axis
\begin{pspicture}(-11,0)(11,0)	
\psaxes[Dx=5, subticks=5]{<->}(0,0)(-11,0)(11,0)	%creates axes
\psline[linewidth=3pt, linecolor=cyan]{o->}(-2,0)(11,0)	%creates a thick, blue line from -2 (open) to infinity
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

PStricks Graphing an interval in LaTeX on Overleaf

Example 3: Graphing a curve through specific points

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{article}
\usepackage{pst-all}
\begin{document}
\psset{xunit=.5cm,yunit=0.5cm,}
\begin{pspicture}(-11,-11)(11,11)
\psgrid[subgriddiv=1, gridcolor=gray,griddots=10,gridlabels=0pt](0,0)(-10,-10)(10,10)
\psaxes[labelFontSize=\scriptscriptstyle]{<->}(0,0)(-10.5,-10.5)(10.5,10.5)
\pscurve[linewidth=1.5pt, showpoints=true, dotstyle=o, fillcolor=cyan]{<->}(-9,4)(-8,1)(-4,-5)(0,-4)(5,-3)(9,1)
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

 PStricks Graphing a curve through specific points in LaTeX on Overleaf

Example 4: Graphing a function

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{article}
\usepackage{pst-all}
\begin{document}
\psset{xunit=.5cm,yunit=0.5cm,algebraic=true}
\begin{pspicture}(-11,-11)(11,11)
\psaxes[Dx=2, Dy=2, subticks=2, labelFontSize=\scriptscriptstyle]{<->}(0,0)(-10.5,-10.5)(10.5,10.5)[$x$,0][$y$,90]
\psplot[linestyle=dotted, linewidth=2pt, linecolor=red, yMaxValue=10, yMinValue=-10]{0.1}{10} {ln(x)}
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

PStricks Graphing a function in LaTeX on Overleaf

Example 5: Graphing a trig function

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{amsart}
\usepackage{pst-all}
\begin{document}
\begin{pspicture}(-6.5,-2.5)(6.5,5.5)
\psaxes[trigLabelBase=2,dx=\pstPI2, xunit=\psPi,trigLabels, xsubticks=2]{<->}(0,0)(-1.2,-2.4)(1.2,5.4)[$x$,0][$y$,90]
\psplot[algebraic,linewidth=1.6pt,plotpoints=10000, linecolor=red]{-\psPi}{\psPi}{cos(2*x)+ 3}
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

 PStricks Graphing a trig function in LaTeX on Overleaf

Example 6: Drawing a polygon

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass[11pt]{article}
\usepackage{pst-all}
\begin{document}
\psset{xunit=1cm,yunit=1cm,algebraic=true}
\begin{pspicture}(0,0)(3,3)
\pspolygon[linecolor=orange,fillcolor=blue!20, fillstyle=vlines*, hatchcolor=purple, showpoints=false, linearc=0.2](1,1)(2,1)(2.31,1.95)(1.5,2.54)(0.69,1.95)
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

PStricks Drawing a polygon in LaTeX on Overleaf

Example 7: Drawing a circle

% Original source: http://www.thelazymathematician.com/p/pstricks-examples.html
\documentclass{article}
\usepackage{pst-all}
\begin{document}
\psset{xunit=0.15in, yunit=0.15in}
\begin{pspicture}(0,0)(11,11)
\psaxes[Dx=4,Dy=4, subticks=4]{->}(0,0)(0,0)(10,10)[$x$,0][$y$,0]
\pscircle[runit=0.15in, fillcolor=orange!50, fillstyle=solid,shadow=true](5,5){3}
\end{pspicture}
\end{document}

 Open this example in Overleaf


This example produces the following output:

PStricks Drawing a circle in LaTeX on Overleaf

Overleaf Gallery links

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX