I am working on reusable image parts with Tikz. Thanks to the answer to TikZ 3.0---Multiple arguments for pic, I found out how to do macros with parameters.
But, the problem with using predefined pics is that tikzscale does not scale them with the rest of the image. Here a small example.
The main file contains the tikz macro and the include statements:
\documentclass{article}
\usepackage{tikz,tikzscale}
\usetikzlibrary{math}
\tikzset{pics/tripile/.style args={#1}{code={
\coordinate (top) at (0,#1);
\foreach \i in{0,...,#1}
\foreach \j in{0,...,\i}
{
\tikzmath{
\y = .3*(2/3*#1-\i)*cos(30);
\x = .3*(\i/2-\j);}
\draw (\x,\y) circle (3pt);
}
}}}
\begin{document}
\thispagestyle{empty}
\includegraphics[width=.2\textwidth]{test.tikz}
\includegraphics[width=.3\textwidth]{test.tikz}
\includegraphics[width=.4\textwidth]{test.tikz}
\end{document}
The file test.tikz then provides the image
\begin{tikzpicture}[thick]
\draw (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;
\pic at (1,1) {tripile=3};
\end{tikzpicture}
The output looks like

but I would like the proportions between the square and the pile of circles to remain the same while scaling as in

Is there a way of defining a scalable pic?
pics don't scale. You can use the keytransform shapeto enable this behaviour (pgf manual p. 252/section 18.2, pic syntax). (I.e.\pic at (1,1) [transform shape] {tripile=3};Does that help you? – Huang_d Jun 08 '17 at 08:38