TikZ 库创建

TikZ 库创建

我想知道创建新 Tikz 库的最佳(即更快)方法。

假设我在 PDF/SVG/任何矢量图形程序中都有组件。可以直接从 SVG 转换为 TikZ 代码(https://github.com/kjellmf/svg2tikz)。我可以轻松地对我拥有的每个组件执行该任务。然后我必须通过对获得的代码进行后处理,将锚点/标签添加到创建的形状中。

例如这种形状:

绝缘栅双极晶体管

我会得到以下代码:

\definecolor{c010202}{RGB}{1,2,2}
\definecolor{cFFFFFF}{RGB}{255,255,255}


\begin{tikzpicture}[y=0.80pt, x=0.8pt,yscale=-1, inner sep=0pt, outer sep=0pt]
  \path[draw=c010202,line join=round,line cap=round] (311.6780,393.3070) --
    (311.6780,404.6450) -- (297.5060,410.3140) -- (297.5060,410.3140);
  \path[draw=c010202,line join=round,line cap=round] (311.6780,450.0000) --
    (311.6780,438.6610) -- (297.5060,432.9920) -- (297.5060,432.9920);
  \path[draw=c010202,line join=round,line cap=rect,line width=1.600pt]
    (297.5050,404.6460) -- (297.5050,438.6620) -- (297.5050,438.6620);
  \path[draw=c010202] (294.6710,438.6610);
  \path[fill=c010202] (300.9860,436.6890) -- (302.5760,432.7140) .. controls
    (302.6780,432.4570) and (302.9690,432.3330) .. (303.2260,432.4350) .. controls
    (303.2750,432.4560) and (303.3220,432.4840) .. (303.3630,432.5180) --
    (308.5310,436.8910) .. controls (308.7420,437.0700) and (308.7670,437.3840) ..
    (308.5900,437.5950) .. controls (308.4880,437.7160) and (308.3360,437.7810) ..
    (308.1800,437.7720) -- (301.4200,437.3750) .. controls (301.1450,437.3590) and
    (300.9360,437.1220) .. (300.9510,436.8470) .. controls (300.9530,436.7930) and
    (300.9650,436.7400) .. (300.9860,436.6890) -- cycle;
  \path (300.9860,436.6890) -- (302.5760,432.7140) .. controls (302.6780,432.4570)
    and (302.9690,432.3330) .. (303.2260,432.4350) .. controls (303.2750,432.4560)
    and (303.3220,432.4840) .. (303.3630,432.5180) -- (308.5310,436.8910) ..
    controls (308.7420,437.0700) and (308.7670,437.3840) .. (308.5900,437.5950) ..
    controls (308.4880,437.7160) and (308.3360,437.7810) .. (308.1800,437.7720) --
    (301.4200,437.3750) .. controls (301.1450,437.3590) and (300.9360,437.1220) ..
    (300.9510,436.8470) .. controls (300.9530,436.7930) and (300.9650,436.7400) ..
    (300.9860,436.6890) -- cycle;
      \path[draw=c010202,line join=round,line cap=round] (294.6710,404.6460) --
        (294.6710,438.6610) -- (284.7500,438.6610);
          \path[fill=cFFFFFF] (284.7500,438.6610) circle (0.0424cm);
          \path[fill=c010202] (284.7500,436.9570) .. controls (285.6890,436.9570) and
            (286.4540,437.7220) .. (286.4540,438.6610) .. controls (286.4540,439.6000) and
            (285.6890,440.3650) .. (284.7500,440.3650) .. controls (283.8110,440.3650) and
            (283.0460,439.6000) .. (283.0460,438.6610) .. controls (283.0460,437.7220) and
            (283.8100,436.9570) .. (284.7500,436.9570) .. controls (285.6900,436.9570) and
            (283.8100,436.9570) .. (284.7500,436.9570) -- cycle(284.7500,439.9650) ..
            controls (285.4690,439.9650) and (286.0540,439.3810) .. (286.0540,438.6610) ..
            controls (286.0540,437.9420) and (285.4700,437.3570) .. (284.7500,437.3570) ..
            controls (284.0300,437.3570) and (283.4460,437.9420) .. (283.4460,438.6610) ..
            controls (283.4460,439.3810) and (284.0300,439.9650) .. (284.7500,439.9650) ..
            controls (285.4700,439.9650) and (284.0300,439.9650) .. (284.7500,439.9650) --
            cycle;

\end{tikzpicture}

为了轻松使用它,我必须添加锚点(1 个北锚点、1 个南锚点和 1 个门锚点)以及标签位置。

这种方法是不是好方法?

另一种方法是从任何现有库开始并根据我的需要进行修改。

相关内容