* break strings
@ 2011-06-13 12:12 Steffen Wolfrum
2011-06-13 12:19 ` luigi scarso
2011-06-13 12:25 ` Wolfgang Schuster
0 siblings, 2 replies; 11+ messages in thread
From: Steffen Wolfrum @ 2011-06-13 12:12 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 12:12 break strings Steffen Wolfrum
@ 2011-06-13 12:19 ` luigi scarso
2011-06-13 13:07 ` Steffen Wolfrum
2011-06-13 12:25 ` Wolfgang Schuster
1 sibling, 1 reply; 11+ messages in thread
From: luigi scarso @ 2011-06-13 12:19 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Mon, Jun 13, 2011 at 2:12 PM, Steffen Wolfrum <context@st.estfiles.de> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 12:12 break strings Steffen Wolfrum
2011-06-13 12:19 ` luigi scarso
@ 2011-06-13 12:25 ` Wolfgang Schuster
2011-06-13 13:18 ` Steffen Wolfrum
1 sibling, 1 reply; 11+ messages in thread
From: Wolfgang Schuster @ 2011-06-13 12:25 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 12:19 ` luigi scarso
@ 2011-06-13 13:07 ` Steffen Wolfrum
0 siblings, 0 replies; 11+ messages in thread
From: Steffen Wolfrum @ 2011-06-13 13:07 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 13.06.2011 um 14:19 schrieb luigi scarso:
> On Mon, Jun 13, 2011 at 2:12 PM, Steffen Wolfrum <context@st.estfiles.de> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 12:25 ` Wolfgang Schuster
@ 2011-06-13 13:18 ` Steffen Wolfrum
2011-06-13 13:40 ` luigi scarso
0 siblings, 1 reply; 11+ messages in thread
From: Steffen Wolfrum @ 2011-06-13 13:18 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
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:58 ` Wolfgang Schuster
0 siblings, 2 replies; 11+ messages in thread
From: luigi scarso @ 2011-06-13 13:40 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Mon, Jun 13, 2011 at 3:18 PM, Steffen Wolfrum <context@st.estfiles.de> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
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
1 sibling, 1 reply; 11+ messages in thread
From: Steffen Wolfrum @ 2011-06-13 13:52 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 13.06.2011 um 15:40 schrieb luigi scarso:
> On Mon, Jun 13, 2011 at 3:18 PM, Steffen Wolfrum <context@st.estfiles.de> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 13:40 ` luigi scarso
2011-06-13 13:52 ` Steffen Wolfrum
@ 2011-06-13 13:58 ` Wolfgang Schuster
2011-06-13 14:02 ` luigi scarso
2011-06-13 20:19 ` Hans Hagen
1 sibling, 2 replies; 11+ messages in thread
From: Wolfgang Schuster @ 2011-06-13 13:58 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 13:52 ` Steffen Wolfrum
@ 2011-06-13 13:59 ` luigi scarso
0 siblings, 0 replies; 11+ messages in thread
From: luigi scarso @ 2011-06-13 13:59 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Mon, Jun 13, 2011 at 3:52 PM, Steffen Wolfrum <context@st.estfiles.de> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 13:58 ` Wolfgang Schuster
@ 2011-06-13 14:02 ` luigi scarso
2011-06-13 20:19 ` Hans Hagen
1 sibling, 0 replies; 11+ messages in thread
From: luigi scarso @ 2011-06-13 14:02 UTC (permalink / raw)
To: mailing list for ConTeXt users
On Mon, Jun 13, 2011 at 3:58 PM, Wolfgang Schuster
<schuster.wolfgang@googlemail.com> 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: break strings
2011-06-13 13:58 ` Wolfgang Schuster
2011-06-13 14:02 ` luigi scarso
@ 2011-06-13 20:19 ` Hans Hagen
1 sibling, 0 replies; 11+ messages in thread
From: Hans Hagen @ 2011-06-13 20:19 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-06-13 20:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-13 12:12 break strings 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 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).