Using \coltex
from OPmac tricks in OpTeX
#133
Answered
by
vlasakm
robertbachmann
asked this question in
Q&A
-
I'm using the code from https://petr.olsak.net/opmac-tricks-e.html#coltext % !TeX program = optex
\useOpTeX \fontfam[lm]
\newdimen\hyphdim
\let\hyphentt=\tentt \hyphdim=\fontdimen6\hyphentt \divide\hyphdim by2
\def\hyphenprocess#1{\def\tmp{#1}\let\listwparts=\undefined
\setbox0=\vbox\bgroup\hyphenpenalty=-10000 \hsize=0pt \hfuzz=\maxdimen
\edef\hychar{\hyphenchar\hyphentt=\the\hyphenchar\hyphentt}\hyphenchar\hyphentt=45
\def~{\nobreak\hskip.5em\relax}\tt\noindent\hskip0pt\relax #1\par \hychar
\hyphenprocessA
\expandafter\let\expandafter\listwparts\expandafter\empty
\expandafter\hyphenprocessB\listwparts
}
\def\hyphenprocessA{\setbox2=\lastbox
\ifvoid2 \egroup \else \unskip \unpenalty
\setbox2=\hbox{\unhbox2}%
\tmpnum=\wd2 \advance\tmpnum by100 \divide\tmpnum by\hyphdim
\ifx\listwparts\undefined \xdef\listwparts{,}%
\else \advance\tmpnum by-1 \xdef\listwparts{\the\tmpnum,\listwparts}\fi
\expandafter\hyphenprocessA \fi
}
\def\hyphenprocessB#1,{\if^#1^\expandafter\hyphenprocessC
\else \tmpnum=#1 \expandafter\hyphenprocessD\tmp\end
\fi
}
\def\hyphenprocessC{\expandafter\addto\expandafter\listwparts\expandafter{\tmp}}
\def\hyphenprocessD#1#2\end{\addto\listwparts{#1}%
\advance\tmpnum by-1
\ifnum\tmpnum>0 \def\next{\hyphenprocessD#2\end}%
\else
\def\tmp{#2}\def\next{\addto\listwparts{\-}\expandafter\hyphenprocessB}\fi
\next
}
%%%%%%
\def\coltextstrut{height2ex depth.6ex}
\def\coltext#1#2#3{{\localcolor\let\Tcolor=#1\let\Bcolor=#2\relax
\setbox1=\hbox{-\kern.05em}%
\setbox1=\hbox{{\Bcolor\vrule\coltextstrut width\wd1}\kern-.05em\llap{\Tcolor -}}%
\def\-{\discretionary{\copy1}{}{}}%
\def\uline##1{\skip0=##1\advance\skip0 by.05em
\Bcolor\leaders \vrule\coltextstrut\hskip\skip0 \hskip-.05em\relax}%
\def\uspace{\fontdimen2\font plus\fontdimen3\font minus\fontdimen4\font}%
\def~{\egroup\hbox{\uline{\wd0}\llap{\Tcolor\copy0}}\nobreak{\uline\uspace}\relax \setbox0=\hbox\bgroup}%
\leavevmode\coltextA #3 {} }}
\def\coltextA#1 {\ifx^#1^\unskip\unskip\else
\hyphenprocess{#1}\expandafter\coltextB\listwparts\-\end
\expandafter\coltextA\fi}
\def\coltextB#1\-#2\end{\ifx^#2^\coltextC{#1}\else
\coltextD{#1}\def\next{\coltextB#2\end}\expandafter\next\fi}
\def\coltextC#1{\setbox0=\hbox{#1}\hbox{\uline{\wd0}\hbox{\llap{\Tcolor\copy0}}}\uline\uspace\relax}
\def\coltextD#1{\setbox0=\hbox{#1}\hbox{\uline{\wd0}\llap{\Tcolor\copy0}}\-}
%%%%%%
Lorem ipsum dolor sit amet. \coltext\Red\Yellow{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.} Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
\bye |
Beta Was this translation helpful? Give feedback.
Answered by
vlasakm
May 3, 2023
Replies: 2 comments
-
The way this OPmac trick uses colors is incompatible with the "new" implementation of colors (OpTeX 1.04+). Here is a fix: #57 (comment). |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
robertbachmann
-
I upgraded the OpTeX trick web page. Thank you for noticing. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The way this OPmac trick uses colors is incompatible with the "new" implementation of colors (OpTeX 1.04+).
Here is a fix: #57 (comment).