ConTeXt does not load png file given by lua code
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
Thebackground
command already exists in ConTeXt, useBackground
instead.
– Wolfgang Schuster
Jan 26 at 16:00
add a comment |
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
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
luatex context expansion
asked Jan 26 at 15:14
flyxflyx
944614
944614
Thebackground
command already exists in ConTeXt, useBackground
instead.
– Wolfgang Schuster
Jan 26 at 16:00
add a comment |
Thebackground
command already exists in ConTeXt, useBackground
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
add a comment |
2 Answers
2
active
oldest
votes
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
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
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
add a comment |
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
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
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
add a comment |
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
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
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
add a comment |
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
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
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
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
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
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
edited Jan 26 at 22:40
answered Jan 26 at 15:59
Wolfgang SchusterWolfgang Schuster
5,6011711
5,6011711
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
The
background
command already exists in ConTeXt, useBackground
instead.– Wolfgang Schuster
Jan 26 at 16:00