The macro \ttfamily
does not read up to }
: it is a declaration that sets (locally) the current font and its action continues until the current group ends.
You can do this, but it's conceptually wrong to begin with.
\long\def\mymacro#1{--#1--}
\long\def\mynewmacro{\egroup\iftrue\expandafter\mymacro\expandafter{\else}\fi}
\mymacro{lorem ipsum
dolores
}
{\mynewmacro lorem ipsum
dolores
}
\bye
The \egroup
balances the initial {
; then we have the problem to make \mymacro
into seeing an explicit {
and to get rid of the necessary }
(because \def
wouldn't accept an unbalanced list of tokens). The \iftrue
test follows the true branch; actually what it does is simply disappearing, leaving
\expandafter\mymacro\expandafter{\else}\fi
on the input stream, but with TeX knowing it should ignore the \else
part. With \expandafter
we reach this \else
, whose expansion removes everything up to \fi
. So at the end we remain with
\mymacro{\fi
so by general rule \mymacro
will read up to the matching }
. The remaining \fi
will expand leaving nothing at all.
Note, however, that you can't call this as \begingroup\mynewmacro ...\endgroup
nor use \bgroup
and \egroup
.
\ttfamily
does not read ahead to the end of the group, it is not equivalent to a macro with argument in the way you suggest with\mymacro
\mymacro
.\texttt
you sometimes get overfull boxes, because hyphenation doesn't work properly. That's a known issue. I want to insert a\linebreak[1]
after every character so as mentioned here: tex.stackexchange.com/questions/324042. I want a new command that replaces\texttt
and ideally I also want a command that replaces\ttfamily
to have that functionality. But it appears that\ttfamily
is special in that sense.\mynewmacro
could go wrong that's better to give up with it. Since you want to process text in a special way, a command with argument is what you need.