ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Hyphenation of URLs with and without interaction
@ 2004-01-23 10:59 Tobias Burnus
  2004-01-25 13:30 ` Hans Hagen
  2004-01-26 12:20 ` Willi Egger
  0 siblings, 2 replies; 4+ messages in thread
From: Tobias Burnus @ 2004-01-23 10:59 UTC (permalink / raw)


Hello,

If you run the test case below, once with and once without
\statupinteraction[state=start], you realize that this influences the
hyphenation.

Using interaction, the URL is only hyphenated at '/', '.' etc.
Using no interaction, also the words are hyphenated.

How can I get also hyphenated words with interaction enabled?

-----------------------------------------------------------
\showframe
\setupinteraction[state=start]
\def\gotoURL#1{\useURL[foo][#1]\goto{\url[foo]}[url(foo)]}

\starttext

\hskip5cm\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}

\stoptext
-----------------------------------------------------------

Regards,

Tobias

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

* Re: Hyphenation of URLs with and without interaction
  2004-01-23 10:59 Hyphenation of URLs with and without interaction Tobias Burnus
@ 2004-01-25 13:30 ` Hans Hagen
  2004-01-25 20:00   ` Tobias Burnus
  2004-01-26 12:20 ` Willi Egger
  1 sibling, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2004-01-25 13:30 UTC (permalink / raw)


At 11:59 23/01/2004, you wrote:
>Hello,
>
>If you run the test case below, once with and once without
>\statupinteraction[state=start], you realize that this influences the
>hyphenation.
>
>Using interaction, the URL is only hyphenated at '/', '.' etc.
>Using no interaction, also the words are hyphenated.
>
>How can I get also hyphenated words with interaction enabled?
>
>-----------------------------------------------------------
>\showframe
>\setupinteraction[state=start]
>\def\gotoURL#1{\useURL[foo][#1]\goto{\url[foo]}[url(foo)]}
>
>\starttext
>
>\hskip5cm\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}
>
>\stoptext
>-----------------------------------------------------------

in context, hyphenation of interactive references is a rather tricky thing; 
this has to do with the fact that i want comfortable clickable areas. 
(another reason is that it should work with several backends. Some day i 
may offer an alternative solution (backend dependent).

In the case of url's it's even more tricky since one cannot for instance 
use hyphenation patterns for it, so we have to rely on parsing. And, with 
parsing, we run into those catcode handling situations. When i have time, 
i'll rewrite the parser for etex (time is near that we drop tex in favor of 
etex) which is cleaner (but not entirely upward compatible).

Now to your problem. Hyphenation is not done here and does not make sense 
either (mixed case)


\bgroup \catcode`\~=\active \catcode`\/=\active

\unexpanded\gdef\hyphenatedurl#1% {}{} handles accents
   {\bgroup
    \ifnum\hyphenpenalty<10000 \else
      \def\discretionary##1##2##3{##1\allowbreak##2}%
    \fi
    \obeyhyphens
    \def\splitbefore##1%
      {\setbox\scratchbox=\hbox{##1{}{}}%
       \ifcase\urlsplitmode
         \box\scratchbox
       \or
         \postwordbreak\box\scratchbox\prewordbreak
       \or
         \prewordbreak\discretionary{\box\scratchbox}{}{\box\scratchbox}\prewordbreak
       \else
         \postwordbreak\box\scratchbox\prewordbreak
       \fi}%
    \def\splitafter##1%
      {\ifcase\urlsplitmode
         ##1{}{}%
       \or
         \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
       \or
         \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
       \else
         \prewordbreak\discretionary{}{##1{}{}}{##1{}{}}\prewordbreak
       \fi}%
    \def\flushurl%
      {\savedurl\let\savedurl\empty}%
    \def\\%
      {\spliturl\#}%
    \let\~=\lettertilde\let~=\~%
    \let\/=\letterslash\let/=\/%
    \let\savedurl\empty
\scratchcounter\zerocount
    \handletokens#1\with\scanurl\savedurl
    \egroup}

\egroup

\def\scanurl#1%
   {\advance\scratchcounter\plusone
    \ifx#1\~%
      \flushurl\splitbefore\~%
    \else\ifx#1\#%
      \flushurl\splitbefore\#%
    \else\ifx#1\&%
      \flushurl\splitbefore\&%
    \else\ifx#1\%%
      \flushurl\splitbefore\%%
    \else\ifx#1\_%
      \flushurl\splitbefore\_%
    \else\if\noexpand#1\relax
      #1%
    \else\ifnum\catcode`#1=8
      \flushurl\splitbefore\_%
    \else\ifnum\catcode`#1=6
      \flushurl\splitbefore\#%
    \else\ifnum\catcode`#1=4
      \flushurl\splitbefore\&%
    \else\if#1\lettertilde
      \flushurl\splitbefore\~%
    \else\if#1\letterpercent
      \flushurl\splitbefore\%%
    \else\if#1\letterunderscore
      \flushurl\splitbefore\_%
    \else\if#1\letterquestionmark
      \flushurl\splitafter\letterquestionmark
    \else\if#1\letterat
      \flushurl\splitafter\letterat
    \else\if#1\letterslash
      \edef\savedurl{\savedurl\letterslash}%
    \else\if#1+%
      \flushurl\splitafter+%
    \else\if#1:%
      \flushurl\splitafter:%
    \else\if#1.%
      \flushurl\splitafter.%
    \else\if#1(%
      \flushurl\splitbefore(%
    \else\if#1)%
      \flushurl\splitafter)%
    \else
      \ifx\savedurl\empty\else
        \splitbefore\savedurl
        \let\savedurl\empty
      \fi
      \ifcase\urlhyphenmethod
        #1%
      \else
        \ifnum\scratchcounter>\plusthree % so, \http: will not break
          \edef\savedurl{#1}%
        \else
          #1%
        \fi
      \fi
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\chardef\urlhyphenmethod=0

\setupinteraction[state=start]\showframe

\def\gotoURL#1{\useURL[foo][#1][#1]\goto{\url[foo]}[url(foo)]}

\starttext

\chardef\urlhyphenmethod=0

\hsize1pt\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}

