ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Willi Egger <w.egger@boede.nl>
Subject: Re: Hyphenation of URLs with and without  interaction
Date: Mon, 26 Jan 2004 13:20:10 +0100	[thread overview]
Message-ID: <401505FA.1090000@boede.nl> (raw)
In-Reply-To: <20040123105933.GA15024@physik.fu-berlin.de>

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

      parent reply	other threads:[~2004-01-26 12:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-23 10:59 Tobias Burnus
2004-01-25 13:30 ` Hans Hagen
2004-01-25 20:00   ` Tobias Burnus
2004-01-26 12:20 ` Willi Egger [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=401505FA.1090000@boede.nl \
    --to=w.egger@boede.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).