[NTG-context] Implementing xspace
Aditya Mahajan
adityam at umich.edu
Fri Feb 10 06:03:07 CET 2006
<--- On Feb 9, Hans Hagen wrote --->
> Aditya Mahajan wrote:
>> It basically saves the pain of typing \ or {} after all commands.
>> Suppose I have
>> \abbreviation {ABC} {Some abbreviation}
>>
> keep in mind that such mechanism are
>
> (1) incomplete, since not all chars are looked at
> (2) don't handle commands following such a call
> (3) it's like an input encoding non conforming the default tex parsing
> (4) best can be mention ed in a comment at the top of the file
> (5) always will be fragile
>
> so, i can provide a hook for such a thing in sort/syn but after that
> you're on your own since i'm not going to add support for this at each level
>
> \unprotect
>
> % core-syn:
>
> \def\reprocesssort#1#2#3%
> {\processsort{#1}{#3}{#2}%
> \getvalue{\??so#1\c!next}}
>
> \def\preexecutesort#1#2#3%
> {\ifdoinpututilities \else
> \dowritesort{#1}{#2}{#3}%
> \unexpanded\setgvalue{#2}{\reprocesssort{#1}{#3}{#2}}%
> \fi}
>
> \def\executesort#1#2#3%
> {\begingroup
> \let\executesort\thirdofthreearguments
> \preexecutesort{#1}{#2}{#3}%
> \processsort{#1}{#3}{#2}%
> \endgroup
> \getvalue{\??so#1\c!next}} % not formally documented
>
> \def\reprocesssynonym#1#2#3%
> {\processsynonym{#1}{#3}{#2}%
> \getvalue{\??sm#1\c!next}}
>
> \def\preexecutesynonym#1#2#3#4%
> {\ifdoinpututilities \else
> \dowritesynonym{#1}{#2}{#3}{#4}%
> \unexpanded\setgvalue{#2}{\reprocesssynonym{#1}{#3}{#4}}%
> \fi}
>
> \def\executesynonym#1#2#3#4%
> {\preexecutesynonym{#1}{#2}{#3}{#4}%
> \processsynonym{#1}{#3}{#4}%
> \getvalue{\??sm#1\c!next}} % not formally documented
>
> % cors-spa:
>
> %D This is a dangerous feature because it makes the \TEX\ source
> %D less portable, i.e. any parser now needs to apply exactly the
> %D same algorithm when it wants to interpret the source. We
> %D strongly recommend not to mention this feature in manuals!
>
> \def\autoinsertnextspace{\futurelet\nexttoken\doautoinsertnextspace}
>
> \def\doautoinsertnextspace % slightly extended version of a user supplied macro
> {\ifx\nexttoken \bgroup\else \ifx\nexttoken\begingroup\else
> \ifx\nexttoken \egroup\else \ifx\nexttoken \endgroup\else
> \ifx\nexttoken \/\else \ifx\nexttoken /\else \ifx\nexttoken ~\else
> \ifx\nexttoken \ \else \ifx\nexttoken \blankspace\else \ifx\nexttoken \space\else
> \ifx\nexttoken .\else \ifx\nexttoken ,\else
> \ifx\nexttoken !\else \ifx\nexttoken ?\else
> \ifx\nexttoken :\else \ifx\nexttoken ;\else
> \ifx\nexttoken '\else \ifx\nexttoken "\else
> \ifx\nexttoken )\else
> \ifx\nexttoken -\else \ifx\nexttoken |\else
> % \ifx\nexttoken \%\else \ifx\nexttoken \&\else
> \space
> % \fi\fi
> \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}
>
> \protect
>
> \setupsorting[logo][next=\autoinsertnextspace]
>
> \logo[TEX]{\TeX}
>
> bla bla \TEX test test
> bla bla \TEX (test) test
> bla bla (\TEX) test
>
> \stoptext
Thank you for the hook. It works as expected for logos, however breaks
synonyms. See for example
%\setupsynonyms[abbreviation][next=\autoinsertnextspace]
\abbreviation {ABC} {Another basic channel}
A \ABC is a \ABC\ is a \ABC. \infull{ABC} is an interesting thing.
This comes out as
A ABCis a ANOTHER BASIC CHANNEL is a ANOTHER BASIC CHANNEL. ABC is an
interesting thing.
Somehow, after the first call, \ABC and \infull{ABC} behave opposite
of what is expected.
Aditya
--
Aditya Mahajan, EECS Systems, University of Michigan
http://www.eecs.umich.edu/~adityam || Ph: 7342624008
More information about the ntg-context
mailing list