## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ How to redefine the american voltage signs in CircuiTikz?

Information and discussion about graphics, figures & tables in LaTeX documents.
kgoodrick
Posts: 1
Joined: Wed Jun 13, 2018 8:45 pm

### How to redefine the american voltage signs in CircuiTikz?

Hello All,

I posted this question on the Tex stack exchange a week ago, but unfortunately we haven't been able to come up with a solution yet. I was hoping another set of eyes on it might help find a solution.

Question duplicated below:

I am trying to redefine the plus and minus signs in circuitikz voltage labels to have a user defined thickness. So far I have a solution that works, but it has a few quirks.

The main document:

and voltagemarkers.tex:

\def\pgf@circ@drawvoltagegeneric{    \pgfextra{            \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/straight label distance}            \pgfkeysifdefined{\pgf@temp}                {                    \edef\partheight{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/straight label distance}}                    \edef\tmpdistfromline{(\partheight\pgf@circ@Rlen)}                }                {                \pgfkeysifdefined{/tikz/circuitikz/bipoles/voltage/straight label distance}                    {                        \edef\partheight{\ctikzvalof{bipoles/voltage/straight label distance}}                        \edef\tmpdistfromline{(\partheight\pgf@circ@Rlen)}                    }                    {%calculate default value from part height                        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/height}                        \pgfkeysifdefined{\pgf@temp}                        {                            \edef\partheight{0.5*\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/height}}                            \edef\tmpdistfromline{(\partheight\pgf@circ@Rlen+0.2\pgf@circ@Rlen)}                        }                        {                            \edef\tmpdistfromline{(.5\pgf@circ@Rlen)} %fallback to fixed value                        }                    }                }        \ifnum \ctikzvalof{mirror value}=-1            \ifpgf@circuit@bipole@inverted                \ifpgf@circuit@bipole@voltage@straight                    \def\distfromline{\tmpdistfromline}                \else                    \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen}                \fi            \else                \ifpgf@circuit@bipole@voltage@straight                    \def\distfromline{-\tmpdistfromline}                \else                    \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen}                \fi            \fi        \else            \ifpgf@circuit@bipole@inverted                \ifpgf@circuit@bipole@voltage@straight                    \def\distfromline{-\tmpdistfromline}                \else                    \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen}                \fi            \else                \ifpgf@circuit@bipole@voltage@straight                    \def\distfromline{\tmpdistfromline}                \else                    \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen}                \fi            \fi        \fi        \ifpgf@circuit@bipole@voltage@below            \def\pgf@circ@voltage@angle{90}        \else            \def\pgf@circ@voltage@angle{-90}        \fi        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}        \pgfkeysifdefined{\pgf@temp}            { \edef\distacefromnode{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}} }            { \edef\distacefromnode{\ctikzvalof{voltage/distance from node}} }        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}        \pgfkeysifdefined{\pgf@temp}            { \edef\bumpb{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}} }            { \edef\bumpb{\ctikzvalof{voltage/bump b}} }    }    % %\pgf@circ@Rlen/16 is equal to the length of the currarrow    coordinate (pgfcirc@midtmp) at ($(\tikztostart) ! \pgf@circ@Rlen/16 ! (anchorstartnode)$) %absolute move, minimum space is length of arrowhead    coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distacefromnode ! (anchorstartnode)$)     coordinate (pgfcirc@Vfrom) at ($(pgfcirc@midtmp) ! -\distfromline ! \pgf@circ@voltage@angle:(anchorstartnode)$)    coordinate (pgfcirc@midtmp) at ($(\tikztotarget) ! \pgf@circ@Rlen/16 ! (anchorendnode)$)%absolute move, minimum space is length of arrowhead    coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distacefromnode ! (anchorendnode)$)     coordinate (pgfcirc@Vto) at ($(pgfcirc@midtmp) ! \distfromline ! \pgf@circ@voltage@angle : (anchorendnode)$)     \ifpgf@circuit@bipole@voltage@below        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-110)$)        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-70)$)    \else        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.110)$)        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.70)$)    \fi     \ifpgf@circuit@europeanvoltage        \ifpgf@circuit@bipole@voltage@straight            \ifpgf@circuit@bipole@voltage@backward                (pgfcirc@Vto) --(pgfcirc@Vfrom) node[currarrow, sloped,  allow upside down, pos=1,anchor=tip] {}            \else                (pgfcirc@Vfrom) --(pgfcirc@Vto) node[currarrow, sloped,  allow upside down, pos=1,anchor=tip] {}            \fi        \else            \ifpgf@circuit@bipole@voltage@backward                (pgfcirc@Vto) .. controls (pgfcirc@Vcont2)  and (pgfcirc@Vcont1) ..                    node[currarrow, sloped,  allow upside down, pos=1] {}                (pgfcirc@Vfrom)            \else                (pgfcirc@Vfrom) .. controls (pgfcirc@Vcont1)  and (pgfcirc@Vcont2) ..                    node[currarrow, sloped,  allow upside down, pos=1] {}                (pgfcirc@Vto)            \fi        \fi    \else        \ifpgf@circuit@bipole@voltage@backward            \ifpgf@circ@oldvoltagedirection                (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickplusvm}                (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickminusvm}            \else                (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickminusvm}                (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickplusvm}            \fi        \else            \ifpgf@circ@oldvoltagedirection                (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickminusvm}                (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickplusvm}            \else                (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickplusvm}                (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\thickminusvm}            \fi        \fi    \fi}

voltagemarkers.tex is the same as the definition in the source code with $+$ and $-$ replaced by my macros from the main file.

There are two problems that I have with this solution. The first is that it requires externalization, and specifically it requires [cmd]usepgfplotslibrary{external}[/cmd] Either not externalizing or using [cmd]usetikzlibrary{external}[/cmd] instead both result in the new definitions being ignored. This is not necessarily a problem, but I would at least like to understand why this specific externalization is required.

The second problem is that I need to create an invisible vertical line in the minus symbol to keep the plus and minus inline. I tried using the text height and text depth tikz options described in the manual to keep them the same size, but this resulted in the minus sign being higher than the plus sign in the horizontal components. I also tried using the baseline option, but with it the vertical markers became misaligned.

Is there a better way to do this that does not require the phantom line in the minus sign or externalization? I know this is delving into the depths of circuitikz, but I would certainly appreciate any help you would be able to provide.

Tags:

### Who is online

Users browsing this forum: No registered users and 10 guests