1

I am typing an awful lot of electrical circuits, and when I used LaTeX I used the circuitikz library, which has a simple and concise syntax. Now that I switched to ConTeXt, I have to use the TikZ circuit, which is almost perfect in terms of capabilities, but is also a lot more verbose.

I would like to define aliases (like R for resistor, l for label, V for a voltage arrow and so on). I found this thread, as well as this example in the TikZ manual:

\tikzset{r/.style={radius=#1},rx/.style={x radius=#1},ry/.style={y radius=#1}}

My first problem is that I can't find how to make subkeys work as well ; I don't know how to clearly explain it, so here is a MWE that describes the problem :

\usemodule[tikz]
\usetikzlibrary[circuits.ee.IEC]
\tikzset{
  R/.style={resistor},
  l/.style={info}
}

\starttext
Basic usage \blank
\starttikzpicture[circuit ee IEC]
  \draw (0,0) to [resistor={near start}] ++(2,0);
  \draw (3,0) to [resistor={info=$a$}] ++(2,0);
\stoptikzpicture

\hairline
My tests
\blank
\starttikzpicture[circuit ee IEC]
  \draw (0,0) to [R={near start}] ++(2,0);
  \draw (3,0) to [R={info=$a$}] ++(2,0);
  \draw (6,0) to [R={l=$a$}] ++(2,0);
  \draw (9,0) to [R] ++(2,0);
\stoptikzpicture

\stoptext

enter image description here

As soon as I use my abbreviation, all the keys I can specify as optional are not read, whether I use my abbreviation l for the option or not.

My second problem is that I tried to define a voltage arrow that suits me, and I found the circuit declare annotation key in the pgf manual, with the following example :

\tikzset{circuit declare annotation=
  {circular annotation}
  {9pt}
  {(0pt,8pt) arc (-270:80:3.5pt)}
}

However, I can't find how to make an arrow which size is linked to the node's size ; I tried using (north east) -- (north west), but it appeared to me that there is no node name here, and should write something like (this node.north west)... Is there a way to specify something as "this node" ?

  • For your first issue instead of R/.style={resistor}, l/.style={info} try with R/.style={resistor={#1}}, l/.style={info={#1}} – Salim Bou Sep 10 '16 at 09:06
  • This works perfectly. I tried without the braces around the #1, I don't know why I didn't use the braces. If you could write an answer with a bit of explanation, I'd accept it. – A. Licari-Guillaume Sep 10 '16 at 09:49

1 Answers1

2

To copy style with one argument to another you can use this method

Newstyle/.style={Oldstyle={#1}}

Here braces {#1} are added to create group which includes Oldstyle key list

Code

\usemodule[tikz]
\usetikzlibrary[circuits.ee.IEC]
\tikzset{
  R/.style={resistor={#1}},
  l/.style={info={#1}}
}

\starttext
Basic usage \blank
\starttikzpicture[circuit ee IEC]
  \draw (0,0) to [resistor={near start}] ++(2,0);
  \draw (3,0) to [resistor={info=$a$}] ++(2,0);
\stoptikzpicture

\hairline
My tests
\blank
\starttikzpicture[circuit ee IEC]
  \draw (0,0) to [R={near start}] ++(2,0);
  \draw (3,0) to [R={info=$a$}] ++(2,0);
  \draw (6,0) to [R={l=$a$}] ++(2,0);
  \draw (9,0) to [R] ++(2,0);
\stoptikzpicture

\stoptext

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76