ConTeXt does not load png file given by lua code

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












6















This is my code:



defineexpandable[1]background
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"


tex.sprint(cases[#1])



starttext
background1 % (1)
externalfigure[noise-blue.png][width=4cm] % (2)
externalfigure[background1][width=4cm] % (3)
stoptext


(1) gives me noise-blue.png in the output.
(2) correctly renders the image noise-blue.png.
(3) gives a gray box with



name: noise-blue.png
file: noise-blue.png
state: unknown


Why doesn't it render the image?










share|improve this question






















  • The background command already exists in ConTeXt, use Background instead.

    – Wolfgang Schuster
    Jan 26 at 16:00















6















This is my code:



defineexpandable[1]background
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"


tex.sprint(cases[#1])



starttext
background1 % (1)
externalfigure[noise-blue.png][width=4cm] % (2)
externalfigure[background1][width=4cm] % (3)
stoptext


(1) gives me noise-blue.png in the output.
(2) correctly renders the image noise-blue.png.
(3) gives a gray box with



name: noise-blue.png
file: noise-blue.png
state: unknown


Why doesn't it render the image?










share|improve this question






















  • The background command already exists in ConTeXt, use Background instead.

    – Wolfgang Schuster
    Jan 26 at 16:00













6












6








6








This is my code:



defineexpandable[1]background
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"


tex.sprint(cases[#1])



starttext
background1 % (1)
externalfigure[noise-blue.png][width=4cm] % (2)
externalfigure[background1][width=4cm] % (3)
stoptext


(1) gives me noise-blue.png in the output.
(2) correctly renders the image noise-blue.png.
(3) gives a gray box with



name: noise-blue.png
file: noise-blue.png
state: unknown


Why doesn't it render the image?










share|improve this question














This is my code:



defineexpandable[1]background
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"


tex.sprint(cases[#1])



starttext
background1 % (1)
externalfigure[noise-blue.png][width=4cm] % (2)
externalfigure[background1][width=4cm] % (3)
stoptext


(1) gives me noise-blue.png in the output.
(2) correctly renders the image noise-blue.png.
(3) gives a gray box with



name: noise-blue.png
file: noise-blue.png
state: unknown


Why doesn't it render the image?







luatex context expansion






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 26 at 15:14









flyxflyx

944614




944614












  • The background command already exists in ConTeXt, use Background instead.

    – Wolfgang Schuster
    Jan 26 at 16:00

















  • The background command already exists in ConTeXt, use Background instead.

    – Wolfgang Schuster
    Jan 26 at 16:00
















The background command already exists in ConTeXt, use Background instead.

– Wolfgang Schuster
Jan 26 at 16:00





The background command already exists in ConTeXt, use Background instead.

– Wolfgang Schuster
Jan 26 at 16:00










2 Answers
2






active

oldest

votes


















9














You add spaces in the output of your command at the begin and end of the definition.



defineexpandable[1]Background
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"

tex.sprint(cases[#1])



starttext
“Background1”
stoptext


enter image description here



To get rid of the spaces you have to add a comment sign after the braces.



defineexpandable[1]Background%
directlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"

tex.sprint(cases[#1])
%


starttext
“Background1”
stoptext


enter image description here



You can also use the texdefinition environment to create the command which doesn’t convert the end of a line into a space.



starttexdefinition Background #1
startlua
local cases =
"noise-blue.png",
"noise-yellow.png",
"noise-red.png",
"noise-green.png"

context(cases[#1])
stoplua
stoptexdefinition


Alternative solution



A different way to create a index for your images is the setvariables which you can use to assign a key to each image. The graphics can than be accessed with the getvariable command.



setvariables
[background]
[1=noise-blue.png,
2=noise-yellow.png,
3=noise-red.png,
4=noise-green.png]

starttext
“getvariablebackground1”
stoptext





share|improve this answer
































    6














    As an alternative to Wolfgang's answer and as alternative to your Lua solution, you might want to consider using useexternalfigure which allows you to name figures.



    useexternalfigure[background:1][noise-blue.png]
    useexternalfigure[background:2][noise-yellow.png]
    useexternalfigure[background:3][noise-red.png]
    useexternalfigure[background:4][noise-green.png]

    starttext
    externalfigure[background:1][width=4cm]
    stoptext





    share|improve this answer























    • Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

      – flyx
      Jan 26 at 21:43










    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471969%2fcontext-does-not-load-png-file-given-by-lua-code%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    You add spaces in the output of your command at the begin and end of the definition.



    defineexpandable[1]Background
    directlua
    local cases =
    "noise-blue.png",
    "noise-yellow.png",
    "noise-red.png",
    "noise-green.png"

    tex.sprint(cases[#1])



    starttext
    “Background1”
    stoptext


    enter image description here



    To get rid of the spaces you have to add a comment sign after the braces.



    defineexpandable[1]Background%
    directlua
    local cases =
    "noise-blue.png",
    "noise-yellow.png",
    "noise-red.png",
    "noise-green.png"

    tex.sprint(cases[#1])
    %


    starttext
    “Background1”
    stoptext


    enter image description here



    You can also use the texdefinition environment to create the command which doesn’t convert the end of a line into a space.



    starttexdefinition Background #1
    startlua
    local cases =
    "noise-blue.png",
    "noise-yellow.png",
    "noise-red.png",
    "noise-green.png"

    context(cases[#1])
    stoplua
    stoptexdefinition


    Alternative solution



    A different way to create a index for your images is the setvariables which you can use to assign a key to each image. The graphics can than be accessed with the getvariable command.



    setvariables
    [background]
    [1=noise-blue.png,
    2=noise-yellow.png,
    3=noise-red.png,
    4=noise-green.png]

    starttext
    “getvariablebackground1”
    stoptext





    share|improve this answer





























      9














      You add spaces in the output of your command at the begin and end of the definition.



      defineexpandable[1]Background
      directlua
      local cases =
      "noise-blue.png",
      "noise-yellow.png",
      "noise-red.png",
      "noise-green.png"

      tex.sprint(cases[#1])



      starttext
      “Background1”
      stoptext


      enter image description here



      To get rid of the spaces you have to add a comment sign after the braces.



      defineexpandable[1]Background%
      directlua
      local cases =
      "noise-blue.png",
      "noise-yellow.png",
      "noise-red.png",
      "noise-green.png"

      tex.sprint(cases[#1])
      %


      starttext
      “Background1”
      stoptext


      enter image description here



      You can also use the texdefinition environment to create the command which doesn’t convert the end of a line into a space.



      starttexdefinition Background #1
      startlua
      local cases =
      "noise-blue.png",
      "noise-yellow.png",
      "noise-red.png",
      "noise-green.png"

      context(cases[#1])
      stoplua
      stoptexdefinition


      Alternative solution



      A different way to create a index for your images is the setvariables which you can use to assign a key to each image. The graphics can than be accessed with the getvariable command.



      setvariables
      [background]
      [1=noise-blue.png,
      2=noise-yellow.png,
      3=noise-red.png,
      4=noise-green.png]

      starttext
      “getvariablebackground1”
      stoptext





      share|improve this answer



























        9












        9








        9







        You add spaces in the output of your command at the begin and end of the definition.



        defineexpandable[1]Background
        directlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        tex.sprint(cases[#1])



        starttext
        “Background1”
        stoptext


        enter image description here



        To get rid of the spaces you have to add a comment sign after the braces.



        defineexpandable[1]Background%
        directlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        tex.sprint(cases[#1])
        %


        starttext
        “Background1”
        stoptext


        enter image description here



        You can also use the texdefinition environment to create the command which doesn’t convert the end of a line into a space.



        starttexdefinition Background #1
        startlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        context(cases[#1])
        stoplua
        stoptexdefinition


        Alternative solution



        A different way to create a index for your images is the setvariables which you can use to assign a key to each image. The graphics can than be accessed with the getvariable command.



        setvariables
        [background]
        [1=noise-blue.png,
        2=noise-yellow.png,
        3=noise-red.png,
        4=noise-green.png]

        starttext
        “getvariablebackground1”
        stoptext





        share|improve this answer















        You add spaces in the output of your command at the begin and end of the definition.



        defineexpandable[1]Background
        directlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        tex.sprint(cases[#1])



        starttext
        “Background1”
        stoptext


        enter image description here



        To get rid of the spaces you have to add a comment sign after the braces.



        defineexpandable[1]Background%
        directlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        tex.sprint(cases[#1])
        %


        starttext
        “Background1”
        stoptext


        enter image description here



        You can also use the texdefinition environment to create the command which doesn’t convert the end of a line into a space.



        starttexdefinition Background #1
        startlua
        local cases =
        "noise-blue.png",
        "noise-yellow.png",
        "noise-red.png",
        "noise-green.png"

        context(cases[#1])
        stoplua
        stoptexdefinition


        Alternative solution



        A different way to create a index for your images is the setvariables which you can use to assign a key to each image. The graphics can than be accessed with the getvariable command.



        setvariables
        [background]
        [1=noise-blue.png,
        2=noise-yellow.png,
        3=noise-red.png,
        4=noise-green.png]

        starttext
        “getvariablebackground1”
        stoptext






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 26 at 22:40

























        answered Jan 26 at 15:59









        Wolfgang SchusterWolfgang Schuster

        5,6011711




        5,6011711





















            6














            As an alternative to Wolfgang's answer and as alternative to your Lua solution, you might want to consider using useexternalfigure which allows you to name figures.



            useexternalfigure[background:1][noise-blue.png]
            useexternalfigure[background:2][noise-yellow.png]
            useexternalfigure[background:3][noise-red.png]
            useexternalfigure[background:4][noise-green.png]

            starttext
            externalfigure[background:1][width=4cm]
            stoptext





            share|improve this answer























            • Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

              – flyx
              Jan 26 at 21:43















            6














            As an alternative to Wolfgang's answer and as alternative to your Lua solution, you might want to consider using useexternalfigure which allows you to name figures.



            useexternalfigure[background:1][noise-blue.png]
            useexternalfigure[background:2][noise-yellow.png]
            useexternalfigure[background:3][noise-red.png]
            useexternalfigure[background:4][noise-green.png]

            starttext
            externalfigure[background:1][width=4cm]
            stoptext





            share|improve this answer























            • Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

              – flyx
              Jan 26 at 21:43













            6












            6








            6







            As an alternative to Wolfgang's answer and as alternative to your Lua solution, you might want to consider using useexternalfigure which allows you to name figures.



            useexternalfigure[background:1][noise-blue.png]
            useexternalfigure[background:2][noise-yellow.png]
            useexternalfigure[background:3][noise-red.png]
            useexternalfigure[background:4][noise-green.png]

            starttext
            externalfigure[background:1][width=4cm]
            stoptext





            share|improve this answer













            As an alternative to Wolfgang's answer and as alternative to your Lua solution, you might want to consider using useexternalfigure which allows you to name figures.



            useexternalfigure[background:1][noise-blue.png]
            useexternalfigure[background:2][noise-yellow.png]
            useexternalfigure[background:3][noise-red.png]
            useexternalfigure[background:4][noise-green.png]

            starttext
            externalfigure[background:1][width=4cm]
            stoptext






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 26 at 20:55









            Henri MenkeHenri Menke

            74.2k8164275




            74.2k8164275












            • Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

              – flyx
              Jan 26 at 21:43

















            • Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

              – flyx
              Jan 26 at 21:43
















            Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

            – flyx
            Jan 26 at 21:43





            Thanks for this tip! I'll keep Wolfgang's answer accepted since it solves the question but I'll consider using this code instead.

            – flyx
            Jan 26 at 21:43

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471969%2fcontext-does-not-load-png-file-given-by-lua-code%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay