ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* issue embedding from Lua code
@ 2019-11-01  7:20 Pablo Rodriguez
  2019-11-01  8:13 ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Pablo Rodriguez @ 2019-11-01  7:20 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear list,

I have the following sample:

    \setupinteraction[state=start]
    \starttext
    \startluacode
    function document.special_attachment(reference)
        year = reference:sub(7, 10)
        attachment_url = "https://www.boe.es/buscar/pdf/" ..
        year .. "/" .. reference .. "-consolidado.pdf"
        return attachment_url
    end
    \stopluacode

    \unexpanded\def\giveattachment#1{%
        \cldcontext{document.special_attachment("#1")}}

    \def\cE{BOE-A-1978-31229}

    \attachment[file={\giveattachment{\cE}}, color=red]


\attachment[file={https://www.boe.es/buscar/pdf/1978/BOE-A-1978-31229-consolidado.pdf},
     color=blue]

    \giveattachment{\cE}

    \stoptext

I don’t know why I do get the second attachment, but not the first one.
Lua code seems to be fine (given the last command in the sample).

Could anyone explain me what I’m doing wrong?

Many thanks for your help,

Pablo
--
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: issue embedding from Lua code
  2019-11-01  7:20 issue embedding from Lua code Pablo Rodriguez
@ 2019-11-01  8:13 ` Wolfgang Schuster
  2019-11-01  9:29   ` Hans Hagen
  2019-11-01  9:44   ` Pablo Rodriguez
  0 siblings, 2 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2019-11-01  8:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez

Pablo Rodriguez schrieb am 01.11.2019 um 08:20:
> Dear list,
>
> I have the following sample:
>
>      \setupinteraction[state=start]
>      \starttext
>      \startluacode
>      function document.special_attachment(reference)
>          year = reference:sub(7, 10)
>          attachment_url = "https://www.boe.es/buscar/pdf/" ..
>          year .. "/" .. reference .. "-consolidado.pdf"
>          return attachment_url
>      end
>      \stopluacode
>
>      \unexpanded\def\giveattachment#1{%
>          \cldcontext{document.special_attachment("#1")}}
>
>      \def\cE{BOE-A-1978-31229}
>
>      \attachment[file={\giveattachment{\cE}}, color=red]
>
>
> \attachment[file={https://www.boe.es/buscar/pdf/1978/BOE-A-1978-31229-consolidado.pdf},
>       color=blue]
>
>      \giveattachment{\cE}
>
>      \stoptext
>
> I don’t know why I do get the second attachment, but not the first one.
> Lua code seems to be fine (given the last command in the sample).
>
> Could anyone explain me what I’m doing wrong?
You try to pass a protected (\expanded\def) command to a argument of 
another command
which doesn't work: Remove \unexpanded and your output is as expected.

\def\giveattachment#1%
   {\cldcontext{document.special_attachment("#1")}}

or

\def\giveattachment
   {\cldcontext{document.special_attachment(tokens.scanners.string())}}

Wolfgang

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

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

* Re: issue embedding from Lua code
  2019-11-01  8:13 ` Wolfgang Schuster
@ 2019-11-01  9:29   ` Hans Hagen
  2019-11-01  9:44   ` Pablo Rodriguez
  1 sibling, 0 replies; 7+ messages in thread
From: Hans Hagen @ 2019-11-01  9:29 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 11/1/2019 9:13 AM, Wolfgang Schuster wrote:
> Pablo Rodriguez schrieb am 01.11.2019 um 08:20:
>> Dear list,
>>
>> I have the following sample:
>>
>>      \setupinteraction[state=start]
>>      \starttext
>>      \startluacode
>>      function document.special_attachment(reference)
>>          year = reference:sub(7, 10)
>>          attachment_url = "https://www.boe.es/buscar/pdf/" ..
>>          year .. "/" .. reference .. "-consolidado.pdf"
>>          return attachment_url
>>      end
>>      \stopluacode
>>
>>      \unexpanded\def\giveattachment#1{%
>>          \cldcontext{document.special_attachment("#1")}}
>>
>>      \def\cE{BOE-A-1978-31229}
>>
>>      \attachment[file={\giveattachment{\cE}}, color=red]
>>
>>
>> \attachment[file={https://www.boe.es/buscar/pdf/1978/BOE-A-1978-31229-consolidado.pdf}, 
>>
>>       color=blue]
>>
>>      \giveattachment{\cE}
>>
>>      \stoptext
>>
>> I don’t know why I do get the second attachment, but not the first one.
>> Lua code seems to be fine (given the last command in the sample).
>>
>> Could anyone explain me what I’m doing wrong?
> You try to pass a protected (\expanded\def) command to a argument of 
> another command
> which doesn't work: Remove \unexpanded and your output is as expected.
> 
> \def\giveattachment#1%
>    {\cldcontext{document.special_attachment("#1")}}
> 
> or
> 
> \def\giveattachment
>    {\cldcontext{document.special_attachment(tokens.scanners.string())}}
als also make

        year
        attachment_url

local variables

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
___________________________________________________________________________________

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

* Re: issue embedding from Lua code
  2019-11-01  8:13 ` Wolfgang Schuster
  2019-11-01  9:29   ` Hans Hagen
@ 2019-11-01  9:44   ` Pablo Rodriguez
  2019-11-01 10:08     ` Wolfgang Schuster
  1 sibling, 1 reply; 7+ messages in thread
From: Pablo Rodriguez @ 2019-11-01  9:44 UTC (permalink / raw)
  To: ntg-context

On 11/1/19 9:13 AM, Wolfgang Schuster wrote:
> Pablo Rodriguez schrieb am 01.11.2019 um 08:20:
>> [...]
>> I don’t know why I do get the second attachment, but not the first one.
>> Lua code seems to be fine (given the last command in the sample).
>>
>> Could anyone explain me what I’m doing wrong?
>
> You try to pass a protected (\expanded\def) command to a argument of
> another command
> which doesn't work: Remove \unexpanded and your output is as expected.
>
> \def\giveattachment#1%
>    {\cldcontext{document.special_attachment("#1")}}

Many thanks for your reply, Wolfgang.

Now I understand why it didn’t work.

In my real-world document, I get an error, probably caused by having
\giveattachment deployed in a buffer called inside:

    \start
        \catcode`\#=12 % local change of character TeX category
        \doloopif{\cA}{~=}{}{\getbuffer[main]}
    \stop

This \start..\stop is required to get identifiers in urls (such as
http://a.b/c#d). urls are read from a CSV file using the handlecsv module.

Is there any way to avoid this issue?

> \def\giveattachment
>    {\cldcontext{document.special_attachment(tokens.scanners.string())}}

I’m afraid I cannot make this work.

Many thanks for your help,

Pablo
--
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: issue embedding from Lua code
  2019-11-01  9:44   ` Pablo Rodriguez
@ 2019-11-01 10:08     ` Wolfgang Schuster
  2019-11-01 10:48       ` Pablo Rodriguez
  0 siblings, 1 reply; 7+ messages in thread
From: Wolfgang Schuster @ 2019-11-01 10:08 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez

Pablo Rodriguez schrieb am 01.11.2019 um 10:44:
> On 11/1/19 9:13 AM, Wolfgang Schuster wrote:
>> Pablo Rodriguez schrieb am 01.11.2019 um 08:20:
>>> [...]
>>> I don’t know why I do get the second attachment, but not the first one.
>>> Lua code seems to be fine (given the last command in the sample).
>>>
>>> Could anyone explain me what I’m doing wrong?
>> You try to pass a protected (\expanded\def) command to a argument of
>> another command
>> which doesn't work: Remove \unexpanded and your output is as expected.
>>
>> \def\giveattachment#1%
>>     {\cldcontext{document.special_attachment("#1")}}
> Many thanks for your reply, Wolfgang.
>
> Now I understand why it didn’t work.
>
> In my real-world document, I get an error, probably caused by having
> \giveattachment deployed in a buffer called inside:
>
>      \start
>          \catcode`\#=12 % local change of character TeX category
>          \doloopif{\cA}{~=}{}{\getbuffer[main]}
>      \stop
>
> This \start..\stop is required to get identifiers in urls (such as
> http://a.b/c#d). urls are read from a CSV file using the handlecsv module.
>
> Is there any way to avoid this issue?
1. Fix it in the module to ensure special characters are treated as letters.

2. Use the asciimode environment to make TeX's special characters normal 
letters.

\starttext

\startasciimode
%
&
#
$
^
~
\stopasciimode

\stoptext

Wolfgang

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

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

* Re: issue embedding from Lua code
  2019-11-01 10:08     ` Wolfgang Schuster
@ 2019-11-01 10:48       ` Pablo Rodriguez
  2019-11-01 11:06         ` Wolfgang Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Pablo Rodriguez @ 2019-11-01 10:48 UTC (permalink / raw)
  To: ntg-context

On 11/1/19 11:08 AM, Wolfgang Schuster wrote:
> Pablo Rodriguez schrieb am 01.11.2019 um 10:44:
>> [...]
>>      \start
>>          \catcode`\#=12 % local change of character TeX category
>>          \doloopif{\cA}{~=}{}{\getbuffer[main]}
>>      \stop
>>
>> This \start..\stop is required to get identifiers in urls (such as
>> http://a.b/c#d). urls are read from a CSV file using the handlecsv module.
>>
>> Is there any way to avoid this issue?
> 1. Fix it in the module to ensure special characters are treated as letters.

This would make things way easier, I agree.

BTW, my issue was totally unrelated: missing closing brace (but the
error message in ConTeXt was misleading [at least, to me]).

> 2. Use the asciimode environment to make TeX's special characters normal
> letters.

Is there any ascii mode equivalent for Lua?

I mean, something like "asciimode(whatever)".

Many thanks for your help,

Pablo
--
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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

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

* Re: issue embedding from Lua code
  2019-11-01 10:48       ` Pablo Rodriguez
@ 2019-11-01 11:06         ` Wolfgang Schuster
  0 siblings, 0 replies; 7+ messages in thread
From: Wolfgang Schuster @ 2019-11-01 11:06 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pablo Rodriguez

Pablo Rodriguez schrieb am 01.11.2019 um 11:48:
>> 2. Use the asciimode environment to make TeX's special characters normal
>> letters.
> Is there any ascii mode equivalent for Lua?
>
> I mean, something like "asciimode(whatever)".

You can change catcode regimes to change meaning of the special characters.

\starttext

\startluacode

context.pushcatcodes("text")
context("%")
context("&")
context("#")
context("$")
context("~")
context.popcatcodes()

\stopluacode

\stoptext

Wolfgang

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

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

end of thread, other threads:[~2019-11-01 11:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01  7:20 issue embedding from Lua code Pablo Rodriguez
2019-11-01  8:13 ` Wolfgang Schuster
2019-11-01  9:29   ` Hans Hagen
2019-11-01  9:44   ` Pablo Rodriguez
2019-11-01 10:08     ` Wolfgang Schuster
2019-11-01 10:48       ` Pablo Rodriguez
2019-11-01 11:06         ` Wolfgang Schuster

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