\chardef\urlhyphenmethod=1

\hsize1pt\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}

\stoptext

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

* Re: Hyphenation of URLs with and without interaction
  2004-01-25 13:30 ` Hans Hagen
@ 2004-01-25 20:00   ` Tobias Burnus
  0 siblings, 0 replies; 4+ messages in thread
From: Tobias Burnus @ 2004-01-25 20:00 UTC (permalink / raw)


Hello,

On Sun, Jan 25, 2004 at 02:30:11PM +0100, Hans Hagen wrote:
> in context, hyphenation of interactive references is a rather tricky thing; 
> this has to do with the fact that i want comfortable clickable areas. 
> (another reason is that it should work with several backends. Some day i 
> may offer an alternative solution (backend dependent).
Well, with your code I now can work around one since hyphenation
problem, which allows me to add some hyperlinks to a document which is
mainly intended for print out. The only minor glitch for a single URL is
instead of 'Cylindric-
alCoordinates.html', I get not 'Cylindr
icalCoordinates.html', but this is better than being cut at the edge of
the page. :-)

Thanks for the fast solution.

Hmm, maybe the first one will be \urlhyphenmethod=2 ;)

Regards,

Tobias

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

* Re: Hyphenation of URLs with and without  interaction
  2004-01-23 10:59 Hyphenation of URLs with and without interaction Tobias Burnus
  2004-01-25 13:30 ` Hans Hagen
@ 2004-01-26 12:20 ` Willi Egger
  1 sibling, 0 replies; 4+ messages in thread
From: Willi Egger @ 2004-01-26 12:20 UTC (permalink / raw)


Hello Mathias,

your question forwarded by Tobias Burnus has been discussd a couple of 
days ago on this list. I send you the reply given by Hans Hagen:

At 11:59 23/01/2004, you wrote:
>Hello,
>
>If you run the test case below, once with and once without
>\statupinteraction[state=start], you realize that this influences the
>hyphenation.
>
>Using interaction, the URL is only hyphenated at '/', '.' etc.
>Using no interaction, also the words are hyphenated.
>
>How can I get also hyphenated words with interaction enabled?
>
>-----------------------------------------------------------
>\showframe
>\setupinteraction[state=start]
>\def\gotoURL#1{\useURL[foo][#1]\goto{\url[foo]}[url(foo)]}
>
>\starttext
>
>\hskip5cm\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}
>
>\stoptext
>-----------------------------------------------------------

in context, hyphenation of interactive references is a rather tricky thing;
this has to do with the fact that i want comfortable clickable areas.
(another reason is that it should work with several backends. Some day i
may offer an alternative solution (backend dependent).

In the case of url's it's even more tricky since one cannot for instance
use hyphenation patterns for it, so we have to rely on parsing. And, with
parsing, we run into those catcode handling situations. When i have time,
i'll rewrite the parser for etex (time is near that we drop tex in favor of
etex) which is cleaner (but not entirely upward compatible).

