[Tex/LaTex] Variable battery1 symbol in circuitikz

circuitikztikz-pgf

Is it possible to produce a variable battery1 sign (battery with one up slanted arrow) in circuitikz? There are options for vR and vL (variable resistor) but not for the battery1. I need it to represent a variable power supply. MWE is appended below

\documentclass{article}
\usepackage{tikz,circuitikz}
\begin{document}
\begin{circuitikz}
 \draw   (0,-2) to[battery1] (2,-2) node [right] {Powersupply};
\end{circuitikz}
\end{document}

Generated from MWE
What I want What I want

I can manually put an up arrow and position it to the middle of battery1 sign but any shortcut like vR or vL would help.

Best Answer

Just define your own component. I copy&pasted the battery1 definition and added the arrow.

\documentclass{article}
\usepackage{tikz,circuitikz}

\makeatletter

\def\pgf@circ@battery2@path#1{\pgf@circ@bipole@path{battery2}{#1}}
\compattikzset{battery2/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@battery2@path, \circuitikzbasekey/bipole/is voltage=true, v=#1}}

\ctikzset{bipoles/battery2/height/.initial=.6}
\ctikzset{bipoles/battery2/width/.initial=.3}

\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/battery2/height}}{battery2}{\ctikzvalof{bipoles/battery2/height}}{\ctikzvalof{bipoles/battery2/width}}{
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{0}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{0}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgfusepath{draw}

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@down}}

        \pgfsetarrowsend{latex'}
        \pgfpathmoveto{\pgfpoint{1.5\pgf@circ@res@left}{0.9\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{1.5\pgf@circ@res@right}{0.9\pgf@circ@res@up}}

        \pgfusepath{draw}
}

\makeatother
\begin{document}
\begin{circuitikz}
 \draw   (0,-2) to[battery2] (2,-2) node [right] {Powersupply};
\end{circuitikz}
\end{document}

Output:

battery2