Newsgroups: comp.text.tex Date: 05 Feb 2004 21:55:13 -0800
> Is it possible to use braces in command definition?
Yes, but not the way you tried.
> For example, instead of "This is \textbf{boldface}. " > Then "This is \ob boldface \cb. "
\def\ob#1\cb{\textbf{#1}}
Donald Arseneau
> > Can I define: > > > > \newcommand{\ob}{\textbf\{} > > \newcommand{\cb}{\}} > > You can use \bgroup and \egroup; in your example > > \newcommand{\ob}{\textbf\bgroup} > \newcommand{\cb}{\egroup}
Did you try this? :-)
You could write
\newcommand{\ob}{\bgroup\bf}
with the plain TeX \bf, but \textbf takes an argument, thus you need _explicit_ braces (neither { nor \bgroup)! (But you can let \ob take an argument delimited by \cb, as Donald already suggested.
Peter
> \def\ob#1\cb{\textbf{#1}}
\ob A brace looks like \verb+{+ \eb
My solution (see separate post) does not fall apart in such cases.
David Kastrup
> Can I define: > > \newcommand{\ob}{\textbf\{} > \newcommand{\cb}{\}} > > Then "This is \ob boldface \cb. "
\newcommand{\ob}{\expandafter\textbf\expandafter{\iffalse}\fi}
\newcommand{\cb}{\iffalse{\fi}}
A pity this does not work since \textbf is a macro all by itself. So you rather want to use \bfseries instead of \textbf.
David Kastrup
How about paragraphs in parameter?
\def\tb#1\te{% \begin{tabular}{ll} paragraph & \parbox[t]{0.8\linewidth}{#1} \end{tabular} }
\tb The content here are Indented. blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
\te
!! |
Runaway argument? The content here are Indented. blah blah blah blah blah blah blah bla\ETC. ! Paragraph ended before \tb was complete. <to be read again> \par l.41
I suspect you've forgotten a `}', causing me to apply this control sequence to too much text. How can we recover? My plan is to forget the whole thing and hope for the best.
! Undefined control sequence. l.42 \te
This works:
\newcommand{\tb}{ \begin{tabular}{ll} paragraph & \parbox[t]{0.8\linewidth} }
\newcommand{\te}{\end{tabular}}
\tb{ The content here are Indented. blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
}\te
documented on: 2004.02.06 Fri