issue embedding from Lua code
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
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
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 -----------------------------------------------------------------
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
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
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
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
participants (3)
-
Hans Hagen
-
Pablo Rodriguez
-
Wolfgang Schuster