# TikZ/PGF number in shape name

I'm currently creating my own shapes in TikZ. I'm trying to get a multiplexer to work, but I named the shape mux4to1 and one of its anchors D0.

Basically, I'm getting a syntax error with the following code (MWE):

\documentclass[twoside,a4paper,12pt,headsepline]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[USenglish]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows.meta}

\makeatletter

% multiplexer shape
\pgfdeclareshape{mux4to1}{
% The 'minimum width' and 'minimum height' keys, not the content, determine
% the size
\savedanchor\northeast{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=0.5\pgf@x
\pgf@y=0.5\pgf@y
}
% This is redundant, but makes some things easier:
\savedanchor\southwest{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=-0.5\pgf@x
\pgf@y=-0.5\pgf@y
}
% Inherit from rectangle
\inheritanchorborder[from=rectangle]

% Define same anchor a normal rectangle has
\anchor{center}{\pgfpointorigin}
\anchor{text}{
\pgfpointorigin
}

% Define anchors for signal ports
\anchor{D0}{
\northeast%
\pgf@x=.75\pgf@x%
}
%...
% Draw the box and the port labels
\backgroundpath{
%...

\begingroup
\tikzset{mux/port labels} % Use font from this style
\tikz@textfont

% ----------------------------------------------------------------
\pgf@anchor@mux4to1@D0 % <--------------------- Syntax error here
\pgftext[bottom,at={\pgfpoint{\pgf@x}{\pgf@y}},y=\pgfshapeinnerysep]{0}
% ----------------------------------------------------------------
\endgroup

}
}

% Key to add font macros to the current font

% Define default style for this node
\tikzset{mux/port labels/.style={font=\sffamily\scriptsize}}
\tikzset{every mux4to1 node/.style={draw,minimum width=4cm,minimum
font=\sffamily}}

\makeatother

\begin{document}
\begin{tikzpicture}
\node[mux4to1] (mux) {};

\end{tikzpicture}

\end{document}


I blatantly stole some stuff from Texample:Example: D flip-flops and shift register to help me get started.

My problem might be a general LaTeX or TeX error, as I noticed before that commands with numbers in them were problematic as well.

Ideally, a solution should not be to just rename the shape/anchor, if at all possible. Because mux.Dzero, mux.Done and so on are ugly...

Change

    \pgf@anchor@mux4to1@D0 %


to

    \csname pgf@anchor@mux4to1@D0\endcsname %


The code:

\documentclass[twoside,a4paper,12pt,headsepline]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[USenglish]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows.meta}

\makeatletter

% multiplexer shape
\pgfdeclareshape{mux4to1}{
% The 'minimum width' and 'minimum height' keys, not the content, determine
% the size
\savedanchor\northeast{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=0.5\pgf@x
\pgf@y=0.5\pgf@y
}
% This is redundant, but makes some things easier:
\savedanchor\southwest{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=-0.5\pgf@x
\pgf@y=-0.5\pgf@y
}
% Inherit from rectangle
\inheritanchorborder[from=rectangle]

% Define same anchor a normal rectangle has
\anchor{center}{\pgfpointorigin}
\anchor{text}{
\pgfpointorigin
}

% Define anchors for signal ports
\anchor{D0}{
\northeast%
\pgf@x=.75\pgf@x%
}
%...
% Draw the box and the port labels
\backgroundpath{
%...

\begingroup
\tikzset{mux/port labels} % Use font from this style
\tikz@textfont

% ----------------------------------------------------------------
\csname pgf@anchor@mux4to1@D0\endcsname %
\pgftext[bottom,at={\pgfpoint{\pgf@x}{\pgf@y}},y=\pgfshapeinnerysep]{0}
% ----------------------------------------------------------------
\endgroup

}
}

% Key to add font macros to the current font

% Define default style for this node
\tikzset{mux/port labels/.style={font=\sffamily\scriptsize}}
\tikzset{every mux4to1 node/.style={draw,minimum width=4cm,minimum
font=\sffamily}}

\makeatother

\begin{document}
\begin{tikzpicture}
\node[mux4to1] (mux) {};

\end{tikzpicture}

\end{document}

• Thanks for your answer. The syntax error goes away. However, so does the desired effect of moving \pgf@x/\pgf@y to the location of the anchor. See imgur.com/vxnc9qr The bottom left corner is where I moved my path to before \begingroup.
– FRob
Jan 23 '15 at 21:42
• Argh, never mind. I was subconsciously pretty-printing that to \csname pgf@anchor@mux4to1@D0 \endcsname -- notice the space -- which is obviously another command than without the space before \endcsname.
– FRob
Jan 23 '15 at 22:07