Different behavior inside self-contained macro

This defines three levels, but supports as many as you wish.

\documentclass{article}
\usepackage[T1]{fontenc}

\newcommand{\uw}[1]{%
  \addtocounter{uw}{1}%
  \csname uw\romannumeral\value{uw}\endcsname{#1}%
  \addtocounter{uw}{-1}%
}
\newcounter{uw}

\newcommand{\uwi}[1]{``#1''}
\newcommand{\uwii}[1]{`#1'}
\newcommand{\uwiii}[1]{<<#1>>}

\begin{document}

\uw{abc}

\uw{abc \uw{def} ghi}

\uw{abc \uw{def \uw{ghi} lmn} pqr}

\end{document}

enter image description here


The following suffices:

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}

\newcommand{\uw}[1]{{%
  \renewcommand{\uw}[1]{‚##1‘}%
  „#1“%
}}

\begin{document}

\uw{aaa \uw{bbb} }

\end{document}

I've placed the redefinition inside a group before setting the argument.

Tags:

Macros