Can I use the pstricks package on Overleaf?
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.
- TIP: Visit the PSTricks gallery for many more examples to try out on Overleaf.
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}
This example produces the following output:
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}
This example produces the following output:
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}
This example produces the following output:
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}
This example produces the following output:
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}
This example produces the following output:
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}
This example produces the following output:
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}
This example produces the following output:
Overleaf Gallery links
Overleaf guides
- Creating a document in Overleaf
- Uploading a project
- Copying a project
- Creating a project from a template
- Using the Overleaf project menu
- Including images in Overleaf
- Exporting your work from Overleaf
- Working offline in Overleaf
- Using Track Changes in Overleaf
- Using bibliographies in Overleaf
- Sharing your work with others
- Using the History feature
- Debugging Compilation timeout errors
- How-to guides
- Guide to Overleaf’s premium features
LaTeX Basics
- Creating your first LaTeX document
- Choosing a LaTeX Compiler
- Paragraphs and new lines
- Bold, italics and underlining
- Lists
- Errors
Mathematics
- Mathematical expressions
- Subscripts and superscripts
- Brackets and Parentheses
- Matrices
- Fractions and Binomials
- Aligning equations
- Operators
- Spacing in math mode
- Integrals, sums and limits
- Display style in math mode
- List of Greek letters and math symbols
- Mathematical fonts
- Using the Symbol Palette in Overleaf
Figures and tables
- Inserting Images
- Tables
- Positioning Images and Tables
- Lists of Tables and Figures
- Drawing Diagrams Directly in LaTeX
- TikZ package
References and Citations
- Bibliography management with bibtex
- Bibliography management with natbib
- Bibliography management with biblatex
- Bibtex bibliography styles
- Natbib bibliography styles
- Natbib citation styles
- Biblatex bibliography styles
- Biblatex citation styles
Languages
- Multilingual typesetting on Overleaf using polyglossia and fontspec
- Multilingual typesetting on Overleaf using babel and fontspec
- International language support
- Quotations and quotation marks
- Arabic
- Chinese
- French
- German
- Greek
- Italian
- Japanese
- Korean
- Portuguese
- Russian
- Spanish
Document structure
- Sections and chapters
- Table of contents
- Cross referencing sections, equations and floats
- Indices
- Glossaries
- Nomenclatures
- Management in a large project
- Multi-file LaTeX projects
- Hyperlinks
Formatting
- Lengths in LaTeX
- Headers and footers
- Page numbering
- Paragraph formatting
- Line breaks and blank spaces
- Text alignment
- Page size and margins
- Single sided and double sided documents
- Multiple columns
- Counters
- Code listing
- Code Highlighting with minted
- Using colours in LaTeX
- Footnotes
- Margin notes
Fonts
Presentations
Commands
Field specific
- Theorems and proofs
- Chemistry formulae
- Feynman diagrams
- Molecular orbital diagrams
- Chess notation
- Knitting patterns
- CircuiTikz package
- Pgfplots package
- Typesetting exams in LaTeX
- Knitr
- Attribute Value Matrices
Class files
- Understanding packages and class files
- List of packages and class files
- Writing your own package
- Writing your own class