On 12/10/2014 10:58 PM, Hans Hagen wrote:
> On 12/10/2014 8:15 PM, Pablo Rodriguez wrote:
>> On 12/09/2014 12:07 AM, Hans Hagen wrote:
>>> On 12/8/2014 5:47 PM, Pablo Rodriguez wrote:
>>>> [..]
>>>> And sorry for asking this again, but I need underscore hyphenation with
>>>> the underscore character from the font and only for the \tex and
>>>> \hyphenatedurl commands (not for the rest of the text).
>>>> [...]
>>>
>>> just a variant of the addfunyhyphen:
>>
>> Many thanks for your sample, Hans.
>>
>> It really works great.
>>
>> Sorry for asking this again: would it be possible to add this feature
>> also to \hyphenatedurl.
>>
>> I’m composing a book on A6 and it is really hard to add some urls.
> 
> some code from an upcoming manual:

Many thanks for the sample, Hans.

For some strange reason, the line:

         ["/"]  = "before", ["\\"] = "before",

removes the backslashes in your sample. Setting \hsize to \zeropoint or
other length seems to avoid the problem.

What I had in mind is something different. Sorry for not having
explained in a more accurate manner before. The current line breaking
(without hyphenation) in \hyphenatedurl is fine for me.

The issue is that there are some urls that contain long words inside.
Here is one of them:

        http://www.nietzschesource.org/#eKGWB/GD-Sprueche-12.

And only for those words underscore hyphenation is required. They should
be hyphenated as any other word, only using the underscore hyphen.

This would mean that urls would have two line breaks: one without hyphen
(as it was before) and another extra with underscore.

Many thanks for your help,


Pablo


> \startluacode
>      local specials = {
>          ["!"]  = "before", ["?"]  = "before",
>          ['"']  = "before", ["'"]  = "before",
>          ["/"]  = "before", ["\\"] = "before",
>          ["#"]  = "before",
>          ["$"]  = "before",
>          ["%"]  = "before",
>          ["&"]  = "before",
>          ["*"]  = "before",
>          ["+"]  = "before", ["-"]  = "before",
>          [","]  = "before", ["."]  = "before",
>          [":"]  = "before", [";"]  = "before",
>          ["<"]  = "before", [">"]  = "before",
>          ["="]  = "before",
>          ["@"]  = "before",
>          ["("]  = "before",
>          ["["]  = "before",
>          ["{"]  = "before",
>          ["^"]  = "before", ["_"]  = "before",
>          ["`"]  = "before",
>          ["|"]  = "before",
>          ["~"]  = "before",
>          --
>          [")"]  = "after",
>          ["]"]  = "after",
>          ["}"]  = "after",
>      }
> 
>      languages.hyphenators.traditional.installmethod("url",
>          function(dictionary,word,n)
>              local t = { }
>              for i=1,#word do
>                  local w = word[i]
>                  local s = specials[w]
>                  if s == "after" then
>                      s = {
>                          start  = 1,
>                          length = 1,
>                          after  = w,
>                          left   = false,
>                          right  = false,
>                      }
>                      specials[w] = s
>                  elseif s == "before" then
>                      s = {
>                          start  = 1,
>                          length = 1,
>                          before = w,
>                          left   = false,
>                       -- right  = false,
>                      }
>                      specials[w] = s
>                  end
>                  t[i] = s or false
>              end
>              return t
>          end
>      )
> \stopluacode
> 
> \startluacode
> 
>      function document.addfunnyhyphen(tfmdata)
>          local underscore = utf.byte("_")
>          local char       = tfmdata.characters[underscore]
>          tfmdata.characters[0xFE000]   = {
>              width    = 0,
>              height   = 0,
>              depth    = 0,
>              commands = {
>                  { "right", -char.width },
>                  { "down", char.depth },
>                  { "slot", 1, underscore },
>              }
>          }
>      end
> 
>  
> utilities.sequencers.appendaction("aftercopyingcharacters","after","document.addfunnyhyphen")
> 
> \stopluacode
> 
> \definehyphenationfeatures
>    [url]
>    [characters=all,
>     righthyphenchar="FE000,
>     alternative=url]
> 
> \setuphyphenation[method=traditional]
> 
> \unexpanded\def\hyphenatedurl#1%
>    {\dontleavehmode
>     \begingroup
>     \tt
>     \sethyphenationfeatures[url]%
>     #1%
>     \endgroup}
> 
> \starttext
> 
> \hsize5mm
> \hyphenatedurl{http://www.pragma-ade.nl}
> 
> \stoptext



-- 
http://www.ousia.tk
___________________________________________________________________________________
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
___________________________________________________________________________________

Reply via email to