I have defined a biopole device called galvanometer, which is rotation corrected. It means it displays a circled 'G' letter which is always readable, no matter in which orientation the device is drawn.
I want this code to generate myammeter (which will print 'A') or myvoltmeter (which will print 'V'). However I want to reuse the same code as a template and issue directives like \newcircleddevice{myvoltmeter}{V} or \newcircleddevice{myammmeter}{A} instead of simply copy-pasting the code and changing 'G' to 'V' or 'A' (I am currently using this approach).
Just the simple definition using \newcommand doesn't work. How do I achieve a templatized definition?
This is my MWE. This is a perfectly compilable code.
\documentclass[tikz]{standalone}
\usepackage[siunitx]{circuitikz}
% rotation corrected galvanometer
\ctikzset{bipoles/galvanometer/height/.initial=.60}
\ctikzset{bipoles/galvanometer/width/.initial=.60}
\makeatletter
\def\pgf@circ@galvanometer@path#1{\pgf@circ@bipole@path{galvanometer}{#1}}
\tikzset{galvanometer/.style = {\circuitikzbasekey, /tikz/to
path=\pgf@circ@galvanometer@path}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/voltmeter/height}}{galvanometer}
{\ctikzvalof{bipoles/galvanometer/height}}{\ctikzvalof{bipoles/galvanometer/width}}
{
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
\pgfpointorigin \pgf@circ@res@other = \pgf@x
\advance \pgf@circ@res@other by -\pgf@circ@res@up
\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
\pgfusepath{draw}
\pgfgetlastxy{\tempx}{\tempy}
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}
\pgfstartlinewidth}
\pgfscope
\pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
\pgfusepath{draw}
\endpgfscope
\pgfsetlinewidth{\pgfstartlinewidth}
\pgfgetlastxy{\XCoord}{\YCoord}
\ifdim \XCoord < \tempx
\ifdim \YCoord < \tempy
\def\pgf@circ@temp{UP} % these are debgging variables
\pgftransformrotate{180}
\else
\def\pgf@circ@temp{RIGHT}
\pgftransformrotate{-90}
\fi
\else
\ifdim \YCoord < \tempy
\def\pgf@circ@temp{LEFT}
\pgftransformrotate{90}
\else
\def\pgf@circ@temp{DOWN}
%\pgftransformrotate{90}
\fi
\fi
%\pgfnode{circle}{center}{\textbf{G}\pgf@circ@temp}{}{}% for testing
\pgfnode{circle}{center}{\textbf{G}}{}{}
}
\makeatother
\begin{document}
\begin{circuitikz}
\draw (0,0) to[galvanometer] ++(5,0) to[galvanometer] ++(0,5) to[galvanometer] ++(-5,0) to[galvanometer] ++(0,-5);
\draw (2.5,0.5) node[above] {A};
\draw (7,0) to[galvanometer] ++(5,0) to[galvanometer] ++(0,5) to[galvanometer] ++(-5,0) to[galvanometer] ++(0,-5);
\draw (7.5,2.5) node[right] {B};
\draw (0,-7) to[galvanometer] ++(5,0) to[galvanometer] ++(0,5) to[galvanometer] ++(-5,0) to[galvanometer] ++(0,-5);
\draw (7,-7) to[galvanometer] ++(5,0) to[galvanometer] ++(0,5) to[galvanometer] ++(-5,0) to[galvanometer] ++(0,-5);
\draw (7,-20) to[galvanometer] ++(10,0) to[galvanometer] ++(0,10) to[galvanometer] ++(-10,0) to[galvanometer] ++(0,-10);
%\draw (17,30) to[galvanometer] ++(5,0) to[galvanometer] ++(0,5) to[galvanometer] ++(-5,0) to[galvanometer] ++(0,-5);
\end{circuitikz}
\end{document}



circuitikzchanged a lot since then. You can look at https://tex.stackexchange.com/questions/524328/i-need-to-use-a-different-version-of-circuitikz-how-can-i-do-that, there is a (hackish but safe) way to test newer versions. – Rmano Apr 19 '20 at 08:35circuitikz(and in general on latex) ... so many of my documents might fail to compile if i update recklessly. I usually save only the source code, not compiled PDF. but i will find a way to update without using any hacks. – magguu Apr 19 '20 at 12:54