ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: break strings
Date: Mon, 13 Jun 2011 22:19:12 +0200	[thread overview]
Message-ID: <4DF670C0.1070108@wxs.nl> (raw)
In-Reply-To: <C239355E-582B-4319-B01E-08CF177773B9@googlemail.com>

On 13-6-2011 3:58, Wolfgang Schuster wrote:
>
> Am 13.06.2011 um 15:40 schrieb luigi scarso:
>
>> Where is the difference ?
>
> The TeX solution is faster.
>
> \define[1]\ThisHelps
>    {\handletokens#1\with{\hskip 0pt plus .1pt\firstofoneargument}}
>
> \define[1]\ThisHelpsLuigi
>    {\startluacode
>     s='#1'
>     s= string.gsub(s,'(.)',"\%1\\hskip 0sp plus .1pt")
>     context(s)
>     \stopluacode}
>
> \showframe
>
> \starttext
>
> \testfeatureonce{10000}{\ThisHelps     {abcde123xyz}}%
> \testfeatureonce{10000}{\ThisHelpsLuigi{abcde123xyz}}
>
> \stoptext

A few variants ...

\startluacode
     local gsub = string.gsub
     function LuigiX(s)
         local s = gsub(s,'.',"\%1\\hskip 0sp plus .1pt")
         context(s)
     end
     local gmatch = string.gmatch
     function LuigiY(s)
         local LuigiYY = context.LuigiYY
         for s in gmatch(s,".") do
             LuigiYY(s)
         end
     end
\stopluacode

\def\ThisHelpsLuigiX#1{\ctxlua{LuigiX('#1')}}
\def\ThisHelpsLuigiY#1{\ctxlua{LuigiY('#1')}}

\def\LuigiYY#1{#1\hskip\zeropoint plus .1pt\relax}

The disadvantage of the lua way is that for long strings we end up with 
a lot of data collected at the lua end that gets passed to tex. Normally 
this is no real problem.

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


      parent reply	other threads:[~2011-06-13 20:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-13 12:12 Steffen Wolfrum
2011-06-13 12:19 ` luigi scarso
2011-06-13 13:07   ` Steffen Wolfrum
2011-06-13 12:25 ` Wolfgang Schuster
2011-06-13 13:18   ` Steffen Wolfrum
2011-06-13 13:40     ` luigi scarso
2011-06-13 13:52       ` Steffen Wolfrum
2011-06-13 13:59         ` luigi scarso
2011-06-13 13:58       ` Wolfgang Schuster
2011-06-13 14:02         ` luigi scarso
2011-06-13 20:19         ` Hans Hagen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DF670C0.1070108@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).