[NTG-context] break strings

2011-06-13 Thread Steffen Wolfrum
Hi,

say I have arbitrary string of alphanumeric characters:


\starttext

\showframe

9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu

\stoptext



How can I (automatically) force a break at end of line, without manually adding 
\crlf or \break at break points?

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


Re: [NTG-context] break strings

2011-06-13 Thread luigi scarso
On Mon, Jun 13, 2011 at 2:12 PM, Steffen Wolfrum  wrote:
> Hi,
>
> say I have arbitrary string of alphanumeric characters:
>
>
> \starttext
>
> \showframe
>
> 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
>
> \stoptext
In mkiv make a lua script using gsub, i.e. something like
s='9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu'
s= string.gsub(s,'(.)',"%1\\hskip0sp")


\starttext
\startluacode
s='9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu'
s= string.gsub(s..s..s,'(.)',"%1\\hskip0sp")
context(s)
\stopluacode
\stoptext

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


Re: [NTG-context] break strings

2011-06-13 Thread Wolfgang Schuster

Am 13.06.2011 um 14:12 schrieb Steffen Wolfrum:

> Hi,
> 
> say I have arbitrary string of alphanumeric characters:
> 
> 
> \starttext
> 
> \showframe
> 
> 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
> 
> \stoptext
> 
> How can I (automatically) force a break at end of line, without manually 
> adding \crlf or \break at break points?

\handletokens ...\with{\hskip 0pt plus .1pt\firstofoneargument}

Wolfgang

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


Re: [NTG-context] break strings

2011-06-13 Thread Steffen Wolfrum

Am 13.06.2011 um 14:19 schrieb luigi scarso:

> On Mon, Jun 13, 2011 at 2:12 PM, Steffen Wolfrum  
> wrote:
>> Hi,
>> 
>> say I have arbitrary string of alphanumeric characters:
>> 
>> 
>> \starttext
>> 
>> \showframe
>> 
>> 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
>> 
>> \stoptext
> In mkiv make a lua script using gsub, i.e. something like
> s='9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu'
> s= string.gsub(s,'(.)',"%1\\hskip0sp")
> 
> 
> \starttext
> \startluacode
> s='9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu'
> s= string.gsub(s..s..s,'(.)',"%1\\hskip0sp")
> context(s)
> \stopluacode
> \stoptext



... ok, compared to this solution it is for sure easier to manually add \crlf  
:o))

The background are hundreds of URL's, which are part of regular text ... now 
transformed in a complicated but working beast:
\startbuffer[myurl:01]\catcode`\%=12 \catcode`\_=12 \catcode`\&=12 
\catcode`\#=12\setupalign[line,block,hanging]\useURL[test][http://www.lfd.m-v.de/dschutz/beschlue/ent49.html#nr.5][][http://www.lfd.m-v.de/dschutz/beschlue/ent49.html#nr.5]\from[test]\removeunwantedspaces\stopbuffer\getbuffer[myurl:01]

If I now again add your lines of luacode too, I go crazy :o)

Is there no handy little context command that could just be pasted before the 
string, like the following?
\useURL[...][...][][\ThisHelps 
9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu]


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


Re: [NTG-context] break strings

2011-06-13 Thread Steffen Wolfrum

Am 13.06.2011 um 14:25 schrieb Wolfgang Schuster:

> 
> Am 13.06.2011 um 14:12 schrieb Steffen Wolfrum:
> 
>> Hi,
>> 
>> say I have arbitrary string of alphanumeric characters:
>> 
>> 
>> \starttext
>> 
>> \showframe
>> 
>> 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
>> 
>> \stoptext
>> 
>> How can I (automatically) force a break at end of line, without manually 
>> adding \crlf or \break at break points?
> 
> \handletokens ...\with{\hskip 0pt plus .1pt\firstofoneargument}


Yes, this helps:

\showframe

\define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus 
.1pt\firstofoneargument}}

Test text test text\ThisHelps 
{9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}

\stoptext


Thank you!!

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


Re: [NTG-context] break strings

2011-06-13 Thread luigi scarso
On Mon, Jun 13, 2011 at 3:18 PM, Steffen Wolfrum  wrote:
>
> Am 13.06.2011 um 14:25 schrieb Wolfgang Schuster:
>
>>
>> Am 13.06.2011 um 14:12 schrieb Steffen Wolfrum:
>>
>>> Hi,
>>>
>>> say I have arbitrary string of alphanumeric characters:
>>>
>>>
>>> \starttext
>>>
>>> \showframe
>>>
>>> 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
>>>
>>> \stoptext
>>>
>>> How can I (automatically) force a break at end of line, without manually 
>>> adding \crlf or \break at break points?
>>
>> \handletokens ...\with{\hskip 0pt plus .1pt\firstofoneargument}
>
>
> Yes, this helps:
>
> \showframe
>
> \define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus 
> .1pt\firstofoneargument}}
>
> Test text test text\ThisHelps 
> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
>
> \stoptext
>
>
> Thank you!!
>
> Steffen
Where is the difference ?

\starttext


\showframe

