LaTeX 3 string variable with braces
I want to include some braces in my string variable:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:Nn l_example_var {{}
str_put_right:NV l_example_var {l_example_int}
str_put_right:Nn l_example_var {}~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
Unfortunately this results in the braces being preceded by pesky backslashes:
> l_example_var={0} some text.
<recently read> }
l.13 ^^Istr_show:N l_example_var
How would I be able to get rid of the backslashes in front of the braces? E.g. l_example_var={0} some text.
expl3
add a comment |
I want to include some braces in my string variable:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:Nn l_example_var {{}
str_put_right:NV l_example_var {l_example_int}
str_put_right:Nn l_example_var {}~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
Unfortunately this results in the braces being preceded by pesky backslashes:
> l_example_var={0} some text.
<recently read> }
l.13 ^^Istr_show:N l_example_var
How would I be able to get rid of the backslashes in front of the braces? E.g. l_example_var={0} some text.
expl3
c_left_brace_str
andc_right_brace_str
instead of{
and}
, but are you sure you needstr
instead of a token list, i.e.tl_set:N...
?
– Christian Hupfer
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doingtl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.
– tambre
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
@tambre: Your use-case wasn't clear, I could have done atl...
like solution as well...
– Christian Hupfer
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago
add a comment |
I want to include some braces in my string variable:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:Nn l_example_var {{}
str_put_right:NV l_example_var {l_example_int}
str_put_right:Nn l_example_var {}~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
Unfortunately this results in the braces being preceded by pesky backslashes:
> l_example_var={0} some text.
<recently read> }
l.13 ^^Istr_show:N l_example_var
How would I be able to get rid of the backslashes in front of the braces? E.g. l_example_var={0} some text.
expl3
I want to include some braces in my string variable:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:Nn l_example_var {{}
str_put_right:NV l_example_var {l_example_int}
str_put_right:Nn l_example_var {}~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
Unfortunately this results in the braces being preceded by pesky backslashes:
> l_example_var={0} some text.
<recently read> }
l.13 ^^Istr_show:N l_example_var
How would I be able to get rid of the backslashes in front of the braces? E.g. l_example_var={0} some text.
expl3
expl3
edited 2 days ago
Christian Hupfer
147k14192386
147k14192386
asked 2 days ago
tambre
1689
1689
c_left_brace_str
andc_right_brace_str
instead of{
and}
, but are you sure you needstr
instead of a token list, i.e.tl_set:N...
?
– Christian Hupfer
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doingtl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.
– tambre
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
@tambre: Your use-case wasn't clear, I could have done atl...
like solution as well...
– Christian Hupfer
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago
add a comment |
c_left_brace_str
andc_right_brace_str
instead of{
and}
, but are you sure you needstr
instead of a token list, i.e.tl_set:N...
?
– Christian Hupfer
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doingtl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.
– tambre
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
@tambre: Your use-case wasn't clear, I could have done atl...
like solution as well...
– Christian Hupfer
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago
c_left_brace_str
and c_right_brace_str
instead of {
and }
, but are you sure you need str
instead of a token list, i.e. tl_set:N...
?– Christian Hupfer
2 days ago
c_left_brace_str
and c_right_brace_str
instead of {
and }
, but are you sure you need str
instead of a token list, i.e. tl_set:N...
?– Christian Hupfer
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doing
tl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.– tambre
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doing
tl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.– tambre
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
@tambre: Your use-case wasn't clear, I could have done a
tl...
like solution as well...– Christian Hupfer
2 days ago
@tambre: Your use-case wasn't clear, I could have done a
tl...
like solution as well...– Christian Hupfer
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
I'm not sure what's the benefit of a string such as {42}
and probably you need a token list instead. However,
str_set:Nx l_example_str { c_left_brace_str int_use:N l_example_int c_right_brace_str }
will do. For a token list it's similar
tl_set:Nx l_example_tl { { int_use:N l_example_int } }
add a comment |
Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use c_left_brace_str
and c_right_brace_str
and the V
modifier for the str_set:Nn
macro
There are other literal string constants such as c_hash_str
or c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:NV l_example_var c_left_brace_str
str_put_right:NV l_example_var l_example_int
str_put_right:NV l_example_var c_right_brace_str
str_put_right:Nn l_example_var {~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
l_example_var={0} some text. }
l.16 str_show:N l_example_var
? x No pages of output. Transcript written on stringwith.log.
1
There should be no brace around aV
argument. Not that braces make a difference, it's more on the conceptual side.
– egreg
2 days ago
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%2f467535%2flatex-3-string-variable-with-braces%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
I'm not sure what's the benefit of a string such as {42}
and probably you need a token list instead. However,
str_set:Nx l_example_str { c_left_brace_str int_use:N l_example_int c_right_brace_str }
will do. For a token list it's similar
tl_set:Nx l_example_tl { { int_use:N l_example_int } }
add a comment |
I'm not sure what's the benefit of a string such as {42}
and probably you need a token list instead. However,
str_set:Nx l_example_str { c_left_brace_str int_use:N l_example_int c_right_brace_str }
will do. For a token list it's similar
tl_set:Nx l_example_tl { { int_use:N l_example_int } }
add a comment |
I'm not sure what's the benefit of a string such as {42}
and probably you need a token list instead. However,
str_set:Nx l_example_str { c_left_brace_str int_use:N l_example_int c_right_brace_str }
will do. For a token list it's similar
tl_set:Nx l_example_tl { { int_use:N l_example_int } }
I'm not sure what's the benefit of a string such as {42}
and probably you need a token list instead. However,
str_set:Nx l_example_str { c_left_brace_str int_use:N l_example_int c_right_brace_str }
will do. For a token list it's similar
tl_set:Nx l_example_tl { { int_use:N l_example_int } }
answered 2 days ago
egreg
708k8618823163
708k8618823163
add a comment |
add a comment |
Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use c_left_brace_str
and c_right_brace_str
and the V
modifier for the str_set:Nn
macro
There are other literal string constants such as c_hash_str
or c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:NV l_example_var c_left_brace_str
str_put_right:NV l_example_var l_example_int
str_put_right:NV l_example_var c_right_brace_str
str_put_right:Nn l_example_var {~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
l_example_var={0} some text. }
l.16 str_show:N l_example_var
? x No pages of output. Transcript written on stringwith.log.
1
There should be no brace around aV
argument. Not that braces make a difference, it's more on the conceptual side.
– egreg
2 days ago
add a comment |
Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use c_left_brace_str
and c_right_brace_str
and the V
modifier for the str_set:Nn
macro
There are other literal string constants such as c_hash_str
or c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:NV l_example_var c_left_brace_str
str_put_right:NV l_example_var l_example_int
str_put_right:NV l_example_var c_right_brace_str
str_put_right:Nn l_example_var {~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
l_example_var={0} some text. }
l.16 str_show:N l_example_var
? x No pages of output. Transcript written on stringwith.log.
1
There should be no brace around aV
argument. Not that braces make a difference, it's more on the conceptual side.
– egreg
2 days ago
add a comment |
Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use c_left_brace_str
and c_right_brace_str
and the V
modifier for the str_set:Nn
macro
There are other literal string constants such as c_hash_str
or c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:NV l_example_var c_left_brace_str
str_put_right:NV l_example_var l_example_int
str_put_right:NV l_example_var c_right_brace_str
str_put_right:Nn l_example_var {~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
l_example_var={0} some text. }
l.16 str_show:N l_example_var
? x No pages of output. Transcript written on stringwith.log.
Apparently, the {
and }
'strings' shall appear literally in the string, so one way to add them is to use c_left_brace_str
and c_right_brace_str
and the V
modifier for the str_set:Nn
macro
There are other literal string constants such as c_hash_str
or c_dollar_str
, which are constant token lists with catcode 12 actually. See page 75 in the current interface3
manual (as of 2018/12/27).
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
str_new:N l_example_var
int_new:N l_example_int
str_set:NV l_example_var c_left_brace_str
str_put_right:NV l_example_var l_example_int
str_put_right:NV l_example_var c_right_brace_str
str_put_right:Nn l_example_var {~some~text}
str_show:N l_example_var
ExplSyntaxOff
end{document}
The output is
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018)
(preloaded format=pdflatex) write18 enabled. entering extended mode
(./stringwith.tex LaTeX2e <2018-12-01>
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2018/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(./stringwith.aux)
l_example_var={0} some text. }
l.16 str_show:N l_example_var
? x No pages of output. Transcript written on stringwith.log.
edited 2 days ago
answered 2 days ago
Christian Hupfer
147k14192386
147k14192386
1
There should be no brace around aV
argument. Not that braces make a difference, it's more on the conceptual side.
– egreg
2 days ago
add a comment |
1
There should be no brace around aV
argument. Not that braces make a difference, it's more on the conceptual side.
– egreg
2 days ago
1
1
There should be no brace around a
V
argument. Not that braces make a difference, it's more on the conceptual side.– egreg
2 days ago
There should be no brace around a
V
argument. Not that braces make a difference, it's more on the conceptual side.– egreg
2 days ago
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f467535%2flatex-3-string-variable-with-braces%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
c_left_brace_str
andc_right_brace_str
instead of{
and}
, but are you sure you needstr
instead of a token list, i.e.tl_set:N...
?– Christian Hupfer
2 days ago
@ChristianHupfer Thanks for the help. Using a token list would indeed seem more fitting. However doing
tl_set:NV l_example_tl { {l_example_int} }
results in the surrounding braces disappearing.– tambre
2 days ago
tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }
– egreg
2 days ago
@tambre: Your use-case wasn't clear, I could have done a
tl...
like solution as well...– Christian Hupfer
2 days ago
@ChristianHupfer Sorry about that.
– tambre
2 days ago