Now to your problem. Hyphenation is not done here and does not make sense
either (mixed case)


\bgroup \catcode`\~=\active \catcode`\/=\active

\unexpanded\gdef\hyphenatedurl#1% {}{} handles accents
   {\bgroup
    \ifnum\hyphenpenalty<10000 \else
      \def\discretionary##1##2##3{##1\allowbreak##2}%
    \fi
    \obeyhyphens
    \def\splitbefore##1%
      {\setbox\scratchbox=\hbox{##1{}{}}%
       \ifcase\urlsplitmode
         \box\scratchbox
       \or
         \postwordbreak\box\scratchbox\prewordbreak
       \or
 
\prewordbreak\discretionary{\box\scratchbox}{}{\box\scratchbox}\prewordbreak
       \else
         \postwordbreak\box\scratchbox\prewordbreak
       \fi}%
    \def\splitafter##1%
      {\ifcase\urlsplitmode
         ##1{}{}%
       \or
         \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
       \or
         \prewordbreak\discretionary{##1{}{}}{}{##1{}{}}\prewordbreak
       \else
         \prewordbreak\discretionary{}{##1{}{}}{##1{}{}}\prewordbreak
       \fi}%
    \def\flushurl%
      {\savedurl\let\savedurl\empty}%
    \def\\%
      {\spliturl\#}%
    \let\~=\lettertilde\let~=\~%
    \let\/=\letterslash\let/=\/%
    \let\savedurl\empty
\scratchcounter\zerocount
    \handletokens#1\with\scanurl\savedurl
    \egroup}

\egroup

\def\scanurl#1%
   {\advance\scratchcounter\plusone
    \ifx#1\~%
      \flushurl\splitbefore\~%
    \else\ifx#1\#%
      \flushurl\splitbefore\#%
    \else\ifx#1\&%
      \flushurl\splitbefore\&%
    \else\ifx#1\%%
      \flushurl\splitbefore\%%
    \else\ifx#1\_%
      \flushurl\splitbefore\_%
    \else\if\noexpand#1\relax
      #1%
    \else\ifnum\catcode`#1=8
      \flushurl\splitbefore\_%
    \else\ifnum\catcode`#1=6
      \flushurl\splitbefore\#%
    \else\ifnum\catcode`#1=4
      \flushurl\splitbefore\&%
    \else\if#1\lettertilde
      \flushurl\splitbefore\~%
    \else\if#1\letterpercent
      \flushurl\splitbefore\%%
    \else\if#1\letterunderscore
      \flushurl\splitbefore\_%
    \else\if#1\letterquestionmark
      \flushurl\splitafter\letterquestionmark
    \else\if#1\letterat
      \flushurl\splitafter\letterat
    \else\if#1\letterslash
      \edef\savedurl{\savedurl\letterslash}%
    \else\if#1+%
      \flushurl\splitafter+%
    \else\if#1:%
      \flushurl\splitafter:%
    \else\if#1.%
      \flushurl\splitafter.%
    \else\if#1(%
      \flushurl\splitbefore(%
    \else\if#1)%
      \flushurl\splitafter)%
    \else
      \ifx\savedurl\empty\else
        \splitbefore\savedurl
        \let\savedurl\empty
      \fi
      \ifcase\urlhyphenmethod
        #1%
      \else
        \ifnum\scratchcounter>\plusthree % so, \http: will not break
          \edef\savedurl{#1}%
        \else
          #1%
        \fi
      \fi
    \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}

\chardef\urlhyphenmethod=0

\setupinteraction[state=start]\showframe

\def\gotoURL#1{\useURL[foo][#1][#1]\goto{\url[foo]}[url(foo)]}

\starttext

\chardef\urlhyphenmethod=0

\hsize1pt\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}

\chardef\urlhyphenmethod=1

\hsize1pt\gotoURL{http://www.physik.fu-berlin.de/SomeVeryVeryVeryLongDirectory/And/AQuiteLongFileName.html}

\stoptext


_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

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

end of thread, other threads:[~2004-01-26 12:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-23 10:59 Hyphenation of URLs with and without interaction Tobias Burnus
2004-01-25 13:30 ` Hans Hagen
2004-01-25 20:00   ` Tobias Burnus
2004-01-26 12:20 ` Willi Egger

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