ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Implementing xspace
@ 2006-02-08 22:08 Aditya Mahajan
  2006-02-08 23:16 ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2006-02-08 22:08 UTC (permalink / raw)


Hi,

There was some discussion about this in the past (2002)

http://archive.contextgarden.net/message/20020117.124319.5d0f9b9e.en.html

which Hans concluded by saying

<quote>
it should hook into processsynonym but in such a way that it does 
not break other code because synonyms are used (here) for more purposes 
then you want to know.
</quote>

Is there any update on this? I would really like something like xspace to 
be integrated with abbreviations and \cite.

-- 

Aditya

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-08 22:08 Implementing xspace Aditya Mahajan
@ 2006-02-08 23:16 ` Hans Hagen
  2006-02-09  2:13   ` Aditya Mahajan
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2006-02-08 23:16 UTC (permalink / raw)


Aditya Mahajan wrote:
> Hi,
>
> There was some discussion about this in the past (2002)
>
> http://archive.contextgarden.net/message/20020117.124319.5d0f9b9e.en.html
>
> which Hans concluded by saying
>
> <quote>
> it should hook into processsynonym but in such a way that it does 
> not break other code because synonyms are used (here) for more purposes 
> then you want to know.
> </quote>
>   
i've forgotten what thi sis supposed to do (what its' used for)

(that kind of parsing is rather fragile)

Hans

-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-08 23:16 ` Hans Hagen
@ 2006-02-09  2:13   ` Aditya Mahajan
  2006-02-09  9:11     ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2006-02-09  2:13 UTC (permalink / raw)


<--- On Feb 9, Hans Hagen wrote --->

> Aditya Mahajan wrote:
>> Hi,
>>
>> There was some discussion about this in the past (2002)
>>
>> http://archive.contextgarden.net/message/20020117.124319.5d0f9b9e.en.html
>>
>> which Hans concluded by saying
>>
>> <quote>
>> it should hook into processsynonym but in such a way that it does
>> not break other code because synonyms are used (here) for more purposes
>> then you want to know.
>> </quote>
>>
> i've forgotten what thi sis supposed to do (what its' used for)


It basically saves the pain of typing \ or {} after all commands. 
Suppose I have
\abbreviation {ABC} {Some abbreviation}

As we know \ABC is an abbreviation.

Notice that there is no \ or {} after \ABC. Normally tex will gobble 
this space. With xspace one can use something like

\def\ABC{Some abbreviation\xspace}

and it will intelligently decide whether to keep a space or not. 
Adding this feature will not effect existing documents.

More details and deinition from xspace.dtx

% |\xspace| should be used at the end of a macro designed to be used
% mainly in text. It adds a space unless the macro is followed by
% certain punctuation characters.

% After |\newcommand{\gb}{Great Britain\xspace}|\\
% \newcommand{\gb}{Great Britain\xspace}
% |\gb is a very nice place to live.|\\
% \gb is a very nice place to live.\\
% |\gb, a small island off the coast of France.|\\
% \gb, a small island off the coast of France.
%
% |\xspace| saves the user from having to type \verb*+\ + or |{}| after
% most occurrences of a macro name in text. However if either of these
% constructions follows |\xspace|, a space is not added by |\xspace|.
% This means that it is safe to add |\xspace| to the end of an existing
% macro without making too many changes in your document.
%
% Sometimes |\xspace| may make the wrong decision, and add a space when
% it is not required. In these cases follow the macro with |{}|, as this
% has the effect of suppressing the space.
%
% Note that this package must be loaded \emph{after} any language (or
% other) packages that make punctuation characters `active'.

\def\@xspace{%
   \ifx\@let@token\bgroup\else
   \ifx\@let@token\egroup\else
   \ifx\@let@token\/\else
   \ifx\@let@token\ \else
   \ifx\@let@token~\else
   \ifx\@let@token.\else
   \ifx\@let@token!\else
   \ifx\@let@token,\else
   \ifx\@let@token:\else
   \ifx\@let@token;\else
   \ifx\@let@token?\else
   \ifx\@let@token/\else
   \ifx\@let@token'\else
   \ifx\@let@token)\else
   \ifx\@let@token-\else
   \ifx\@let@token\@xobeysp\else
   \ifx\@let@token\space\else
   \ifx\@let@token\@sptoken\else
    \space
  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}


-- 
Aditya Mahajan, EECS Systems, University of Michigan
http://www.eecs.umich.edu/~adityam || Ph: 7342624008

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-09  2:13   ` Aditya Mahajan
@ 2006-02-09  9:11     ` Hans Hagen
  2006-02-10  5:03       ` Aditya Mahajan
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2006-02-09  9:11 UTC (permalink / raw)


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

Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-09  9:11     ` Hans Hagen
@ 2006-02-10  5:03       ` Aditya Mahajan
  2006-02-10  8:29         ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Mahajan @ 2006-02-10  5:03 UTC (permalink / raw)


<--- 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-10  5:03       ` Aditya Mahajan
@ 2006-02-10  8:29         ` Hans Hagen
  2006-02-11  4:52           ` Aditya Mahajan
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2006-02-10  8:29 UTC (permalink / raw)


Aditya Mahajan wrote:

... should be

\def\reprocesssort#1#2#3%
  {\processsort{#1}{#2}{#3}%
   \getvalue{\??so#1\c!next}}

\def\reprocesssynonym#1#2#3%
  {\processsynonym{#1}{#2}{#3}%
   \getvalue{\??sm#1\c!next}}

-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Implementing xspace
  2006-02-10  8:29         ` Hans Hagen
@ 2006-02-11  4:52           ` Aditya Mahajan
  0 siblings, 0 replies; 7+ messages in thread
From: Aditya Mahajan @ 2006-02-11  4:52 UTC (permalink / raw)


<--- On Feb 10, Hans Hagen wrote --->

> Aditya Mahajan wrote:
>
> ... should be
>
> \def\reprocesssort#1#2#3%
>  {\processsort{#1}{#2}{#3}%
>   \getvalue{\??so#1\c!next}}
>
> \def\reprocesssynonym#1#2#3%
>  {\processsynonym{#1}{#2}{#3}%
>   \getvalue{\??sm#1\c!next}}
>

Thank you. Works as expected.

Aditya

-- 
Aditya Mahajan, EECS Systems, University of Michigan
http://www.eecs.umich.edu/~adityam || Ph: 7342624008

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-02-11  4:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 22:08 Implementing xspace Aditya Mahajan
2006-02-08 23:16 ` Hans Hagen
2006-02-09  2:13   ` Aditya Mahajan
2006-02-09  9:11     ` Hans Hagen
2006-02-10  5:03       ` Aditya Mahajan
2006-02-10  8:29         ` Hans Hagen
2006-02-11  4:52           ` Aditya Mahajan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).