# How to distinguish numbered from unnumbered parts?

This question is analogous to my earlier recent question. The other questions refers to chapters, this one refers to parts. The solution for chapters does not seem to work for parts.

I am writing a memoir document and I'd like to customize the visual appearance of the part title with Tikz1. This works so far, as shown by this MWE2:

\documentclass[a4paper,11pt]{memoir}

\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{calc}

\renewcommand{\midpartskip}{}
\renewcommand{\printpartname}{}
\renewcommand{\printpartnum}{}
\renewcommand{\printparttitle}[1]{\noindent\Huge\begin{tikzpicture}
\clip (0,0) rectangle (\textwidth,\baselineskip);

\node (bottomleft) at (0,0) {};
\node (topright) at (\textwidth,\baselineskip) {};

\draw[red] (bottomleft.center) -- (topright.center);

\node at ($(bottomleft)!0.5!(topright)$) {\textbf{#1}};

\node at (.1\textwidth, .5\baselineskip) {\thepart};
\end{tikzpicture}}

\begin{document}

\part{First}

\lipsum[1-10]

\part*{Extra}

\lipsum[11-20]

\part{Last}

\lipsum[21-30]

\end{document}

This outputs the part name and part number at the beginning of each part in such a way that both pieces of information are embedded into the graphic.

Unfortunately (albeit unsurprisingly), the middle unnumbered part (\part*) reuses the number of the previous part. I would like to hide that number. Therefore, my question is:

How can I find out whether or not the current part is numbered? Is there any function that returns such a value, or a function that only prints its argument if the current part is numbered?

As I have already asked the analogous question about chapters, I have first tried to apply the solution suggested for that question:

While numbered chapters invoke the \printchapternum command, unnumbered chapters will invoke the \printchapternonum command instead. Therefore, each of these commands can be replaced in a way to set a marker that can then be checked from within \printchaptertitle.

Unfortunately, while \printpartnum exists for parts, no analogous command \printpartnonum seems to exist. In the memoir manual, there also is no analogous mention of unnumbered parts as there is about unnumbered chapters and \printchapternonum. Hence, the solution that works for chapters apparently will not work for parts.

1: My actual graphic is quite a bit more complex and more appealing. The simple graphical part title in the MWE here are just for demonstration purposes.

2: Unlike my actual document, this MWE draws its contents from the lipsum package.

Based upon a comment by daleif, I could solve this by patching \@spart:

\documentclass[a4paper,11pt]{memoir}

\usepackage{lipsum}

\newif\ifisstarredpart
\isstarredpartfalse

\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{letltxmacro}
\makeatletter
\LetLtxMacro{\@oldspart}{\@spart}
\renewcommand{\@spart}[1]{\isstarredparttrue\@oldspart{#1}\isstarredpartfalse}
\makeatother

\renewcommand{\midpartskip}{}
\renewcommand{\printpartname}{}
\renewcommand{\printpartnum}{}%{\isstarredpartfalse}
\renewcommand{\printparttitle}[1]{\noindent\Huge\begin{tikzpicture}
\clip (0,0) rectangle (\textwidth,\baselineskip);

\node (bottomleft) at (0,0) {};
\node (topright) at (\textwidth,\baselineskip) {};

\draw[red] (bottomleft.center) -- (topright.center);

\node at ($(bottomleft)!0.5!(topright)$) {\textbf{#1}};

\ifisstarredpart
\else
\node at (.1\textwidth, .5\baselineskip) {\thepart};
\fi
\end{tikzpicture}}

\begin{document}

\part{First}

\lipsum[1-10]

\part*{Extra}

\lipsum[11-20]

\part{Last}

\lipsum[21-30]

\end{document}

For patching, I have used the letltxmacro package, as suggested in an answer for another question.

The patch than works so that before the original \@spart is evaluated, the flag for starred parts is set to true, and afterwards, it is set to false again.