LaTeX 3 string variable with braces












3















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.










share|improve this question

























  • 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...?

    – user31729
    Dec 27 '18 at 13:07













  • @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
    Dec 27 '18 at 13:57













  • tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

    – egreg
    Dec 27 '18 at 14:07











  • @tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

    – user31729
    Dec 27 '18 at 17:16











  • @ChristianHupfer Sorry about that.

    – tambre
    Dec 27 '18 at 18:20
















3















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.










share|improve this question

























  • 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...?

    – user31729
    Dec 27 '18 at 13:07













  • @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
    Dec 27 '18 at 13:57













  • tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

    – egreg
    Dec 27 '18 at 14:07











  • @tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

    – user31729
    Dec 27 '18 at 17:16











  • @ChristianHupfer Sorry about that.

    – tambre
    Dec 27 '18 at 18:20














3












3








3








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 16:19







user31729

















asked Dec 27 '18 at 13:02









tambretambre

1689




1689













  • 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...?

    – user31729
    Dec 27 '18 at 13:07













  • @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
    Dec 27 '18 at 13:57













  • tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

    – egreg
    Dec 27 '18 at 14:07











  • @tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

    – user31729
    Dec 27 '18 at 17:16











  • @ChristianHupfer Sorry about that.

    – tambre
    Dec 27 '18 at 18:20



















  • 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...?

    – user31729
    Dec 27 '18 at 13:07













  • @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
    Dec 27 '18 at 13:57













  • tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

    – egreg
    Dec 27 '18 at 14:07











  • @tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

    – user31729
    Dec 27 '18 at 17:16











  • @ChristianHupfer Sorry about that.

    – tambre
    Dec 27 '18 at 18:20

















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

– user31729
Dec 27 '18 at 13:07







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

– user31729
Dec 27 '18 at 13:07















@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
Dec 27 '18 at 13:57







@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
Dec 27 '18 at 13:57















tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

– egreg
Dec 27 '18 at 14:07





tl_set:Nx l_example_tl { { int_to_arabic:n { l_example_int } } }

– egreg
Dec 27 '18 at 14:07













@tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

– user31729
Dec 27 '18 at 17:16





@tambre: Your use-case wasn't clear, I could have done a tl... like solution as well...

– user31729
Dec 27 '18 at 17:16













@ChristianHupfer Sorry about that.

– tambre
Dec 27 '18 at 18:20





@ChristianHupfer Sorry about that.

– tambre
Dec 27 '18 at 18:20










2 Answers
2






active

oldest

votes


















4














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





share|improve this answer































    5














    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.







    share|improve this answer





















    • 1





      There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

      – egreg
      Dec 27 '18 at 14:00













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









    4














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





    share|improve this answer




























      4














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





      share|improve this answer


























        4












        4








        4







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





        share|improve this answer













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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 '18 at 14:15









        egregegreg

        726k8819223230




        726k8819223230























            5














            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.







            share|improve this answer





















            • 1





              There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

              – egreg
              Dec 27 '18 at 14:00


















            5














            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.







            share|improve this answer





















            • 1





              There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

              – egreg
              Dec 27 '18 at 14:00
















            5












            5








            5







            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.







            share|improve this answer















            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.








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 27 '18 at 16:23

























            answered Dec 27 '18 at 13:11







            user31729















            • 1





              There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

              – egreg
              Dec 27 '18 at 14:00
















            • 1





              There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

              – egreg
              Dec 27 '18 at 14:00










            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
            Dec 27 '18 at 14:00







            There should be no brace around a V argument. Not that braces make a difference, it's more on the conceptual side.

            – egreg
            Dec 27 '18 at 14:00




















            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%2f467535%2flatex-3-string-variable-with-braces%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

            Wiesbaden

            Marschland

            Dieringhausen