
高校の物理の教科書で使用されている一般的な電源の回路記号を作成してみました。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC,shapes.gates.ee}
\makeatletter
\pgfdeclareshape{mybox}{%
\inheritsavedanchors[from=rectangle ee]
\inheritanchor[from=rectangle ee]{center}
\inheritanchor[from=rectangle ee]{north}
\inheritanchor[from=rectangle ee]{south}
\inheritanchor[from=rectangle ee]{east}
\inheritanchor[from=rectangle ee]{west}
\inheritanchor[from=rectangle ee]{north east}
\inheritanchor[from=rectangle ee]{north west}
\inheritanchor[from=rectangle ee]{south east}
\inheritanchor[from=rectangle ee]{south west}
\inheritanchor[from=rectangle ee]{input}
\inheritanchor[from=rectangle ee]{output}
\inheritanchorborder[from=rectangle ee]
\inheritbackgroundpath[from=rectangle ee]
\anchor{west circ center}{
\pgfpointlineattime{0.5}{\southwest}{\northeast}
\advance\pgf@x by-0.5\tikzcircuitssizeunit%
}
\anchor{east circ center}{
\pgfpointlineattime{0.5}{\southwest}{\northeast}
\advance\pgf@x by0.5\tikzcircuitssizeunit%
}
\backgroundpath{%
\pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{west}}
\pgfpathlineto{\pgfpointanchor{\tikz@fig@name}{west circ center}}
\pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{east}}
\pgfpathlineto{\pgfpointanchor{\tikz@fig@name}{east circ center}}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointanchor{\tikz@fig@name}{east circ center}}{0.25\tikzcircuitssizeunit}
\pgfpathcircle{\pgfpointanchor{\tikz@fig@name}{west circ center}}{0.25\tikzcircuitssizeunit}
\pgfusepath{stroke,fill}
}
}
\makeatother
\tikzset{
circuit declare symbol=general source,
set general source graphic={
draw,fill=white,shape=mybox, circuit symbol size=width 3 height 1,
transform shape,
}
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw(0,0)to[general source={info={foo}}](2,0)to[resistor={info=bar}](4,0);
\draw(0,0)to[resistor](0,-3)to[make contact](4,-3)to[bulb](4,0);
\end{tikzpicture}
\end{document}
は、私のマシンでは機能する や などのコマンドを使用して描画されます。自体\backgroundpath
は、と のみに基づいたハード計算によるバックグラウンド パスを使用して独自の派生シェイプを定義しますが、他のアンカーが確立されると、面倒に見えます。\pgfpathlineto
\pgfpointanchor
tikz
\southwest
\northeas
私のやり方には何か害やリスクがありますか?tikz
のやり方に切り替えるべきでしょうか、それともこのままでいいのでしょうか?
答え1
つまり、あなたは間違っていません。それが価値があるかどうかはあなた次第です。
PGFマニュアルでは\anchor
、 とは対照的に\savedanchor
、 はオンデマンド作成つまり、アンカーの座標は、ユーザーが明示的に を記述した場合にのみ計算されます(A.east)
。
アンカーの 90% はまったく使用されておらず、計算に時間を無駄にする必要がないため、これにより多くの時間が節約されます。
TiがけZは背景パスを描画しているため、これら\anchor
の座標はまだ計算されていません。Tiの場合けZ は描画のためだけにこれらの座標を計算するので、\anchor
そもそも使用しても意味がありません... すべてを単純に作成します\savedanchor
。
つまり、TeXとの互換性の問題ではないのです。けZは純粋なTeXコードを好みます。なぜなら、その方が速いからです。著者は、何百万人もの人々の2秒を節約するために、さらに2時間を費やすことを決意しました。私の意見では、TiはけZ は TeX 用に設計されており、LaTeX と互換性があります。
あなたの場合、それはすべてあなた次第です。簡単なコードを書いて、さらに数ミリ秒待ちたいですか? それとも、 で遊んでみたいですか\pgf@x
? 私は個人的に前者を好みます。