#StackBounty: #macros #color #listings #languages How do I customize Circuit_macros in listings?

Bounty: 50

MWE;

documentclass{article}
usepackage{xcolor}
usepackage{listings}
definecolor{Others}{RGB}{0,110,40}      % Green
definecolor{Character}{RGB}{146,76,157} % Purple
definecolor{Number}{RGB}{176,128,0}     % Brown

lstdefinestyle{circuit_macros}
{
basicstyle=scriptsizettfamilynull,
literate=*{0}{{textcolor{Number}{0}}}{1}%
      {1}{{textcolor{Number}{1}}}{1}%
       {2}{{textcolor{Number}{2}}}{1}%
       {3}{{textcolor{Number}{3}}}{1}%
       {4}{{textcolor{Number}{4}}}{1}%
       {5}{{textcolor{Number}{5}}}{1}%
       {6}{{textcolor{Number}{6}}}{1}%
       {7}{{textcolor{Number}{7}}}{1}%
       {8}{{textcolor{Number}{8}}}{1}%
       {9}{{textcolor{Number}{9}}}{1}%
       {.0}{{textcolor{Number}{.0}}}{1}%
       {.1}{{color{Number}{.1}}}{1}%
       {.2}{{color{Number}{.2}}}{1}%
       {.3}{{color{Number}{.3}}}{1}%
       {.4}{{color{Number}{.4}}}{1}%
       {.5}{{color{Number}{.5}}}{1}%
       {.6}{{color{Number}{.6}}}{1}%
       {.7}{{color{Number}{.7}}}{1}%
       {.8}{{color{Number}{.8}}}{1}%
       {.9}{{color{Number}{.9}}}{1}%
       {(}{{color{Character}{(}}}{1}%
       {)}{{color{Character}{)}}}{1}%
       {/}{{color{black}{/}}}{1}% 
       {:}{{color{Character}{:}}}{1}%
       {;}{{color{black}{;}}}{1}%
       {,}{{color{black}{,}}}{1}%
       {.}{{color{black}{.}}}{1}%
       {(}{{color{Character}{(}}}{1}%
       {)}{{color{Character}{)}}}{1}%
       ,
morekeywords={In1,In2,In3},
keywordstyle=color{black},
morekeywords=[2]{scale,above,with,at,Here,line,to,end,start,from,ljust},
keywordstyle=[2]{bfcolor{black}},
morekeywords=[3]{PS,PE},
keywordstyle=[3]{color{Character}},
morekeywords=[4]{corner,Out,In1,In2,In3,In4},
keywordstyle=[4]{color{black}},
morekeywords=[5]{down_,up_,elen_,right_,log_init,NOT_gate,dot,AND_gate,OR_gate},
keywordstyle=[5]color{Others},
sensitive=false,
comment=[l][color{gray}]{#},
string=[b]",
stringstyle=color{red},
}

begin{document}

begin{lstlisting}[style=circuit_macros]
% `logic.cir'

.PS

scale=25.4
log_init

#setrgb(0,0,1) # Blue Color
#dot(,,1)

O:(0,0)

"A" at Here above;DA:dot(,,1);
line down_ elen_/2 with .start at DA.s;dot;{A:line down_ 3.5*elen_};line right_ elen_/2;corner;
line down_ elen_/2;NOT_gate;LA:line down_ to (Here.x,A.end.y);

"B" at (elen_,0) above;DB:dot(,,1);
line down_ elen_/2 with .start at DB.s;dot;{B:line down_ 3.5*elen_};line right_ elen_/2;corner;
line down_ elen_/2;NOT_gate;LB:line to (Here.x,B.end.y);

"C" at (2*elen_,0) above;DC:dot(,,1);
line down_ elen_/2 with .start at DC.s;dot;{C:line down_ 3.5*elen_};line right_ elen_/2;corner;
line down_ elen_/2;NOT_gate;LC:line to (Here.x,C.end.y);

right_

X1:AND_gate(2) at (3*elen_,LC.y+15)
line from X1.In1 to (LA.x,X1.In1.y);dot
line from X1.In2 to (LB.x,X1.In2.y);dot

X2:AND_gate(2) at (X1.x,X1.y-15);
line from X2.In1 to (LB.x,X2.In1.y);dot
line from X2.In2 to (C.x,X2.In2.y);dot

X3:AND_gate(3) at (X1.x,X1.y-30);
line from X3.In1 to (A.x,X3.In1.y);dot
line from X3.In2 to (B.x,X3.In2.y);dot
line from X3.In3 to (LC.x,X3.In3.y);dot

line right_ elen_ from X2.Out;X4:OR_gate(3) with .In2 at Here;
line right_ elen_/2 from X1.Out;corner;line down_ to (Here.x,X4.In1.y);corner;line to X4.In1
line right_ elen_/2 from X3.Out;corner;line up_ to (Here.x,X4.In3.y);corner;line to X4.In3

line right_ elen_/2 from X4.Out; "X" ljust;dot(,,1);

.PE
end{lstlisting}
end{document}

And output (Of course there are errors. This was what I could do.)

enter image description here

But original output

enter image description here

What I want to do;

1) codes with digits such as In1, In2 should be black.

2) at the end of the :or characters starting ; and ending : must be purple. Such as ;DA:, X1: written in source code. Other DA, X1 should be black.

3) When I copy and paste the output into the notebook, there is a space between characters. So when I paste it into its own program it gives an error.

enter image description here

Are these possible?

Related to: advanced string highlighting in listings


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.