%% tikzlibrarytikzphysics.core.code.tex
%% -----------------------------------------------------------
%% Core helpers shared by all tikzphysics modules.
%%
%% Provides:
%%   * \tikzphysics@length@keyhandler  --- unit-aware length key router
%%   * physics debug/.cd family     --- anchor and key overlays
%%   * \tikzphysics@registeranchors / \tikzphysics@registerkeys --- registries
%%     used by each shape so debug mode knows what to display
%%   * \geometryvalue --- per-node resolved geometry values
%%
%% Every shape module should \usetikzlibrary{tikzphysics.core}
%% before declaring its shapes.
%%
%% Author  : Vaibhav Blayer
%% Version : v1.2.0 (2026-09-05)
%% License : LPPL 1.3c
%% -----------------------------------------------------------

\makeatletter

%% Public hooks run after a style's built-in defaults. The short names are
%% intentional: users can write every block/.style without a key directory.
\tikzset{
  every physics object/.style={},
  every physics connection/.style={},
}
\newcommand{\tikzphysics@declarehook}[1]{%
  \tikzset{every physics #1/.style={},
    every #1/.style={/tikz/every physics #1}}%
}

%% ============================================================
%%  UNIT-AWARE LENGTH KEY HANDLER
%%
%%  Usage inside a key's .code handler:
%%    some key/.code = {\tikzphysics@length@keyhandler{/pgf/minimum width}{#1}}
%%
%%  Semantics:
%%    - If the user value carries a unit (4cm, 30mm, 2ex, 1.5in),
%%      that unit is respected.
%%    - If the user value is a bare number or a unit-free math
%%      expression (4, 2*sqrt(2), 3+1), the result is interpreted
%%      as centimetres.  This matches TikZ's typical "coordinate"
%%      convention and keeps JEE-physics dimensions readable.
%%
%%  IMPORTANT IMPLEMENTATION NOTE:
%%    Do NOT use \pgfkeysalso{#1=\pgfmathresult pt} directly.
%%    pgfkeys stores the RHS as unexpanded token sequence, so the
%%    shared \pgfmathresult macro gets overwritten by the next
%%    call — causing cross-contamination between keys
%%    (e.g. setting minimum width then minimum height would make
%%    both end up with the second value).  Instead, resolve to a
%%    fixed-point literal via \pgfmathsetlength + \the, then build
%%    the \pgfkeysalso call with \edef+\noexpand so the stored
%%    value is a constant string like "85.35826pt".
%% ============================================================

\newdimen\tikzphysics@length@tmpdim

%% Resolve a tikzphysics length into a concrete dimension.  Bare values
%% are centimetres; explicit TeX units are preserved.  All public size
%% keys are required to be strictly positive so invalid geometry fails
%% at the option that introduced it rather than much later in PGF math.
\newcommand{\tikzphysics@resolve@length}[2]{%
  \tikzphysics@resolve@nonnegative{#1}{#2}%
  \ifdim#1=0pt\relax
    \PackageError{tikzphysics}%
      {Length `#2' must be greater than zero}%
      {Use a positive bare value (interpreted as cm) or a positive TeX dimension.}%
  \fi
}

%% Spring leads and other optional distances may be zero.
\newcommand{\tikzphysics@resolve@nonnegative}[2]{%
  \pgfmathparse{#2}%
  \ifpgfmathunitsdeclared
    \pgfmathsetlength{#1}{\pgfmathresult pt}%
  \else
    \pgfmathsetlength{#1}{\pgfmathresult cm}%
  \fi
  \ifdim#1<0pt\relax
    \PackageError{tikzphysics}%
      {Length `#2' must not be negative}%
      {Use zero, a positive bare value (cm), or a positive TeX dimension.}%
  \fi
}

\newcommand{\tikzphysics@length@keyhandler}[2]{%
  \tikzphysics@resolve@length{\tikzphysics@length@tmpdim}{#2}%
  \edef\tikzphysics@length@call{%
    \noexpand\pgfkeysalso{#1=\the\tikzphysics@length@tmpdim}%
  }%
  \tikzphysics@length@call
}

%% ============================================================
%%  ANCHOR AND KEY REGISTRIES
%%
%%  Each shape module registers the anchors it exposes and the
%%  keys it accepts.  Debug mode reads these registries to know
%%  what to overlay.
%% ============================================================

\newcommand{\tikzphysics@registeranchors}[2]{%
  \expandafter\gdef\csname tikzphysics@anchors@#1\endcsname{#2}%
}

\newcommand{\tikzphysics@registerkeys}[2]{%
  \expandafter\gdef\csname tikzphysics@keys@#1\endcsname{#2}%
}

%% User-facing name shown at the top of debug key panels.  Internal PGF shape
%% names stay namespaced even when the public TikZ style is deliberately short.
\newcommand{\tikzphysics@registerdisplayname}[2]{%
  \expandafter\gdef\csname tikzphysics@displayname@#1\endcsname{#2}%
}

%% Key-defaults registry: stores {key/default, key/default, ...}
%% for the debug overlay to display.
\newcommand{\tikzphysics@registerkeydefaults}[2]{%
  \expandafter\gdef\csname tikzphysics@keydefaults@#1\endcsname{#2}%
}

%% ============================================================
%%  NAMED-NODE GEOMETRY VALUES
%%
%%  Shapes may register a recorder that snapshots useful scalar metadata
%%  after a named node has been built.  Values are stored per node and are
%%  therefore safe when several differently configured shapes coexist.
%%
%%  Public access:
%%    \geometryvalue{W}{left angle}
%%    \tikzphysicsgeometryvalue{W}{left angle}  % collision-safe spelling
%%
%%  A stored value is a fixed literal, so it can be used directly in a TikZ
%%  option such as rotate=\geometryvalue{W}{slope angle}.
%% ============================================================

\newcommand{\tikzphysics@registergeometryrecorder}[2]{%
  \expandafter\gdef\csname tikzphysics@geometry@recorder@#1\endcsname{#2}%
}

\newcommand{\tikzphysics@storegeometryvalue}[3]{%
  \expandafter\xdef\csname tikzphysics@geometry@value@#1@#2\endcsname{#3}%
}

\newcommand{\tikzphysicsgeometryvalue}[2]{%
  \ifcsname tikzphysics@geometry@value@#1@#2\endcsname
    \csname tikzphysics@geometry@value@#1@#2\endcsname
  \else
    \PackageError{tikzphysics}%
      {Geometry value `#2' is unavailable for node `#1'}%
      {Check that the node is named, uses a supported tikzphysics shape, and
       that the property name is documented.}%
    0%
  \fi
}

\newcommand{\geometryvalue}[2]{\tikzphysicsgeometryvalue{#1}{#2}}

%% Queue a registered recorder for the node being constructed.  The hook runs
%% after the node exists, while \tikzlastnode still identifies it.
\tikzset{
  physics geometry shape/.code = {%
    \pgfkeysalso{%
      prefix after command = {%
        \pgfextra{%
          \edef\tikzphysics@geometry@tmpnode{\tikzlastnode}%
          \ifx\tikzphysics@geometry@tmpnode\@empty\else
            \ifcsname tikzphysics@geometry@recorder@#1\endcsname
              \csname tikzphysics@geometry@recorder@#1\endcsname
                {\tikzphysics@geometry@tmpnode}%
            \fi
          \fi
        }%
      }%
    }%
  },
}

%% ============================================================
%%  NUMERIC (EDGE-PARAMETRIC) ANCHORS
%%
%%  Declares a family of anchors <edge>-0, <edge>-1, ..., <edge>-100
%%  linearly interpolating from (sx,sy) to (ex,ey).  Each anchor
%%  corresponds to "t%" of the way along the edge, measured from
%%  the start point.  Call from inside \pgfdeclareshape, once per
%%  edge.  Coordinate arguments may reference saved macros (or
%%  literal dimens) -- they are left unexpanded so they resolve at
%%  anchor-access time, while the integer t is baked into the
%%  generated csname and the computation.
%%
%%  CCW convention across tikzphysics is to start each edge at its
%%  CCW-trajectory starting point, e.g.:
%%    bottom  : bl -> br   (left to right)
%%    right   : br -> tr   (bottom to top)
%%    top     : tr -> tl   (right to left)
%%    left    : tl -> bl   (top to bottom)
%%    slope   : apex -> foot  (strict CCW on a wedge with br apex)
%%
%%  Usage:
%%    \tikzphysics@declareedgeanchors{bottom}{-\myhx}{-\myhy}{\myhx}{-\myhy}
%%
%%  Cost: 101 \anchor csnames per edge per shape.  Negligible at
%%  typeset time.
%% ============================================================

%% Worker: install one anchor at a specific t.
%%   #1 = edge name
%%   #2 = t integer (0..100)
%%   #3 = startx, #4 = starty, #5 = endx, #6 = endy
\def\tikzphysics@declareedgeanchor@one#1#2#3#4#5#6{%
  \anchor{#1-#2}{%
    \pgfmathsetlength{\pgf@x}{(#3)+((#2)/100)*((#5)-(#3))}%
    \pgfmathsetlength{\pgf@y}{(#4)+((#2)/100)*((#6)-(#4))}%
  }%
}

%% Dispatcher: loop 0..100 and call the worker for each.  The
%% integer t is baked into a partial call via \edef (so it survives
%% foreach scope pop); the four coordinate args are left
%% unexpanded so saved macros inside them resolve at anchor-access
%% time, not declaration time.
\def\tikzphysics@declareedgeanchors#1#2#3#4#5{%
  \foreach \tikzphysics@@t in {0,1,...,100} {%
    \edef\tikzphysics@@partial{%
      \noexpand\tikzphysics@declareedgeanchor@one{#1}{\tikzphysics@@t}%
    }%
    \tikzphysics@@partial{#2}{#3}{#4}{#5}%
  }%
}

%% ============================================================
%%  LOGICAL SHAPE OVERRIDE
%%
%%  Some physics* names are styles that reuse a base PGF shape
%%  (e.g. physicsblock is shape=rectangle, physicspulley is shape=circle).
%%  For debug lookup we want the *logical* name so the right
%%  anchor/key list is shown.
%%
%%  Usage inside a style:
%%    my shape/.style = {
%%      shape = rectangle,
%%      physics logical shape = my shape,
%%      ...
%%    }
%%
%%  The drawer checks \tikzphysics@logical@shape@<nodename> before
%%  falling back to \pgf@sh@ns@<nodename>.
%% ============================================================

\tikzset{
  %% We use `prefix after command' rather than `append after
  %% command' so the logical-shape recorder runs BEFORE any
  %% debug emitter that was queued via `every node/.append
  %% style' at a wider scope.  Without that ordering, the
  %% emitter would look up the shape while the override is
  %% still undefined and fall through to PGF's base shape.
  physics logical shape/.code = {%
    \pgfkeysalso{%
      prefix after command = {%
        \pgfextra{%
          \edef\tikzphysics@logical@tmpnode{\tikzlastnode}%
          \expandafter\xdef
            \csname tikzphysics@logical@shape@\tikzphysics@logical@tmpnode\endcsname{#1}%
        }%
      }%
    }%
  },
}

%% ============================================================
%%  DEBUG OVERLAY
%%
%%  Keys (all under the `physics debug/' path, cascadable from
%%  tikzpicture -> scope -> node):
%%    physics debug/anchors = true | false
%%    physics debug/keys    = true | false
%%    physics debug/all     = true | false   (shorthand for both)
%%
%%  Debug output is allowed to bleed outside the node's bounding
%%  box; this is intentional, because the feature is a coding aid
%%  and users will always disable it before final typesetting.
%%
%%  Visual style is tunable via the following keys:
%%    physics debug/anchor dot color
%%    physics debug/anchor dot radius
%%    physics debug/anchor label color
%%    physics debug/anchor label font
%%    physics debug/key label color
%%    physics debug/key label font
%% ============================================================


%% Snapshot options while the node is still being constructed, then restore
%% them in its after-command hook. This makes local false overrides, local
%% colours and multiple differently configured nodes reliable.
\newif\iftikzphysics@debug@anchors
\newif\iftikzphysics@debug@keys
\def\tikzphysics@debug@properties{anchors,keys,anchor list,anchor families,anchor samples,anchor dot color,anchor dot radius,anchor label color,anchor label font,key label color,key label font,anchor legend xshift,anchor legend yshift,key panel xshift,key panel yshift}
\tikzset{
  physics debug/.cd,
  anchors/.is choice,
  anchors/true/.code={\pgfkeyssetvalue{/tikz/physics debug/anchors}{true}},
  anchors/false/.code={\pgfkeyssetvalue{/tikz/physics debug/anchors}{false}},
  anchors/.initial=false, anchors/.default=true,
  keys/.is choice,
  keys/true/.code={\pgfkeyssetvalue{/tikz/physics debug/keys}{true}},
  keys/false/.code={\pgfkeyssetvalue{/tikz/physics debug/keys}{false}},
  keys/.initial=false, keys/.default=true,
  all/.style={/tikz/physics debug/anchors=#1,/tikz/physics debug/keys=#1},
  all/.default=true,
  anchor legend xshift/.initial=0pt,
  anchor legend yshift/.initial=-2cm,
  key panel xshift/.initial=0pt,
  key panel yshift/.initial=2cm,
  anchor list/.initial=auto,
  anchor families/.initial={},
  anchor samples/.initial={0,25,50,75,100},
  anchor dot color/.initial=red,
  anchor dot radius/.initial=1.2pt,
  anchor label color/.initial=red!80!black,
  anchor label font/.initial=\tiny\ttfamily,
  key label color/.initial=gray,
  key label font/.initial=\tiny\ttfamily,
  /tikz/show anchors/.style={physics debug/anchors=#1},
  /tikz/show anchors/.default=true,
  /tikz/show keys/.style={physics debug/keys=#1},
  /tikz/show keys/.default=true,
  /tikz/physics debug setup/.style={
    execute at begin node=\tikzphysics@debug@snapshot,
    append after command={\pgfextra{
      \edef\tikzphysics@debug@do{\noexpand\tikzphysics@debug@emit{\tikzlastnode}}%
      \tikzphysics@debug@do
    }}
  },
}
\def\tikzphysics@debug@snapshot{%
  \ifx\tikz@fig@name\@empty\else
    \@for\tikzphysics@debug@prop:=\tikzphysics@debug@properties\do{%
      \pgfkeysgetvalue{/tikz/physics debug/\tikzphysics@debug@prop}{\tikzphysics@debug@value}%
      \expandafter\global\expandafter\let
        \csname tikzphysics@debug@saved@\tikz@fig@name @\tikzphysics@debug@prop\endcsname
        \tikzphysics@debug@value
    }%
  \fi
}
\def\tikzphysics@debug@emit#1{%
  \begingroup
    \ifcsname tikzphysics@debug@saved@#1@anchors\endcsname
      \@for\tikzphysics@debug@prop:=\tikzphysics@debug@properties\do{%
        \expandafter\let\expandafter\tikzphysics@debug@value
          \csname tikzphysics@debug@saved@#1@\tikzphysics@debug@prop\endcsname
        \pgfkeyslet{/tikz/physics debug/\tikzphysics@debug@prop}{\tikzphysics@debug@value}%
      }%
      \csname tikzphysics@debug@anchors\pgfkeysvalueof{/tikz/physics debug/anchors}\endcsname
      \csname tikzphysics@debug@keys\pgfkeysvalueof{/tikz/physics debug/keys}\endcsname
      \tikzset{physics debug/all=false}%
      \iftikzphysics@debug@anchors\tikzphysics@debug@drawanchors{#1}\fi
      \iftikzphysics@debug@keys\tikzphysics@debug@drawkeys{#1}\fi
    \fi
  \endgroup
}

%% ---- shape resolver ----
%% Return the shape name to use for debug lookup.  Prefers
%% physics logical shape (set by physics* styles on composite shapes)
%% over pgf's raw shape name.  Result goes to \tikzphysics@debug@shape.
\newcommand{\tikzphysics@debug@resolveshape}[1]{%
  \expandafter\ifcsname tikzphysics@logical@shape@#1\endcsname
    \edef\tikzphysics@debug@shape{\csname tikzphysics@logical@shape@#1\endcsname}%
  \else
    \expandafter\ifcsname pgf@sh@ns@#1\endcsname
      \edef\tikzphysics@debug@shape{\csname pgf@sh@ns@#1\endcsname}%
    \else
      \let\tikzphysics@debug@shape\@empty
    \fi
  \fi
}

%% ---- drawer: anchors ----
%% For the named node #1, resolve its shape, then:
%%   - draw a small numbered dot at each registered anchor
%%   - place a vertical legend below the node listing all anchors
%% This avoids label overlap on the shape itself.
\newcounter{tikzphysics@debug@anchorcount}
\newcommand{\tikzphysics@debug@drawanchors}[1]{%
  \begingroup
    \tikzphysics@debug@resolveshape{#1}%
    \ifx\tikzphysics@debug@shape\@empty\else
      \expandafter\ifcsname tikzphysics@anchors@\tikzphysics@debug@shape\endcsname
        \edef\tikzphysics@debug@list{\csname tikzphysics@anchors@\tikzphysics@debug@shape\endcsname}%
        \def\tikzphysics@debug@auto{auto}%
        \edef\tikzphysics@debug@selection{\pgfkeysvalueof{/tikz/physics debug/anchor list}}%
        \ifx\tikzphysics@debug@selection\tikzphysics@debug@auto
          \ifcsname tikzphysics@reference@anchors@\tikzphysics@debug@shape\endcsname
            \edef\tikzphysics@debug@list{\csname tikzphysics@reference@anchors@\tikzphysics@debug@shape\endcsname}%
          \fi
        \else
          \let\tikzphysics@debug@list\tikzphysics@debug@selection
        \fi
        \edef\tikzphysics@debug@families{\pgfkeysvalueof{/tikz/physics debug/anchor families}}%
        \edef\tikzphysics@debug@samples{\pgfkeysvalueof{/tikz/physics debug/anchor samples}}%
        \def\tikzphysics@debug@all{all}%
        \ifx\tikzphysics@debug@families\tikzphysics@debug@all
          \ifcsname tikzphysics@reference@families@\tikzphysics@debug@shape\endcsname
            \edef\tikzphysics@debug@families{\csname tikzphysics@reference@families@\tikzphysics@debug@shape\endcsname}%
          \else\let\tikzphysics@debug@families\@empty\fi
        \fi
        %% Expand native foreach ranges such as 0,1,...,100 before combining
        %% them with family names. The resulting list is local to this drawer.
        \gdef\tikzphysics@debug@expanded{}%
        \foreach \tikzphysics@debug@sample in \tikzphysics@debug@samples{%
          \ifx\tikzphysics@debug@expanded\@empty
            \xdef\tikzphysics@debug@expanded{\tikzphysics@debug@sample}%
          \else
            \xdef\tikzphysics@debug@expanded{\tikzphysics@debug@expanded,\tikzphysics@debug@sample}%
          \fi
        }%
        \let\tikzphysics@debug@samples\tikzphysics@debug@expanded

        \@for\tikzphysics@debug@family:=\tikzphysics@debug@families\do{%
          \@for\tikzphysics@debug@sample:=\tikzphysics@debug@samples\do{%
            \ifx\tikzphysics@debug@list\@empty
              \edef\tikzphysics@debug@list{\tikzphysics@debug@family-\tikzphysics@debug@sample}%
            \else
              \edef\tikzphysics@debug@list{\tikzphysics@debug@list,\tikzphysics@debug@family-\tikzphysics@debug@sample}%
            \fi
          }%
        }%

        \edef\tikzphysics@debug@dotcolor{\pgfkeysvalueof{/tikz/physics debug/anchor dot color}}%
        \edef\tikzphysics@debug@dotradius{\pgfkeysvalueof{/tikz/physics debug/anchor dot radius}}%
        \edef\tikzphysics@debug@labelcolor{\pgfkeysvalueof{/tikz/physics debug/anchor label color}}%
        %% One dot/label per position; coincident anchors share numbers.
        \setcounter{tikzphysics@debug@anchorcount}{0}%
        \def\tikzphysics@debug@clusters{}%
        \@for\tikzphysics@debug@a:=\tikzphysics@debug@list\do{%
          \stepcounter{tikzphysics@debug@anchorcount}%
          \pgf@process{\pgfpointanchor{#1}{\tikzphysics@debug@a}}%
          \edef\tikzphysics@debug@px{\the\pgf@x}%
          \edef\tikzphysics@debug@py{\the\pgf@y}%
          \pgfmathtruncatemacro{\tikzphysics@debug@cx}{round(\tikzphysics@debug@px/0.1pt)}%
          \pgfmathtruncatemacro{\tikzphysics@debug@cy}{round(\tikzphysics@debug@py/0.1pt)}%
          \edef\tikzphysics@debug@cluster{\tikzphysics@debug@cx:\tikzphysics@debug@cy}%
          \ifcsname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname
            \expandafter\edef\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname{%
              \csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname,\arabic{tikzphysics@debug@anchorcount}}%
          \else
            \expandafter\edef\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname{\arabic{tikzphysics@debug@anchorcount}}%
            \expandafter\edef\csname tikzphysics@debug@location@\tikzphysics@debug@cluster\endcsname{\tikzphysics@debug@a}%
            \ifx\tikzphysics@debug@clusters\@empty
              \let\tikzphysics@debug@clusters\tikzphysics@debug@cluster
            \else
              \edef\tikzphysics@debug@clusters{\tikzphysics@debug@clusters,\tikzphysics@debug@cluster}%
            \fi
          \fi
        }%
        \@for\tikzphysics@debug@cluster:=\tikzphysics@debug@clusters\do{%
          \edef\tikzphysics@debug@a{\csname tikzphysics@debug@location@\tikzphysics@debug@cluster\endcsname}%
          \fill[\tikzphysics@debug@dotcolor] (#1.\tikzphysics@debug@a)
            circle (\tikzphysics@debug@dotradius);%
          \node[\tikzphysics@debug@dotcolor,font=\tiny\bfseries,
                inner sep=0pt,anchor=south west,yshift=.5pt,xshift=.5pt]
            at (#1.\tikzphysics@debug@a)
            {\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname};%
        }%
        %% Pass 2: place legend below the node using a tabular.
        \setcounter{tikzphysics@debug@anchorcount}{0}%
        \gdef\tikzphysics@debug@legendrows{}%
        \foreach \tikzphysics@debug@a in \tikzphysics@debug@list {%
          \stepcounter{tikzphysics@debug@anchorcount}%
          %% Odd entries start a new row; even entries end it.
          \ifodd\value{tikzphysics@debug@anchorcount}%
            %% Add row separator before odd entries (except the first)
            \ifnum\value{tikzphysics@debug@anchorcount}>1
              \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{%
                \tikzphysics@debug@legendrows \noexpand\\
                \arabic{tikzphysics@debug@anchorcount}.\noexpand\space \tikzphysics@debug@a}%
            \else
              \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{%
                \tikzphysics@debug@legendrows
                \arabic{tikzphysics@debug@anchorcount}.\noexpand\space \tikzphysics@debug@a}%
            \fi
          \else
            \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{%
              \tikzphysics@debug@legendrows \noexpand&
              \arabic{tikzphysics@debug@anchorcount}.\noexpand\space \tikzphysics@debug@a}%
          \fi
        }%
        %% Place legend below the node
        \node[\tikzphysics@debug@labelcolor,
              font=\pgfkeysvalueof{/tikz/physics debug/anchor label font},
              anchor=north west,
              inner sep=2pt,
              fill=white,
              fill opacity=0.9,
              text opacity=1,
              draw=\tikzphysics@debug@dotcolor,
              draw opacity=0.3,
              line width=0.2pt,
              rounded corners=1pt,
              xshift=\pgfkeysvalueof{/tikz/physics debug/anchor legend xshift},
              yshift=\pgfkeysvalueof{/tikz/physics debug/anchor legend yshift}]
          at (#1.center)
          {\begin{tabular}{@{}l@{\quad}l@{}}
            \tikzphysics@debug@legendrows
           \end{tabular}};%
      \fi
    \fi
  \endgroup
}


%% Reference content is generated from module declarations. This is an API
%% reference, explicitly labelled as defaults rather than live node values.
\newcommand{\tikzphysics@debug@drawkeys}[1]{%
  \begingroup
    \tikzphysics@debug@resolveshape{#1}%
    \ifcsname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname
      \node[physics debug/all=false,anchor=south west,fill=white,
        draw=gray!50,inner sep=4pt,align=left,text width=8cm,
        font=\pgfkeysvalueof{/tikz/physics debug/key label font},
        text=\pgfkeysvalueof{/tikz/physics debug/key label color},
        xshift=\pgfkeysvalueof{/tikz/physics debug/key panel xshift},
        yshift=\pgfkeysvalueof{/tikz/physics debug/key panel yshift}]
        at (#1.center)
        {\csname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname};
    \fi
  \endgroup
}

%% Standalone reference card, usable inside a tikzpicture for nodes, paths,
%% and pics alike. Ordinary node options position/style the card.
\newcommand{\physicshelp}[2][]{%
  \begingroup
    \ifcsname tikzphysics@reference@lookup@#2\endcsname
      \edef\tikzphysics@debug@shape{\csname tikzphysics@reference@lookup@#2\endcsname}%
      \node[physics debug/all=false,draw=gray!50,fill=white,
        rounded corners=2pt,inner sep=6pt,align=left,text width=9cm,
        font=\scriptsize\ttfamily,#1]
        {\csname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname};
    \else
      \PackageError{tikzphysics}{Unknown reference topic `#2'}%
        {Use a public style name such as wedge, spring, pulley, or pendulum.}%
    \fi
  \endgroup
}
\let\tikzphysicshelp\physicshelp

\makeatother
\usetikzlibrary{tikzphysics.catalog}
\endinput
