[NTG-context] \replaceword with spaces

Hans Hagen j.hagen at xs4all.nl
Sun Apr 15 18:02:04 CEST 2018


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


More information about the ntg-context mailing list