% !TeX TXS-program:compile = txs:///arara
% arara: lualatex: {shell: no, synctex: no, interaction: batchmode}

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}
\usepackage{codehigh}

%====MACRO
\usepackage{tikz,xstring,simplekv,listofitems}
\usetikzlibrary{calc}
\defKV[bicolortxt]{colors=\def\bicolortxtcols{#1},style=\def\bicolortxtsttyle{#1},intdelta=\def\bicolortxtdelta{#1},paralcolors=\def\bicolortxtcolstrapez{#1}}
\setKVdefault[bicolortxt]{colors={red/blue},style=midh,intdelta=0.66,paralcolors={red/blue/orange/gray}}

\NewDocumentCommand\bicolortxt{ O{} m }{%
	\restoreKV[bicolortxt]%
	\setKV[bicolortxt]{#1}%
	\IfStrEq{\bicolortxtsttyle}{paral}%
		{%
			\setsepchar[.]{/}%
			\readlist*\bicolortrapez{\bicolortxtcolstrapez}%
		}%
		{%
			\StrCut{\bicolortxtcols}{/}{\bicolorabove}{\bicolorbelow}%
		}%
	\tikz[baseline=(l.base),inner sep=0pt,outer sep=0pt]{%
		\node[inner sep=0pt,outer sep=0pt](l){\phantom{#2}};
		\coordinate (lnw) at ([shift={(-0.5\pgflinewidth,0.5\pgflinewidth)}]l.north west) ;
		\coordinate (ln) at ([shift={(0,0.5\pgflinewidth)}]l.north) ;
		\coordinate (lne) at ([shift={(0.5\pgflinewidth,0.5\pgflinewidth)}]l.north east) ;
		\coordinate (le) at ([shift={(0.5\pgflinewidth,0)}]l.east) ;
		\coordinate (lse) at ([shift={(0.5\pgflinewidth,-0.5\pgflinewidth)}]l.south east) ;
		\coordinate (ls) at ([shift={(0,-0.5\pgflinewidth)}]l.south) ;
		\coordinate (lsw) at ([shift={(-0.5\pgflinewidth,-0.5\pgflinewidth)}]l.south west) ;
		\coordinate (lw) at ([shift={(-0.5\pgflinewidth,0)}]l.west) ;
		\IfStrEqCase{\bicolortxtsttyle}{%
			{ellips}%
				{%
					\coordinate (lcircn) at ($(l.center)!\bicolortxtdelta!(l.north)$) ;
					\coordinate (lcirce) at ($(l.center)!\bicolortxtdelta!(l.east)$) ;
				}%
			{rect}%
				{%
					\coordinate (lrectnw) at ($(l.center)!\bicolortxtdelta!(l.north west)$) ;
					\coordinate (lrectse) at ($(l.center)!\bicolortxtdelta!(l.south east)$) ;
				}%
			{paral}%
				{%
					\coordinate (ltrapna) at ($(l.north west)!0.333!(l.north east)$) ;
					\coordinate (ltrapnb) at ($(l.north west)!0.666!(l.north east)$) ;
					\coordinate (ltrapsa) at ($(l.south west)!0.333!(l.south east)$) ;
					\coordinate (ltrapsb) at ($(l.south west)!0.666!(l.south east)$) ;
				}%
		}%
		\begin{scope}
			\IfStrEqCase{\bicolortxtsttyle}{%
				{midh}{\clip(ls)rectangle(lnw);\node[\bicolorabove]at(l){#2};}%
				{midv}{\clip(lnw)rectangle(le);\node[\bicolorabove]at(l){#2};}%
				{ndiag}{\clip(lnw)--(lne)--(lse)--cycle;\node[\bicolorabove]at(l){#2};}%
				{sdiag}{\clip(lsw)--(lnw)--(lne)--cycle;\node[\bicolorabove]at(l){#2};}%
				{ellips}{\clip(lsw)rectangle(lne);\node[\bicolorabove]at(l){#2};}%
				{rect}{\clip(lsw)rectangle(lne);\node[\bicolorabove]at(l){#2};}%
				{paral}{\clip(lsw)--(lnw)--(ltrapna)--cycle;\node[{\bicolortrapez[1]}]at(l){#2};}%
			}%
		\end{scope}
		\begin{scope}
			\IfStrEqCase{\bicolortxtsttyle}{%
				{midh}{\clip(ls)rectangle(lne);\node[\bicolorbelow]at(l){#2};}%
				{midv}{\clip(lsw)rectangle(le);\node[\bicolorbelow]at(l){#2};}%
				{ndiag}{\clip(lsw)--(lnw)--(lse)--cycle;\node[\bicolorbelow]at(l){#2};}%
				{sdiag}{\clip(lsw)--(lne)--(lse)--cycle;\node[\bicolorbelow]at(l){#2};}%
				{ellips}{\clip(lsw)rectangle(lne);\pgfpathellipse{\pgfpointanchor{l}{center}}{\pgfpointanchor{lcirce}{center}}{\pgfpointanchor{lcircn}{center}}\pgfusepath{clip}\node[\bicolorbelow]at(l){#2};}%
				{rect}{\clip(lrectnw)rectangle(lrectse);\node[\bicolorbelow]at(l){#2};}%
				{paral}{\clip(lsw)--(ltrapna)--(ltrapnb)--(ltrapsa)--cycle;\node[{\bicolortrapez[2]}]at(l){#2};}%
			}%
		\end{scope}
		\IfStrEq{\bicolortxtsttyle}{paral}%
			{%
				\begin{scope}%3
					\clip(ltrapsa)--(ltrapnb)--(lne)--(ltrapsb)--cycle;\node[{\bicolortrapez[3]}]at(l){#2};
				\end{scope}
				\begin{scope}%
					\clip(ltrapsb)--(lne)--(lse)--cycle;\node[{\bicolortrapez[4]}]at(l){#2};
				\end{scope}
			}%
			{}%
	}%
}

\def\sampleformula{$\displaystyle\int_0^1 \dfrac{1+x}{1+x^2}\,\mathrm{d}x$}
\def\sampletxt{But I must explain to you how all this mistaken idea of denouncing pleasure.}
\def\samplenum{1500}

\begin{document}

\begin{codehigh}[language=latex/latex2]
\def\sampleformula{$\displaystyle\int_0^1 \dfrac{1+x}{1+x^2}\,\mathrm{d}x$}
\def\sampletxt{But I must explain to you how all this mistaken idea of denouncing pleasure.}
\def\samplenum{1500}
\end{codehigh}

\begin{demohigh}[language=latex/latex2]
\bicolortxt[style=midh]{\sampleformula} 
or \bicolortxt[colors=violet/magenta,style=midv]{\sampleformula} 
or \bicolortxt[colors=darkgray/olive,style=ndiag]{\sampleformula} 
or \bicolortxt[colors=orange/teal,style=sdiag]{\sampleformula}
or \bicolortxt[colors=orange/teal,style=ellips]{\sampleformula}
or \bicolortxt[colors=pink/violet,style=rect]{\sampleformula}
\end{demohigh}

\begin{demohigh}[language=latex/latex2]
\bicolortxt[style=midh]{\sampletxt}\par
\bicolortxt[colors=violet/magenta,style=midv]{\sampletxt}\par
\bicolortxt[colors=darkgray/olive,style=ndiag]{\sampletxt}\par
\bicolortxt[colors=orange/teal,style=sdiag]{\sampletxt}\par
\bicolortxt[colors=orange/teal,style=ellips]{\sampletxt}\par
\bicolortxt[colors=pink/violet,style=rect]{\sampletxt}
\end{demohigh}

\begin{demohigh}[language=latex/latex2]
\bicolortxt[style=midh]{\parbox{2.5cm}{\sampletxt}}~
\bicolortxt[colors=violet/gray,style=midv]{\parbox{2.5cm}{\sampletxt}}~
\bicolortxt[colors=darkgray/olive,style=ndiag]{\parbox{2.5cm}{\sampletxt}}~
\bicolortxt[colors=orange/cyan,style=sdiag]{\parbox{2.5cm}{\sampletxt}}~
\bicolortxt[colors=pink/violet,style=ellips]{\parbox{2.5cm}{\sampletxt}}
\bicolortxt[colors=pink/violet,style=ellips,intdelta=0.85]{\parbox{2.75cm}{\sampletxt}}~
\bicolortxt[colors=cyan/darkgray,style=rect]{\parbox{2.5cm}{\sampletxt}}
\end{demohigh}

\begin{demohigh}[language=latex/latex2]
\bicolortxt[style=paral]{\parbox{3.75cm}{\sampletxt}}
\end{demohigh}

\begin{demohigh}[language=latex/latex2]
\bicolortxt[style=midh]{\samplenum}\par
\bicolortxt[colors=violet/magenta,style=midv]{\samplenum}\par
\bicolortxt[colors=darkgray/olive,style=ndiag]{\samplenum}\par
\bicolortxt[colors=orange/teal,style=sdiag]{\samplenum}\par
\bicolortxt[colors=orange/teal,style=ellips]{\samplenum}
\end{demohigh}

\end{document}