ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: \replaceword with spaces
Date: Sun, 15 Apr 2018 18:02:04 +0200	[thread overview]
Message-ID: <294c97d6-67d3-84d7-babd-726e4e49a375@xs4all.nl> (raw)
In-Reply-To: <63212a22-e421-fc61-cdb7-c42831992003@gmx.es>

On 4/15/2018 1:30 PM, Pablo Rodriguez wrote:
> Dear list,
> 
> I have the following sample:
> 
>      \replaceword[some][via ][Vía]
>      \replaceword[some][calle ][c/ ]
>      \replaceword[some][ calle][ Calle]
>      \starttext
>      \startTEXpage[offset=2em]
>      This is what I get:
> 
>      \setreplacements[some]%
>      calle via del viaducto de la calle
> 
>      \resetreplacements
>      This is what I need:
> 
>      c/ Vía del viaducto de la Calle
>      \stopTEXpage
>      \stoptext
> 
> Is there any way to get spaces in the string to be replaced?
not with a lot of effort on my end which i'm not willing to invest in 
something that is just a hack for bad input ... tex has no spaces so 
then we need other magic

anyway, i added a bogus lookup to the font handler that will remove 
characters so in a next beta you can do this (some upbeat music in the 
background so i could convince myself)

\startluacode
      fonts.handlers.otf.addfeature {
          name    = "crap",
          type    = "chainsubstitution",
          prepend = true,
          lookups = {
              {
                  type = "multiple",
                  data = {
                      ["v"] = { "V", "í", "a" },
                  },
              },
              {
                  type = "multiple",
                  data = {
                      ["c"] = { "c", "/" },
                  },
              },
              {
                  type = "substitution",
                  data = {
                      ["c"] = "C",
                  },
              },
          },
          data = {
              rules = {
                  {
                      comment = "'via' => 'Vía'",
                      current = { { "v" }, { "i" }, { "a" } },
                      after   = { { " " } },
                      lookups = { 1, 0, 0 },
                  },
                  {
                      comment = "'calle ' => 'c/ '",
                      current = { { "c" }, { "a" }, { "l" }, { "l" }, { 
"e" } },
                      after   = { { " " } },
                      lookups = { 2, 0, 0, 0, 0 },
                  },
                  {
                      comment = "' calle' => ' Calle'",
                      before  = { { " " } },
                      current = { { "c" } },
                      after   = { { "a" }, { "l" }, { "l" }, { "e" } },
                      lookups = { 3 },
                  },
              },
          },
      }
\stopluacode

\definefontfeature[default][default][crap=yes]

\starttext

\startTEXpage[offset=2em]
     \type{text:} \type{calle via del viaducto de la calle}

     \type{done:} calle via del viaducto via de la calle

     \type{okay:} c/ Vía del viaducto Vía de la Calle
\stopTEXpage

\stoptext

one could make a constructor for this but would hide the weirdness of it 
... yet another obscure feature

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2018-04-15 16:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-15 11:30 Pablo Rodriguez
2018-04-15 16:02 ` Hans Hagen [this message]
2018-04-15 16:14   ` Pablo Rodriguez
2018-04-15 16:39     ` Hans Hagen
2018-04-15 19:12       ` Pablo Rodriguez
2018-04-15 16:22   ` Floris van Manen
2018-04-15 16:42     ` Hans Hagen
2018-04-15 17:07       ` Floris van Manen
2018-04-15 17:23         ` Hans Hagen
2018-04-15 17:14   ` luigi scarso

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=294c97d6-67d3-84d7-babd-726e4e49a375@xs4all.nl \
    --to=j.hagen@xs4all.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).