🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #1977

Re: Help writing a macro that expands to \verb

#1977
From: Donald Arseneau
Date: Wed, 02 Sep 1992 09:43
36 lines
1747 bytes
In article <1992Sep1.123134.7107@cs.cornell.edu>, raman@cs.cornell.edu (T. V. Raman) writes...
> 
>Hi!
> 
>I would like to have a macro of the following type:
>\term#1 which expands to \verb|#1| but do not know how to write it.
> 
>Clearly \def\term#1{\verb|#1|} is not the solution.

Haven't there been a lot of requests like this lately?
Here's how:

\def\term#{% not #1 but just #
   \afterassignment\Term \let\TErm= }% remove {. final space is necessary

There's more. How to do the rest depends on how braces should be treated.

If:  \term{a{b} should give \verb"a{b" then use:

\edef\Term{\noexpand\verb \string}}

If:  \term{a{b}} should give \verb"a{b}" then use:

\def\Term{\bgroup \tt \let\do\@makeother \dospecials \makeactbraces}

\begingroup
\catcode`\(=\catcode`\{ \catcode`\{=\active
\catcode`\)=\catcode`\} \catcode`\}=\active
\gdef\makeactbraces(\catcode`\{=\active \catcode`\}=\active
  \edef{(\bgroup\string{)\edef}(\egroup\string}))
\endgroup

That's it.  \term cannot be used in the argument to another command, 
just like \verb.

Donald Arseneau        asnd@reg.triumf.ca
Technical Details
Message-ID: <2SEP199202432926@reg.triumf.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!access.usask.ca!kakwa.ucs.ualberta.ca!unixg.ubc.ca!reg.triumf.ca!asnd
References: <1992Sep1.123134.7107@cs.cornell.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.text.tex
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!access.usask.ca!kakwa.ucs.ualberta.ca!unixg.ubc.ca!reg.triumf.ca!asnd
From: asnd@reg.triumf.ca (Donald Arseneau)
Subject: Re: Help writing a macro that expands to \verb
Message-ID: <2SEP199202432926@reg.triumf.ca>
Summary: How: \def\term#1{\verb|#1|}
News-Software: VAX/VMS VNEWS 1.41    
Keywords: Macro \verb Latex
Sender: news@unixg.ubc.ca (Usenet News Maintenance)
Nntp-Posting-Host: reg.triumf.ca
Organization: TRIUMF: Tri-University Meson Facility
References: <1992Sep1.123134.7107@cs.cornell.edu>
Date: Wed, 2 Sep 1992 09:43:00 GMT
Lines: 36