circuitikz / circuitikz

CircuiTikZ TeX/LaTeX package for drawing circuits
https://circuitikz.github.io/circuitikz
418 stars 63 forks source link

how to use other shape for a node like triangle (for european invert/not symbol)? #679

Closed goyalyashpal closed 1 year ago

goyalyashpal commented 1 year ago

The required shape is an open/unfilled right triangle which is only on one side of the wire i.e. its origin anchor.

texstudio_dNE3e5kV58

%% Page 157 4.22.7 CircuiTikZ
    \draw (0,3) node[european nand port](A){}
        (A.out) to[short, *-o] ++(0.5,0);

From TikZ > Arrows > Reference: Arrow Tips > Geometric (page 219) I found out that:

Anyhow, I have already tried creating the node with all following combinations:


Citations:

Page 157, 4.22.7 European logic port usage The node for using outside for tripoles/european not symbol=ieee circle is ocirc (open circle).

Page 156, 4.23 Flip-flops a negation flag ... will put an ocirc shape on the border of corresponding pin

Page 199, 6.1 Nodes to bipoles (and 4.12 terminal shapes) You can use other shapes too, but at your own risk…


I was easily able to put a circle on the bottom left pin (blpin) of the muxdemux, but couldn't

\documentclass[border=10px]{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{tikzpicture}
\path (0,0) node[muxdemux, muxdemux def={NL=2,Lh=2,Rh=2}](mdemux){};
% Page 170 anchor=0
\path (mdemux.blpin 1) node[ocirc,anchor=0](){};
\end{tikzpicture}
\end{document}

image

goyalyashpal commented 1 year ago

I was able to get the tikz shapes nodes placed at the anchor, but the only problem now is that none of the shape can form that right angled triangle

\documentclass[a4paper]{article}
\usepackage{circuitikz}
%\usetikzlibrary{shapes.geometric, shapes.arrows,arrows.meta}

% No anchors with pic
% Pic not supported with CircuiTikZ
% See CTikZ manual: section 8.5 FAQ, and 1.7

\tikzset{
    euroinvert/.pic={
    \draw (0,0) -- (-25:-5mm) |- (0,0); }
}

\ctikzsubcircuitdef{euroinver}{apex, base, top}{%
    % reference anchor is -apex
    coordinate(#1-apex)
    (#1-apex) -- ++(-25:-5mm) coordinate (#1-top) --
    (#1-top |- #1-apex) coordinate (#1-base) --
    (#1-apex)
}
\begin{document}

\ctikzsubcircuitactivate{euroinver}

\begin{tikzpicture}[]
\path (0,0) node[muxdemux, muxdemux def={NL=2,Lh=2,Rh=2,NB=0},external pins width = 2](mdemux){};
\draw (mdemux.blpin 1) pic[draw](){euroinvert};
\draw (mdemux.brpin 1) \euroinver{ha}{base};
\end{tikzpicture}
\end{document}

image

goyalyashpal commented 1 year ago

experimental support for generating sub-circuits, or circuits blocks That means that in future releases the interface can change; use it at your risk and if you need it to continue working as-is, please use the GitHub project page and download and save the circuitikzgit.sty file for future-proof use!

https://github.com/circuitikz/circuitikz/blob/2fd195d286a33e3430890091f95191835e552ebf/doc/circuitikzmanual.tex#L1745

  1. i will move this subcircuit definition to my custom style file, and do \RequirePackage{circuitikz}[1.5.5] - will that make it foolproof??
  2. Will it hurt if i activate it right after the definition in the style file itself? (seems yes, it shows errors)
Rmano commented 1 year ago
  1. i will move this subcircuit definition to my custom style file, and do \RequirePackage{circuitikz}[1.5.5] - will that make it foolproof??

I suppose it will work. Never tried; I do not think that any package depends on circuitikz

  1. Will it hurt if i activate it right after the definition in the style file itself? (seems yes, it shows errors)

Yes. The problem is that to know the distances with the actual sizes of components, you have to call the "activate" after all the options are active. That will typeset the circuit to measure the distances... What you could try to do is to add the activation to a hook, if you don't change styles after the preamble (something like \AtBeginDocument, or better one of the new hooks, you can look at lthooks-doc.pdf in your TeX system).

Rmano commented 1 year ago

I suppose it will work. Never tried; I do not think that any package depends on circuitikz

I supposed wrong. There are only some "go back" points in the package, and 1.5.5 is not one of them. Anyway, I do not think to change the subcircuit thing anymore --- at least not in a backward compatible way (I am a bit of a sucker for backward compatibility...). I'll change the manual to reflect that in a future commit...

Rmano commented 1 year ago

See #682 😉

goyalyashpal commented 1 year ago

hey, by any means, do you think adding this as new component would be worth it??

Rmano commented 1 year ago

You got me... I never use European logic symbols (I think a symbol must convey its meaning graphically, and the European symbols don't do that --- just a lot of rectangles). So I am not the right one to judge it. Standard TikZ circuit library has options to add negation on the inputs, which I never tried even to think how to implement (I provide the anchor to trick it); maybe that would be the logical way to do it...

goyalyashpal commented 1 year ago

I think a symbol must convey its meaning graphically, and the European symbols don't do that --- just a lot of rectangles

u are right, i used to think same before. and still do think same as long as logic symbols (or perhaps more aptly, logic circuit diagram) for gates are concerned.

but where european rectangles shine is in providing consistent looking, easy to follow abstraction for more complex logic units like mux, demux, comparator, etc...

in my opinion, the circle looks very odd and feels out of place in these otherwise prefect boxes.


wow, the vertical alignment here 😅:point_down:
totally missed this


Rmano commented 1 year ago

Yes, the look is quite nice. I think that's definitely possible (and maybe good) to add the shape --- it's not invasive and it can be used in a lot of place.

goyalyashpal commented 1 year ago

Yes, the look is quite nice

glad u liked 'em 😊😃

Rmano commented 1 year ago

What about...

image

this one scales with logic port class (this is a bit arbitrary, I know) and the default size I chose are quite random too, but... what do you think?

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usepackage{ctikzmanutils}
\makeatletter
\ctikzset{euroinver/width/.initial = 0.2}
\ctikzset{euroinver/height/.initial = 0.1}
\pgfdeclareshape{euroinver}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northeast{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{euroinver/height}\pgf@circ@scaled@Rlen
        \pgf@x=\ctikzvalof{euroinver/width}\pgf@circ@scaled@Rlen
    }
    \anchor{center}{\pgfpointorigin}
    \anchor{top}{\northeast\pgf@x=0pt\relax}
    \anchor{apex}{\northeast\pgf@y=0pt\relax}
    \anchor{base}{\pgfpointorigin}
    \anchor{mid}{\northeast\pgf@x=0.5\pgf@x\pgf@y=0.5\pgf@y}
    % not standard geoanchors, south west is the same as 0,0...
    \anchor{right}{\northeast\pgf@y=0pt\relax}
    \anchor{east}{\northeast\pgf@y=0pt\relax}
    \anchor{e}{\northeast\pgf@y=0pt\relax}
    \anchor{left}{\pgfpointorigin}
    \anchor{west}{\pgfpointorigin}
    \anchor{w}{\pgfpointorigin}
    \anchor{south}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x}
    \anchor{s}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x}
    \anchor{north}{\northeast\pgf@x=0.5\pgf@x}
    \anchor{n}{\northeast\pgf@x=0.5\pgf@x}
    \anchor{south west}{\pgfpointorigin}
    \anchor{sw}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{ne}{\northeast}
    \anchor{north west}{\northeast\pgf@x=0pt\relax}
    \anchor{nw}{\northeast\pgf@x=0pt\relax}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{se}{\northeast\pgf@y=0pt\relax}
    % geo anchors based on north-east (not correct, fix me)
    % \pgfcirc@northeast@symmetric@geoanchors
    \pgf@circ@draw@component{
        \northeast\pgf@circ@res@up=\pgf@y\pgf@circ@res@right=\pgf@x
        %\typeout{DIMENSxy:\space\the\pgf@circ@scaled@Rlen\space \the\pgf@circ@res@right\space \the\pgf@circ@res@up}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathclose
        \pgfusepath{draw}
    }
}
\makeatother
\begin{document}
\begin{tikzpicture}[]
    \path (0,0) node[muxdemux, muxdemux def={NL=2,Lh=2,Rh=2,NB=0},external pins width = 2](mdemux){};
    \draw (mdemux.blpin 1) node[euroinver,anchor=apex]{};
    \draw (mdemux.brpin 1) node[euroinver]{} ;
\end{tikzpicture}

\showanchors[]{euroinver, scale=6}{}(north/90/0.4, north east/45/0.4, east/0/0.4,
    south east/-45/0.4,
    south/-90/0.4, south west/-135/0.4, west/180/0.4, north west/135/0.4,
    left/160/0.4, right/30/0.4, center/-120/0.3,
    base/-90/0.6, top/90/0.6, apex/-90/0.6, mid/60/0.6
    )

\end{document}
goyalyashpal commented 1 year ago

i prepared a whole paragraph of reply... but thought it will require a bit more testing and filtering on my part.

Rmano commented 1 year ago

If you can use the new shape with one of your examples I'll be glad to add it...

Rmano commented 1 year ago

What about this:

image image

CODE: ```latex \documentclass[]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[siunitx, RPvoltages]{circuitikz} \usepackage{ctikzmanutils} \makeatletter \ctikzset{european inversion mark/width/.initial = 0.2} \ctikzset{european inversion mark/height/.initial = 0.1} \pgfdeclareshape{euroinv}{ \savedmacro{\ctikzclass}{\edef\ctikzclass{muxdemuxes}} \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}} \savedanchor\northeast{% \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen} \pgf@y=\ctikzvalof{european inversion mark/height}\pgf@circ@scaled@Rlen \pgf@x=\ctikzvalof{european inversion mark/width}\pgf@circ@scaled@Rlen } \anchor{center}{\pgfpointorigin} \anchor{top}{\northeast\pgf@x=0pt\relax} \anchor{apex}{\northeast\pgf@y=0pt\relax} \anchor{base}{\pgfpointorigin} \anchor{mid}{\northeast\pgf@x=0.5\pgf@x\pgf@y=0.5\pgf@y} % not standard geoanchors, south west is the same as 0,0... \anchor{right}{\northeast\pgf@y=0pt\relax} \anchor{east}{\northeast\pgf@y=0pt\relax} \anchor{e}{\northeast\pgf@y=0pt\relax} \anchor{left}{\pgfpointorigin} \anchor{west}{\pgfpointorigin} \anchor{w}{\pgfpointorigin} \anchor{south}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x} \anchor{s}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x} \anchor{north}{\northeast\pgf@x=0.5\pgf@x} \anchor{n}{\northeast\pgf@x=0.5\pgf@x} \anchor{south west}{\pgfpointorigin} \anchor{sw}{\pgfpointorigin} \anchor{north east}{\northeast} \anchor{ne}{\northeast} \anchor{north west}{\northeast\pgf@x=0pt\relax} \anchor{nw}{\northeast\pgf@x=0pt\relax} \anchor{south east}{\northeast\pgf@y=0pt\relax} \anchor{se}{\northeast\pgf@y=0pt\relax} % geo anchors based on north-east (not correct, fix me) % \pgfcirc@northeast@symmetric@geoanchors \pgf@circ@draw@component{ \northeast\pgf@circ@res@up=\pgf@y\pgf@circ@res@right=\pgf@x \pgfsetbeveljoin \pgfpathmoveto{\pgfpointorigin} \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}} \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}} \pgfpathclose \pgfusepath{draw} } } \makeatother \begin{document} \section{Dummy sec} \subsection{Dummy subsec} \subsubsection{Dummy subsubsec} \circuitdesc{euroinv, scale=2}{Inversion marker for European logic symbols\footnotemark}{}(base/180/0.2, top/90/0.2, apex/0/0.2, mid/45/0.2) \footnotetext{Thanks for the contribution by \href{https://github.com/circuitikz/circuitikz/issues/679}{\texttt{yashpalgoyal1304} on GitHub}.} It's often necessary or handy to add an inversion marker to symbols created with this class of devices; the \texttt{euroinv} shape will nicely do. It'll scale with the \texttt{muxdemuxes} class, and the length and height can be changed with the keys \texttt{european inversion mark/width} (default \texttt{0.2}) and \texttt{height} (default \texttt{0.1}), with the same units that are used for the \texttt{external pins width} and similar keys. \begin{LTXexample}[varwidth=true] \begin{tikzpicture}[] \path (0,3) node[muxdemux, muxdemux def={NL=2,Lh=2,Rh=2,NB=1}, external pins width = 0.5](mdemux){}; \draw (mdemux.blpin 1) node[euroinv,anchor=apex]{}; \draw (mdemux.brpin 1) node[euroinv]{}; \draw (mdemux.bbpin 1) node[euroinv, anchor=apex, rotate=90]{}; \ctikzset{european inversion mark/.cd, width=0.1} \ctikzset{muxdemuxes/.cd, fill=yellow, thickness=4, scale=0.8} \path (0,0) node[muxdemux, muxdemux def={NL=2,Lh=2,Rh=2,NB=0}, external pins width = 0.5](mdemux){}; \draw (mdemux.blpin 1) node[euroinv,anchor=apex]{}; \draw (mdemux.brpin 1) node[euroinv]{}; \end{tikzpicture} \end{LTXexample} %\showanchors[]{euroinv, scale=6}{}(north/90/0.4, north east/45/0.4, east/0/0.4, % south east/-45/0.4, % south/-90/0.4, south west/-135/0.4, west/180/0.4, north west/135/0.4, % left/160/0.4, right/30/0.4, center/-120/0.3, % base/-90/0.6, top/90/0.6, apex/-90/0.6, mid/60/0.6 % ) \end{document} ```
goyalyashpal commented 1 year ago

"and the length and height can be changed with ..."

yeah, that's what i was thinking for. I was thinking more about angle... as when modifying, it may be convenient to be able to specify the apex angle? what do you think? although, yeah, the height and width gives better control...

but specifying angle, and width might be sufficient too... maybe, i am not sure update: thinking more, i guess it's not needed. 'would be an unnecessary complication

goyalyashpal commented 1 year ago

the default size I chose are quite random too

for other dimensions:


wow, was searching for the IEEE standard, and it requires sign in to view :eyes:

goyalyashpal commented 1 year ago

Found one more interesting document while searching: http://www.wakerly.org/DDPP/DDPP3_pdf/IEEEsyms.pdf | archival link

It contains nice terminology which will come in handy while writing tutorials.

At page 2, it says the following:

ANOTHER KIND OF BUBBLE In addition to the familiar bubble, the IEEE standard also allows an external, triangular “polarity symbol” to be used to specify active-low inputs and outputs, for which the external LOW level corresponds to the internal 1-state. However, under a positive-logic convention, the bubble and the triangular polarity symbol are equivalent, so we use the more traditional bubble in this appendix.


Update: have read it complete, and wow, it is awesome. I wish i had stumbled it back when i was writing my document. would have saved me quite a lot of unnecessary confusions and decision making... the G0/7 vs A-B-C vs C0/7 or C0-C3 at page #20/"810" totally hit at home)

Rmano commented 1 year ago

wow, was searching for the IEEE standard, and it requires sign in to view eyes

I have it, and 1973 one in some place, but I can't find it now. I used them to define IEEE shapes(see #383 for more details). There is no specific size there, but you can see here that the 2:1 proportion is more or less the correct one:

image

Notice that in IEEE the triangle is normally meant to indicate an electrical condition (negative logic versus positive logic), not logical; but it's true that now everything is in positive logic, so it became equivalent to the "negaation ball".

goyalyashpal commented 1 year ago

Notice that in IEEE the triangle is normally meant to indicate an electrical condition (negative logic versus positive logic), not logical; but it's true that now everything is in positive logic, ...

i don't really understand these terms then 😅, will learn someday later. any recommended resource suggestion regarding that are welcome :)

Rmano commented 1 year ago

i don't really understand these terms then sweat_smile, will learn someday later. any recommended resource suggestion regarding that are welcome :)

No surprise, I know it because I'm old 😜. If you consider "1" low voltage and "0" high voltage, a NAND swaps meaning with a NOR, and so on. But I think I saw a negative logic circuit last time in an exam when I was a student at Uni, so we can probably consider it historical.

So do you think I can merge it like it is?

goyalyashpal commented 1 year ago

So do you think I can merge it like it is?

reviewing there itself

goyalyashpal commented 1 year ago

Just sharing for reference:

U+2300 Miscellaneous Technical
⌲ U+2332 CONICAL TAPER
⌳ U+2333 SLOPE