Clip text from a drawn rectangle in Tikz

fillpath-clippingtikz-pgftransparency

Rather than defining a specific color for some text in a drawn box, I want the text to be clipped from the box so that the paper color is visible. Here's the MWE:

\documentclass{article}
\pagestyle{empty}

\usepackage{tikz}
\usepackage{geometry}


\usetikzlibrary{positioning,calc,intersections}

\geometry{papersize={70mm, 20mm}}

\newcommand\placeTextBox[7]{
\begin{tikzpicture}[remember picture,overlay]
\fontsize{#5}{#5}\selectfont
\filldraw [fill=#7, draw=#7, line width=0.25mm, rounded corners=0.25mm]
     ($(current page.south west)+(#1,#2)-(#3/2,#4/2)$) rectangle 
     ($(current page.south west)+(#1,#2)+(#3/2,#4/2)$)
      node[pos=0.5, text depth=0pt, text=white] {#6};
\end{tikzpicture}
}

\tikzstyle{reverseclip}=[insert path={(current page.north east) --
  (current page.south east) --
  (current page.south west) --
  (current page.north west) --
  cycle}
]

\begin{document}
\placeTextBox{35mm}{10mm}{30mm}{3.1mm}{3.0mm}{\textbf{Transparent text}}{black}
\end{document}

This gives me the following result:

enter image description here

However, instead of using "text=white" in the node for the text, what do I need to do in order to have the text clipped from the black box to get the red paper color to show through?

Best Answer

You can use a knockout group, but is is not supported by many viewers. You can also use a tikzfadingfrompicture like this

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{fadings, patterns}
\begin{tikzfadingfrompicture}[name=myfading]
\node[fill=transparent!0] {\textbf Transparent text};
\end{tikzfadingfrompicture}
\begin{document}
\begin{tikzpicture}
\pattern [pattern=checkerboard,pattern color=black!30] (-2,-1) rectangle (2,1);
\fill[red, path fading=myfading, fit fading=false] (-2,-1) rectangle (2,1);
\end{tikzpicture}
\end{document}

Red node with transparent text on checkerboard pattern