[texhax] Enumerating sentences in arguments to macros

Christer Thörn df03toch at ing.hj.se
Wed Nov 10 10:03:48 CET 2004


Alexandru Scorpan wrote:

>> I'm trying to make some LaTeX-macros and would like to extract the 
>> first sentence of an argument to my macro. Is it possible to somehow 
>> enumerate the sentences in an argument?
> 
> 
> You could go Plain TeX a bit, using something like
> 
> \def\mycommand#1.#2\mystop%
>     {first sentence = #1.  Oh, and here's the rest = #2}
> 
> Then this should act more or less like
> 
> \mycommand Blah. Blih. Bluh.\mystop
> 
> would print
> 
> first sentence = Blah.  Oh, and here's the rest = Blih. Bluh.

So if I try something like this, it doesn't work.

\def\frsts#1.#2\mystop%
     {#1}

\newcommand{\firstsentence}[1]
{
	\frsts #1\mystop
}

Error messages talks about runaway arguments. Can it be fixed somehow? 
I've tried putting braces and dots around the arguments in various ways, 
but it doesn't help, other than producing different errors that is...

> Notice that \mystop does not need to be defined, and any other suitable 
> delimiter could be used instead.  When \mycommand runs, it reads 
> everything up to "." as the first arg, then everything up to \mystop as 
> the second arg. Both the first period and \mystop are gobbled in the 
> process (and thus you need to provide the period again).
> 
> -- Alex
-- 
Christer Thörn
df03toch(a)ing.hj.se



More information about the texhax mailing list