I am trying to colour letters/words/strings with multiple bands of colour per string. It would look like the flag of Ireland/Russia/Germany is behind the text. I would like my final function to let me use the text as if it were normal (i.e, without a larger bounding box).
I've added an outlined sample which works as I want, which is like normal text. I also want it to be outlined like this but that seems easier anyway.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fadings}
\usepackage{graphicx}
\usepackage{pslatex}
\usepackage{xcolor}
\usepackage{pdfrender}
\usepackage{pst-text}
\usepackage{pst-grad}
\usepackage{calc}
\begin{document}
\newcommand{\sample}{\bfseries sample}
\textpdfrender{
TextRenderingMode=FillStroke,
LineWidth=.2pt,
LineJoinStyle=1,
FillColor=pink
}
\sample \ works well with other text.%
\newlength{\samplewidth}
\newlength{\sampleheight}
\newlength{\colourheight}
\newlength{\bandYone}
\newlength{\bandYtwo}
\newlength{\bandYthree}
\newlength{\bandYfour}
{\setlength{\samplewidth}{\widthof{\sample}}
\setlength{\sampleheight}{\totalheightof{\sample}}
\setlength{\colourheight}{.3333333333\sampleheight}
\setlength{\bandYone}{-.5\sampleheight}
\setlength{\bandYtwo}{\bandYone}
\addtolength{\bandYtwo}{\colourheight}
\setlength{\bandYthree}{\bandYtwo}
\addtolength{\bandYthree}{\colourheight}
\setlength{\bandYfour}{\bandYthree}
\addtolength{\bandYfour}{\colourheight}
\framebox{%
\begin{tikzfadingfrompicture}[name=A]
\path[clip] (-.5\samplewidth,-.5\sampleheight) rectangle (.5\samplewidth,.5\sampleheight);
\node[scale=1, transparent!0, inner sep=0pt, outer sep=0pt] at (0,0) {\sample};
\end{tikzfadingfrompicture}
\begin{tikzfadingfrompicture}[name=B]
\path[clip] (-.5\samplewidth,-.5\sampleheight) rectangle (.5\samplewidth,.5\sampleheight);
\node[scale=1,transparent!0, inner sep=0pt, outer sep=0pt] at (0,0) {\sample};
\end{tikzfadingfrompicture}
\begin{tikzfadingfrompicture}[name=C]
\path[clip] (-.5\samplewidth,-.5\sampleheight) rectangle (.5\samplewidth,.5\sampleheight);
\node[scale=1,transparent!0, inner sep=0pt, outer sep=0pt] at (0,0) {\sample};
\end{tikzfadingfrompicture}
\begin{tikzpicture}
\path[clip] (-.5\samplewidth,-.5\sampleheight) rectangle (.5\samplewidth,.5\sampleheight);
\node[scale=1,thick, inner sep=0pt, outer sep=0pt] at (0,0) {\sample};
\path[path fading=A,fill=red,fit fading=false] (-.5\samplewidth,\bandYone) rectangle (.5\samplewidth,\bandYtwo);
\path[path fading=B,fill=green,fit fading=false] (-.5\samplewidth,\bandYtwo) rectangle (.5\samplewidth,\bandYthree);
\pathpath fading=C,fill=yellow,fit fading=false rectangle (.5\samplewidth,\bandYfour);
%\path[draw=blue] (-10,-1) rectangle (10,0);
%\path[draw=red] (-10,0) rectangle (10,1);
\end{tikzpicture}
} %Framebox
}
does not work well as it adds space around the text.
\end{document}




pslatex(which I wrote) should not be used this century. – David Carlisle Nov 17 '21 at 22:38