I am trying to make some modification on the answer of Andrew Stacey of my previous question "A macro of drawing a rectangle with several parameters in TikZ".
The current code is the following:
\documentclass{article}
\usepackage[frenchb]{babel}
\usepackage{tikz}
\usetikzlibrary{fit}
\tikzset{
my funny rectangle/.style n args={4}{%
rectangle,
draw,
append after command={\pgfextra{\let\mainnode=\tikzlastnode}
node[above right] at (\mainnode.north west) {#3}%
node[above left] at (\mainnode.north east) {#4}%
node[below left] at (\mainnode.north west) {#1}%
node[above left] at (\mainnode.south west) {#2}%
},
}
}
\begin{document}
\begin{tikzpicture}
\node[my funny rectangle={1}{7}{4}{8}] {a text};
\node[my funny rectangle={$i$}{$i$}{4}{8}, text width={3cm}, minimum height={3cm}, text centered] (abc) at (5,5) {text};
\end{tikzpicture}
\end{document}
I would like to add a condition inside the append after command: if #1 = #2, do only node[below left] at (\mainnode.west) {#1}, else do node[below left] at (\mainnode.north west) {#1} and node[above left] at (\mainnode.south west) {#2}.
The answer that @Werner suggested works fine for arguments like {1}{7}{4}{8}, but does not work for arguments like {$i$}{$i$}{4}{8}. Does anyone have an idea?

