Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!sun1.ruf.uni-freiburg.de!rusmv1!texinfo1 From: texinfo1@rusmv1.rus.uni-stuttgart.de (Rainer Schoepf) Newsgroups: comp.text.tex Subject: Re: (Another) puzzler for wannabe wizards Summary: Showing off! Keywords: Dirty Tricks, catcode changing, puzzle Message-ID: <1991Jun10.113954.17511@rusmv1.rus.uni-stuttgart.de> Date: 10 Jun 91 11:39:54 GMT References: Distribution: comp Organization: Comp.Center (RUS), U of Stuttgart, FRG Lines: 63 In article raichle@azu.informatik.uni-stuttgart.de writes: >Some time ago Don Hosek posted >> A couple puzzlers for those who think that they're TeX gurus. > >Here is another puzzle... > >% ------- CUT HERE ------ >% use plainTeX >\catcode`\"=\active\gdef"{\"} >T"ater % output: T\"ater >\begingroup\catcode`\"=12 > \showthe\catcode`\" % print: 12 > % @ > \showthe\catcode`\" % print: 12 > T"ater % output: T''ater > \catcode`\"=\active > T"ater % output: T''ater >\endgroup >T"ater % output: T\"ater >\bye >% ------- CUT HERE ------ > >At the place marked with @ there should be a >local(!) re-definition of the active char " > >This re-definition should satisfy the following constraints: >- do not assume that the catcode of " is 12 >- no side-effects (local or global) except of changing the macro > definition of " with catcode `active' (i.e., you can't use a > counter, macro, ... to save the current catcode of ") >- with the behaviour specified in the comments >- "small is beautiful" => TeX code with no more than 160 chars >- do not use \aftergroup > > >A solution with \aftergroup: > >% @= > \begingroup \catcode`\"=\active > \aftergroup\def\aftergroup"\catcode`\"=12 > \aftergroup{\aftergroup"\aftergroup}% > \endgroup > > >Have fun > -bernd >__________________________________________________________________________ >Bernd Raichle, Student der Universit"at Stuttgart | "Le langage est source >privat: Stettener Str. 73, D-7300 Esslingen | de malentendus" >email: raichle@azu.informatik.uni-stuttgart.de | (A. de Saint-Exupery) How about this one: \catcode`\"\active \edef"{\char`\expandafter\noexpand"\expandafter}% \expandafter\catcode\expandafter`\expandafter\"\the\catcode`" It relies on a few things: that " (active) is defined to expand to \" previously, that \{} and all letters have their usual category codes, etc. Rainer