pgf's and pstricks's opacity is not working

Update

Ghostscript-9.52 introduced new operators for setting fill and stroke opacity (.setconstantfillopacity, .setconstantstrokeopacity), deprecating the hitherto existing .setopacityalpha. The upcoming GS version 9.53 will produce warning messages if the old operator is used.

Furthermore, a new gs commandline option for activating opacity features was introduced:

ps2pdf -dALLOWPSTRANSPARENCY myfile.ps myfile.pdf

Overleaf users should refer to this answer, https://tex.stackexchange.com/a/559098, if they want to enable transparency with the dvi/ps/pdf route. Many Linux distributions, and perhaps MiKTeX (with built-in Ghostscript) on Windows, still use GS-9.50 as default installation. For this version, option -dNOSAFER is still needed. See bottom of this answer.

TikZ/pgf

The development version on GitHub was updated recently to support the new operators (with fallback-option when using older GS versions.). Also, the GitHub version supports Blend Modes and Transparency Groups.

Instructions for installing the development version within TeXLive-2020 are given on pgf's home page https://github.com/pgf-tikz/pgf

enter image description here

\documentclass[border=3pt,varwidth]{standalone}

\usepackage{tikz}
\usetikzlibrary {patterns,shapes.symbols}

\begin{document}
%\begin{preview}
  \begin{tikzpicture}[thick,fill opacity=0.5]
    \filldraw[fill=red] (0:1cm) circle (12mm);
    \filldraw[fill=green] (120:1cm) circle (12mm);
    \filldraw[fill=blue] (-120:1cm) circle (12mm);
  \end{tikzpicture}
  \tikz {
    \begin{scope}[transparency group]
      \begin{scope}[blend mode=screen]
        \fill[red!90!black] ( 90:.6) circle (1);
        \fill[green!80!black] (210:.6) circle (1);
        \fill[blue!90!black] (330:.6) circle (1);
      \end{scope}
    \end{scope}
  }

  \begin{tikzpicture}
    \shade [left color=red,right color=blue] (-2,-1) rectangle (2,1);
    \begin{scope}[transparency group=knockout]
      \fill [white] (-1.9,-.9) rectangle (1.9,.9);
      \node [opacity=0,font=\fontencoding{T1}\fontfamily{ptm}\fontsize{45}{45}\bfseries] {Ti\emph{k}Z};
    \end{scope}
  \end{tikzpicture}
  \begin{tikzpicture}[opacity=0.5]
    \begin{scope}[transparency group]
      \draw [line width=5mm] (0,0) -- (2,2);
      \draw [line width=5mm] (2,0) -- (0,2);
    \end{scope}
  \end{tikzpicture}
%\end{preview}
  
\end{document}

PSTricks

To avoid warnings emitted by the future GS 9.53 version, the following line may be added just before \begin{document}:

\special{ps: /.setopacityalpha {dup .setfillconstantalpha  .setstrokeconstantalpha} bind def}   

Due to recently discovered Ghostscript vulnerabilities, a number of operations during format conversion, including transparency related operations, have been disabled for default usage, beginning with GS version 9.24.

They can still be accessed in unsafe operation mode of Ghostscript, which must be explicitly enabled by the user.

Enable unsafe mode with the -dNOSAFER option:

ps2pdf -dNOSAFER myfile.ps myfile.pdf

Of course, this may not be done for PS files of untrusted origin.


I'm using Kile. In Kile I use the pdflatex command with the -shell-escape option. For working with opacity I have found this solution. Use the auto-pdf package with this option: \usepackage[pspdf={-dDELAYSAFER}]{auto-pst-pdf}