5

I've produced the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{circuitikz}
\begin{document}

\maketitle

\begin{circuitikz} \draw
                (2,2) node[nand port, fill=green] (NANDMIDA) {}
                (2,0) node[nand port] (NANDMIDB) {}
                (NANDMIDA.out) -- ++(0,-0.5) -- ($(NANDMIDB.in 1) +(0,0.5)$) -- (NANDMIDB.in 1)
                (NANDMIDB.out) -- ++(0,+0.5) -- ($(NANDMIDA.in 2) +(0,-0.5)$)--(NANDMIDA.in 2)
                (NANDMIDA.out) -- ++(0,-0.5) -- ($(NANDMIDB.in 1) +(0,0.5)$) -- (NANDMIDB.in 1)
                (NANDMIDB.out) -- ++(0,+0.5) -- ($(NANDMIDA.in 2) +(0,-0.5)$)--(NANDMIDA.in 2)
                


                ($(NANDMIDA.in 1) - (1, 0)$) node[nand port, anchor=out] (NANDTOPB) {}
                ($(NANDTOPB.out) + (0, 2)$) node[nand port, anchor=out, fill=red] (NANDTOPA) {}
                (NANDTOPA.out) -- ++(0,-0.5) -- ($(NANDTOPB.in 1) +(0,0.5)$) -- (NANDTOPB.in 1)
                (NANDTOPB.out) -- ++(0,+0.5) -- ($(NANDTOPA.in 2) +(0,-0.5)$)--(NANDTOPA.in 2)
                (NANDTOPA.out) -- ++(0,-0.5) -- ($(NANDTOPB.in 1) +(0,0.5)$) -- (NANDTOPB.in 1)
                (NANDTOPB.out) -- ++(0,+0.5) -- ($(NANDTOPA.in 2) +(0,-0.5)$)--(NANDTOPA.in 2)
                
                
                ($(NANDMIDB.in 2) - (1, 0)$) node[nand port, fill=blue, anchor=out] (NANDBOTTOMA) {}
                ($(NANDBOTTOMA.out) - (0, 2)$) node[nand port, anchor=out] (NANDBOTTOMB) {}
                (NANDBOTTOMA.out) -- ++(0,-0.5) -- ($(NANDBOTTOMB.in 1) +(0,0.5)$) -- (NANDBOTTOMB.in 1)
                (NANDBOTTOMB.out) -- ++(0,+0.5) -- ($(NANDBOTTOMA.in 2) +(0,-0.5)$)--(NANDBOTTOMA.in 2)
                (NANDBOTTOMA.out) -- ++(0,-0.5) -- ($(NANDBOTTOMB.in 1) +(0,0.5)$) -- (NANDBOTTOMB.in 1)
                (NANDBOTTOMB.out) -- ++(0,+0.5) -- ($(NANDBOTTOMA.in 2) +(0,-0.5)$)--(NANDBOTTOMA.in 2)
                
                (NANDTOPB.out) -- (NANDMIDA.in 1)
                (NANDBOTTOMA.out) -- (NANDMIDB.in 2)
                % LINK FROM NANDTOPB OUT TO NANDBOTTOMA IN1
                (NANDTOPB.out) -- ++(0,-0.5) -- ($(NANDBOTTOMA.in 1) +(0,+0.5)$)--(NANDBOTTOMA.in 1) 
                % LINK FROM NANDTOPA IN 1 TO NANDBOTTOMA IN2
                (NANDTOPA.in 1) -- ++(-1,0) -- ($(NANDBOTTOMA.in 2) +(-1,0)$)--(NANDBOTTOMA.in 2)
                % CLOCK LINK FROM NANDTOPB IN2 TO NANDTOPB IN1.5
                (NANDTOPB.in 2) -- ++(-1.5,0) -- ($(NANDBOTTOMA.in 1) +(-1.5,-0.3)$)--($(NANDBOTTOMA.in 1)+(0.5, -0.3)$)
                ;
                
                \draw (NANDMIDA.out) to [short, -o, l=$Q$] ++(0.5, 0);
                \draw (NANDMIDB.out) to [short, -o, l=$\overline{Q}$] ++(0.5, 0);
                \draw (NANDBOTTOMB.in 2) to [short, -o, l=$\emph{data}$]++(-1,0);
                \draw ($(NANDTOPB.in 2)+(-1.5,0)$) to [short, -*] ($(NANDBOTTOMA.in 1) +(-1.5,1)$) coordinate (clockNode);
                \draw (clockNode) to [short, -o, l=$\emph{clock}$] ++(-1.5, 0);
                \draw (NANDTOPB.out) to [short, -*] ++(0,0);
                \draw (NANDBOTTOMA.out) to [short, -*] ++(0.0,0);

            \end{circuitikz}

\end{document}

and now I would like to highlight specific paths in the circuit differently like in the following picture:

enter image description here

I tried adding the color name between square brackets before the link I want to color but when I do so it will change the color for every link in the circuit.

1

2 Answers 2

6

As starting point:

