Changes

Jump to navigation Jump to search
1,284 bytes added ,  17:39, 2 August 2005
no edit summary
=== Comments ===
Resulted from thread [http://archive.contextgarden.net/thread/20050704.151237.f815d89d.html] and will be used in some modules such as [[RawSteps]]. It would be nice if processing dash-separated lists of values would make it into the ConTeXt core.
 
 
== Passing verbatim text as macro parameter ==
 
In case you want to write macros that should handle verbatim text,
you can use the tex primitives <tt>\obeyspaces</tt> and <tt>\obeylines</tt>.
<tt>\obeyspaces</tt> changes the category code of the space character,
so that spaces become significant. <tt>\obeylines</tt> does the same for the
newline character.
 
This works fine for the following example:
 
<texcode>
\framed{\obeyspaces{A gap from here to there!}}
</texcode>
 
But if you pass this text as a parameter for your own macro
<tt>\TextWithSpaces</tt>
 
<texcode>
\def\TextWithSpaces#1{\framed{\obeyspaces#1}}%
 
\TextWithSpaces{A gap from here to there!}
</texcode>
 
the additional spaces are '''ignored'''.
The cause for this behavior is, that the category code change
still has no effect here. The change must be done, '''before''' you
pass the parameter.
 
Here is a two-part solution for the problem (''suggested by Taco Hoekwater''):
 
<texcode>
\def\TextWithSpaces{\bgroup\obeyspaces\doTextWithSpaces}
\def\doTextWithSpaces#1{\framed{#1}\egroup}
</texcode>
 
Another way is to postpone argument loading (''suggested by Hans Hagen'').
 
<texcode>
\def \TextWithSpaces {\framed\bgroup\obeyspaces\doTextWithSpaces}
\def\doTextWithSpaces #1{#1\egroup}
</texcode>
Anonymous user

Navigation menu