\define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus
.1pt\firstofoneargument}}

Test text test text\ThisHelps
{9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}

\define[1]\ThisHelpsLuigi{%
\startluacode
s='#1'
s= string.gsub(s,'(.)',"\%1\\hskip0sp")
% maybe only some chars...
%s= string.gsub(s,'[=/]',"\%1\\hskip0sp")
context(s)
\stopluacode}

Test text test text\ThisHelpsLuigi
{9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}

\stoptext


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


Re: [NTG-context] break strings

2011-06-13 Thread Steffen Wolfrum

Am 13.06.2011 um 15:40 schrieb luigi scarso:

> On Mon, Jun 13, 2011 at 3:18 PM, Steffen Wolfrum  
> wrote:
>> 
>> Am 13.06.2011 um 14:25 schrieb Wolfgang Schuster:
>> 
>>> 
>>> Am 13.06.2011 um 14:12 schrieb Steffen Wolfrum:
>>> 
 Hi,
 
 say I have arbitrary string of alphanumeric characters:
 
 
 \starttext
 
 \showframe
 
 9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu
 
 \stoptext
 
 How can I (automatically) force a break at end of line, without manually 
 adding \crlf or \break at break points?
>>> 
>>> \handletokens ...\with{\hskip 0pt plus .1pt\firstofoneargument}
>> 
>> 
>> Yes, this helps:
>> 
>> \showframe
>> 
>> \define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus 
>> .1pt\firstofoneargument}}
>> 
>> Test text test text\ThisHelps 
>> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
>> 
>> \stoptext
>> 
>> 
>> Thank you!!
>> 
>> Steffen
> Where is the difference ?
> 
> \starttext
> 
> 
> \showframe
> 
> \define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus
> .1pt\firstofoneargument}}
> 
> Test text test text\ThisHelps
> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
> 
> \define[1]\ThisHelpsLuigi{%
> \startluacode
> s='#1'
> s= string.gsub(s,'(.)',"\%1\\hskip0sp")
> % maybe only some chars...
> %s= string.gsub(s,'[=/]',"\%1\\hskip0sp")
> context(s)
> \stopluacode}
> 
> Test text test text\ThisHelpsLuigi
> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
> 
> \stoptext


Just my "greenness" with luacode ...

I didn't expect that it could be wrapped so easily in an handy \define command:
context(s) is wrapped in start/stopluacode is wrapped in 
\define[1]\LuigiHelps{...}

Endless possibilities ... great!


Thank you very much for making this clear :o)

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


Re: [NTG-context] break strings

2011-06-13 Thread Wolfgang Schuster

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{1}{\ThisHelps {abcde123xyz}}%
\testfeatureonce{1}{\ThisHelpsLuigi{abcde123xyz}}

\stoptext

Wolfgang

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


Re: [NTG-context] break strings

2011-06-13 Thread luigi scarso
On Mon, Jun 13, 2011 at 3:52 PM, Steffen Wolfrum  wrote:

>> Where is the difference ?
>>
>> \starttext
>>
>>
>> \showframe
>>
>> \define[1]\ThisHelps {\handletokens#1\with{\hskip 0pt plus
>> .1pt\firstofoneargument}}
>>
>> Test text test text\ThisHelps
>> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
>>
>> \define[1]\ThisHelpsLuigi{%
>> \startluacode
>> s='#1'
>> s= string.gsub(s,'(.)',"\%1\\hskip0sp")
>> % maybe only some chars...
>> %s= string.gsub(s,'[=/]',"\%1\\hskip0sp")
>> context(s)
>> \stopluacode}
>>
>> Test text test text\ThisHelpsLuigi
>> {9769387937933hhgiuiuziuziduzid93739837fhieuhifeuhfeiu39739837938398zfhfdkuhfiufhz398739837r98z379dihhfiu}
>>
>> \stoptext
>
>
> Just my "greenness" with luacode ...
>
> I didn't expect that it could be wrapped so easily in an handy \define 
> command:
> context(s) is wrapped in start/stopluacode is wrapped in 
> \define[1]\LuigiHelps{...}
The key point is
 % maybe only some chars...
 %s= string.gsub(s,'[=/]',"\%1\\hskip0sp")
With '[=/]'
you define a set of chars (only '=' and '/' in this example)
so that only '=' => '=\hskip0sp'
and
'/' => '/\hskip0sp'
i.e. breaks appear only on '=' and '/'.
It' possible to define whatever char you want, but you must pay attention to '%'
'#' etc. (as you do with \catcode)

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


Re: [NTG-context] break strings

2011-06-13 Thread luigi scarso
On Mon, Jun 13, 2011 at 3:58 PM, Wolfgang Schuster
 wrote:
>
> Am 13.06.2011 um 15:40 schrieb luigi scarso:
>
>> Where is the difference ?
>
> The TeX solution is faster.
and the Lua's one is usually more flexible.

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


Re: [NTG-context] break strings

2011-06-13 Thread Hans Hagen

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{1}{\ThisHelps {abcde123xyz}}%
\testfeatureonce{1}{\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
___