\documentclass[margin=3mm]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{circuitikz}[semithick]
\draw   (2,2) node[nand port, fill=green]   (N1a) {}
        (2,0) node[nand port]               (N1b) {}
        (N1a.out) -- ++(0,-0.5) -- ($(N1b.in 1) +(0, 0.5)$) -- (N1b.in 1)
        (N1b.out) -- ++(0,+0.5) -- ($(N1a.in 2) +(0,-0.5)$) -- (N1a.in 2)
        
        (N1a.out) to [short,-o] ++(0.5,0) node[right] {$Q$}
        (N1b.out) to [short,-o] ++(0.5,0) node[right] {$\bar{Q}$}
%
        (N1a.in 1) -- ++ (-1,0) node[nand port, anchor=out, left] (N2b) {}
                      ++ ( 0,2) node[nand port, anchor=out, left, fill=red] (N2a) {} 
        ;
\draw[blue]
        (N1b.in 2) -- ++ (-1,0) node[nand port, anchor=out, number inputs=3,
                                     left, fill=cyan] (N3b) {}
                      ++ (0,-2) node[nand port, anchor=out, left] (N3a) {}
        (N3b.out) -- ++(0,-0.5) -- ($(N3a.in 1) +(0,0.5)$) -- (N3a.in 1)
        (N3b.in 1) --++(0, 0.5) -- ($(N2b.out) +(0,-0.5)$) -- (N2b.out)
        (N2b.out) -- ++(0, 0.5) -- ($(N2a.in 2) +(0,-0.5)$) -- (N2a.in 2)
        ;
\path[draw=green]
        (N2a.out) -- ++(0,-0.5) -- ($(N2b.in 1) +(0, 0.5)$) -- (N2b.in 1)
        (N3a.out) -- ++(0,+0.5) -- ($(N3b.in 3) +(0,-0.5)$) -- (N3b.in 3)
        (N3b.in 3) --++(-0.5,0) |- (N2a.in 1)
        (N3a.in 2) to[short,-o, l=\emph{data}] ++(-1,0)
        ;
\draw   (N3b.in 2) -- ++ (-1,0) |- (N2b.in 2) coordinate[pos=0.25] (in)
        (in) to [short, -o, l=\emph{clock}] ++ (-1.2,0)
        ;
    \end{circuitikz}
\end{document}

enter image description here

Edit: or with dots at line connections:

\documentclass[margin=3mm]{standalone}
\usepackage{circuitikz}

\begin{document}
    \begin{circuitikz}[semithick]
\draw   (2,2) node[nand port, fill=green]   (N1a) {}
        (2,0) node[nand port]               (N1b) {}
        (N1a.out) -- ++(0,-0.5) -- ($(N1b.in 1) +(0, 0.5)$) -- (N1b.in 1)
        (N1b.out) -- ++(0,+0.5) -- ($(N1a.in 2) +(0,-0.5)$) -- (N1a.in 2)
        
        (N1a.out) to [short,*-o] ++(0.5,0) node[right] {$Q$}
        (N1b.out) to [short,*-o] ++(0.5,0) node[right] {$\bar{Q}$}
%
        (N1a.in 1) to [short,-*] ++ (-1,0) node[nand port, anchor=out, left] (N2b) {}
                      ++ ( 0,2) node[nand port, anchor=out, left, fill=red] (N2a) {} 
        ;
\draw[blue]
        (N1b.in 2) to [short,-*] ++ (-1,0) node[nand port, anchor=out, number inputs=3,
                                     left, fill=cyan] (N3b) {}
                      ++ (0,-2) node[nand port, anchor=out, left] (N3a) {}
        (N3b.out) -- ++(0,-0.5) -- ($(N3a.in 1) +(0,0.5)$) -- (N3a.in 1)
        (N3b.in 1) --++(0, 0.5) -- ($(N2b.out) +(0,-0.5)$) -- (N2b.out)
        (N2b.out) -- ++(0, 0.5) -- ($(N2a.in 2) +(0,-0.5)$) -- (N2a.in 2)
        ;
\path[draw=green]
        (N2a.out) -- ++(0,-0.5) -- ($(N2b.in 1) +(0, 0.5)$) -- (N2b.in 1)
        (N3a.out) -- ++(0,+0.5) -- ($(N3b.in 3) +(0,-0.5)$) -- (N3b.in 3)
        (N3b.in 3) to[short,*-] ++ (-0.5,0) |- (N2a.in 1)
        (N3a.in 2) to[short,-o, l=\emph{data}] ++(-1,0)
        ;
\draw   (N3b.in 2) -- ++ (-1,0) |- (N2b.in 2) coordinate[pos=0.25] (in)
        (in) to [short, *-o, l=\emph{clock}] ++ (-1.2,0)
        ;
    \end{circuitikz}
\end{document}

enter image description here

2

Just to add information to the (nice) Zarko's answer, let me copy here (because I wrote that, so I can) the underlying reasons, which you can find in the FAQ in the manual (around page 204):

copy of FAQ 8.2 of the circuitikz manual, on apr 19 2022

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .