add tag
निरंजन
I have learnt a way to activate one character in the scope of a specific command, which means outside the command it won't be active. eg.

```
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Script=Devanagari]{Shobhika}
\usepackage{tikz}
\begingroup
\catcode`म=\active
\gdef\new{%
\catcode`म=\active
\def म{\begin{tikzpicture}
		\draw (0,0) circle[radius=0.15cm];
\end{tikzpicture}}
}
\endgroup

\begin{document}
	म \new{म}
\end{document}
```

What if I want to make a sequence of characters active? eg.

```
\catcode`मा=\active
\gdef\new{%
\catcode`मा=\active
\def मा{\begin{tikzpicture}
		\draw (0,0) circle[radius=0.15cm];
\end{tikzpicture}}
}
```

I want customized output for some sequences of Unicode characters in the scope of command `\new`. How to achieve it?
Top Answer
Skillmon
# Another way

The following proposes another way, that doesn't rely on category code changes. Instead we'll just grab an argument and manipulate it. I use `expl3` in the following, just so that I have an easier life. Also, since font-choices aren't vast on my machine, I'll drop your Devanagari example and instead use the Latin alphabet only (sorry).

```tex
\documentclass{article}

\usepackage{tikz}
\def\myreplacement{\tikz\draw(0,0)circle[radius=0.15cm];}

\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_myexample_contents_tl
\NewDocumentCommand \new { m }
  {
    \group_begin:
      \tl_set:Nn \l_myexample_contents_tl { #1 }
      \regex_replace_all:nnN { oc } { \c{myreplacement} } \l_myexample_contents_tl
      \l_myexample_contents_tl
    \group_end:
  }
\ExplSyntaxOff

\begin{document}
  oc \new{This gets replaced: {oc}oc; This doesn't: oC}
\end{document}
```

# Activating the character

Your original question can be answered like this. You can check for the next token with `\futurelet` and test whether that is the token which should follow your character with `\ifx`. If the correct token is following yours place the replacement in the input stream and gobble the following character. Else input the activated character and move on.

```tex
\documentclass{article}

\usepackage{tikz}

\makeatletter
\def\myreplacement@insert{\tikz\draw(0,0)circle[radius=0.15cm];}
\newcommand*\myreplacement
  {%
    \futurelet\myreplacement@tok\myreplacement@a
  }
\newcommand*\myreplacement@a
  {%
    \ifx\myreplacement@tok c%
      \myreplacement@insert
      \expandafter\@gobble
    \else
      o%
    \fi
  }
\makeatother
\begingroup
\lccode`\~=`\o
\lowercase{\endgroup
\newcommand*\new{\catcode`\o=\active \let~\myreplacement}
}

\begin{document}
  oc {\new This gets replaced: {oc}oc; This doesn't: oC}
\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.