梅威瑟:
\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=\scriptsize\ttfamily\null,
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]{\bf\color{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}
并输出(当然有错误。这是我能做的。)
但原始输出
我想做的事;
In1
带有诸如之类的数字的代码In2
应为黑色。:
或 结尾的字符的起始;
和结束:
必须为紫色。例如;DA:
,X1:
源代码中写的 。其他DA
,X1
应为黑色。当我将输出复制并粘贴到笔记本中时,字符之间有一个空格。因此,当我将其粘贴到其自己的程序中时,会出现错误。
这些可能吗?
答案1
\documentclass[a4paper,11pt]{article}
%\documentclass[a4paper,11pt]{standalone}% for demontration only!
\usepackage[top=0.75in, bottom=0.75in, left=0.75in, right=0.75in]{geometry}
%\usepackage{showframe}% for demontration only!
\pagestyle{empty}
\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=\scriptsize\ttfamily\null,
literate=*{,}{{\color{black}{,}}}1%
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%
({{\color{Character}{(}}}1%
){{\color{Character}{)}}}1%
/{{\color{black}{/}}}1%
:{{\color{Character}{:}}}1%
;{{\color{black}{;}}}1%
.{{\color{black}{.}}}1%
({{\color{Character}{(}}}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{black}{*}}}2%
{O:}{{\color{Character}{O:}}}2%
{A.}{{\color{black}{A.}}}2%
{B.}{{\color{black}{B.}}}2%
{C.}{{\color{black}{C.}}}2%
{A:}{{\color{Character}{A:}}}2%
{B:}{{\color{Character}{B:}}}2%
{C:}{{\color{Character}{C:}}}2%
{DA:}{{\color{Character}{DA:}}}3%
{DB:}{{\color{Character}{DB:}}}3%
{DC:}{{\color{Character}{DC:}}}3%
{LA.}{{\color{black}{LA.}}}3%
{LB.}{{\color{black}{LB.}}}3%
{LC.}{{\color{black}{LC.}}}3%
{LA:}{{\color{Character}{LA:}}}3%
{LB:}{{\color{Character}{LB:}}}3%
{LC:}{{\color{Character}{LC:}}}3%
{X1}{{\color{black}{X1}}}2%
{X1:}{{\color{Character}{X1:}}}3%
{X2}{{\color{black}{X2:}}}2%
{X2:}{{\color{Character}{X2:}}}3%
{X3}{{\color{black}{X3:}}}2%
{X3:}{{\color{Character}{X3:}}}3%
{X4}{{\color{black}{X4:}}}2%
{X4:}{{\color{Character}{X4:}}}3%
{"A"}{{\bf\color{red}{"A"}}}3%
{"B"}{{\bf\color{red}{"B"}}}3%
{"C"}{{\bf\color{red}{"C"}}}3%
{"X"}{{\color{red}{"X"}}}3%
{In1}{{\color{black}{In1}}}3%
{In2}{{\color{black}{In2}}}3%
{In3}{{\color{black}{In3}}}3%
{In4}{{\color{black}{In4}}}3%
,
emph={scale,above,with,at,Here,line,to,end,start,from,ljust},
emphstyle={\bf\color{black}},
morekeywords=[3]{PS,PE},
keywordstyle=[3]{\color{Character}},
morekeywords=[5]{down_,up_,elen_,right_,log_init,NOT_gate,dot,AND_gate,OR_gate},
keywordstyle=[5]\color{Others},
sensitive=false,
morecomment=[l][\color{gray}]{\#},
}
\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}