text{ } subscript size in tikzmath macro is not correct












4















This question is related to this earlier TeX-SE question of mine



I would like to have a proper text subscript using the text{} command. It does not seem to work with the tikzmath macros. Please see the following MWW:



documentclass{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{math}

%%%To fix the text subscript
%usepackage{etoolbox}
%makeatletter
%robustify{text}
%makeatother

begin{document}
begin{tikzpicture}

node at (0,0) {$text{b}_text{b}$: Correct};

tikzmath{let test=text{b}_{text{b}};}
node at (0,-1cm) {$test$: Not Correct};

end{tikzpicture}
end{document}


As can be seen from the output, the subscript size is not correct:
Subscript size is not correct



If I apply the suggest fix, the subscript size is corrected:
enter image description here



My question is the use of etoolbox and robustify the suggested way of fixing the text subscripts, which may have some side effects that I may face in the future, or is there a more robust way of correcting the size?



Note: Use of textrm does not work in the above example, which I used for the problem I have reported in my earlier post.










share|improve this question

























  • There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

    – Skillmon
    yesterday











  • @Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

    – berkus
    yesterday













  • What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

    – egreg
    yesterday











  • @egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

    – berkus
    yesterday
















4















This question is related to this earlier TeX-SE question of mine



I would like to have a proper text subscript using the text{} command. It does not seem to work with the tikzmath macros. Please see the following MWW:



documentclass{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{math}

%%%To fix the text subscript
%usepackage{etoolbox}
%makeatletter
%robustify{text}
%makeatother

begin{document}
begin{tikzpicture}

node at (0,0) {$text{b}_text{b}$: Correct};

tikzmath{let test=text{b}_{text{b}};}
node at (0,-1cm) {$test$: Not Correct};

end{tikzpicture}
end{document}


As can be seen from the output, the subscript size is not correct:
Subscript size is not correct



If I apply the suggest fix, the subscript size is corrected:
enter image description here



My question is the use of etoolbox and robustify the suggested way of fixing the text subscripts, which may have some side effects that I may face in the future, or is there a more robust way of correcting the size?



Note: Use of textrm does not work in the above example, which I used for the problem I have reported in my earlier post.










share|improve this question

























  • There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

    – Skillmon
    yesterday











  • @Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

    – berkus
    yesterday













  • What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

    – egreg
    yesterday











  • @egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

    – berkus
    yesterday














4












4








4








This question is related to this earlier TeX-SE question of mine



I would like to have a proper text subscript using the text{} command. It does not seem to work with the tikzmath macros. Please see the following MWW:



documentclass{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{math}

%%%To fix the text subscript
%usepackage{etoolbox}
%makeatletter
%robustify{text}
%makeatother

begin{document}
begin{tikzpicture}

node at (0,0) {$text{b}_text{b}$: Correct};

tikzmath{let test=text{b}_{text{b}};}
node at (0,-1cm) {$test$: Not Correct};

end{tikzpicture}
end{document}


As can be seen from the output, the subscript size is not correct:
Subscript size is not correct



If I apply the suggest fix, the subscript size is corrected:
enter image description here



My question is the use of etoolbox and robustify the suggested way of fixing the text subscripts, which may have some side effects that I may face in the future, or is there a more robust way of correcting the size?



Note: Use of textrm does not work in the above example, which I used for the problem I have reported in my earlier post.










share|improve this question
















This question is related to this earlier TeX-SE question of mine



I would like to have a proper text subscript using the text{} command. It does not seem to work with the tikzmath macros. Please see the following MWW:



documentclass{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{math}

%%%To fix the text subscript
%usepackage{etoolbox}
%makeatletter
%robustify{text}
%makeatother

begin{document}
begin{tikzpicture}

node at (0,0) {$text{b}_text{b}$: Correct};

tikzmath{let test=text{b}_{text{b}};}
node at (0,-1cm) {$test$: Not Correct};

end{tikzpicture}
end{document}


As can be seen from the output, the subscript size is not correct:
Subscript size is not correct



If I apply the suggest fix, the subscript size is corrected:
enter image description here



My question is the use of etoolbox and robustify the suggested way of fixing the text subscripts, which may have some side effects that I may face in the future, or is there a more robust way of correcting the size?



Note: Use of textrm does not work in the above example, which I used for the problem I have reported in my earlier post.







tikz-pgf tikzmath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Bernard

170k775201




170k775201










asked yesterday









berkusberkus

654317




654317













  • There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

    – Skillmon
    yesterday











  • @Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

    – berkus
    yesterday













  • What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

    – egreg
    yesterday











  • @egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

    – berkus
    yesterday



















  • There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

    – Skillmon
    yesterday











  • @Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

    – berkus
    yesterday













  • What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

    – egreg
    yesterday











  • @egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

    – berkus
    yesterday

















There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

– Skillmon
yesterday





There should be an additional set of braces around text{b} for semantic reasons: b_{text{b}}

– Skillmon
yesterday













@Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

– berkus
yesterday







@Skillmon: Yes! Exactly! Without braces I have experienced some issues in some tikzmath operations. Thanks for noting this.

– berkus
yesterday















What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

– egreg
yesterday





What's the reason for tikzmath? Isn't deftest{text{b}_{text{b}}} sufficient?

– egreg
yesterday













@egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

– berkus
yesterday





@egreg I have been using tikzmath for writing some tikz parametric packages, which I have to define many tikzmath macros.

– berkus
yesterday










2 Answers
2






active

oldest

votes


















5














Add a noexpand can fix it directly. But I would think the robustify approach makes more sense if this is an ongoing issue.



documentclass{standalone}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{math}

%%%To fix the text subscript
%usepackage{etoolbox}
%makeatletter
%robustify{text}
%makeatother

begin{document}
begin{tikzpicture}

node at (0,0) {$text{b}_text{b}$: Correct};

tikzmath{let test=text{b}_{text{b}};}
node at (0,-1cm) {$test$: Not Correct};

tikzmath{let test=text{b}_{noexpandtext{b}};}
node at (0,-2cm) {$test$: Corrected with noexpand};

end{tikzpicture}
end{document}


enter image description here






share|improve this answer


























  • The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

    – quark67
    yesterday



















6














You can see what's going on if you add showtext after the tikzmath declaration:



> test=macro:
->protect unhbox voidb@x hbox {b}_{protect unhbox voidb@x hbox {b}}.


Indeed, the definition of text is found in amstext.sty:



% amstext.sty, line 28:
DeclareRobustCommand{text}{%
ifmmodeexpandaftertext@elseexpandaftermboxfi}


You also have to know that tikzmath does full expansion; since text is not found in math mode, it just does mbox. Since at the time of let the meaning of protect is relax, it goes on untouched; then the conditional is expanded and since TeX is not in math mode, you get mbox{b}, which becomes



leavemodehbox{b}


and finally unhboxvoidb@xhbox{b}. This should explain the output of show above.



Possibly you want to evaluate something instead of having b in the argument to text; in this case you need to be careful about what to fully expand and what not.



tikzmath{let test=noexpandtext{b}_{noexpandtext{b}};}


will do, but if instead of b you have something like textbf{abc}, this will die horribly anyhow.



You need noexpand in front of both occurrences of text, in order to suppress its expansion and get the right version when test is indeed used in math mode.






share|improve this answer

























    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%2f475866%2ftext-subscript-size-in-tikzmath-macro-is-not-correct%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









    5














    Add a noexpand can fix it directly. But I would think the robustify approach makes more sense if this is an ongoing issue.



    documentclass{standalone}
    usepackage{amsmath}
    usepackage{tikz}
    usetikzlibrary{math}

    %%%To fix the text subscript
    %usepackage{etoolbox}
    %makeatletter
    %robustify{text}
    %makeatother

    begin{document}
    begin{tikzpicture}

    node at (0,0) {$text{b}_text{b}$: Correct};

    tikzmath{let test=text{b}_{text{b}};}
    node at (0,-1cm) {$test$: Not Correct};

    tikzmath{let test=text{b}_{noexpandtext{b}};}
    node at (0,-2cm) {$test$: Corrected with noexpand};

    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer


























    • The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

      – quark67
      yesterday
















    5














    Add a noexpand can fix it directly. But I would think the robustify approach makes more sense if this is an ongoing issue.



    documentclass{standalone}
    usepackage{amsmath}
    usepackage{tikz}
    usetikzlibrary{math}

    %%%To fix the text subscript
    %usepackage{etoolbox}
    %makeatletter
    %robustify{text}
    %makeatother

    begin{document}
    begin{tikzpicture}

    node at (0,0) {$text{b}_text{b}$: Correct};

    tikzmath{let test=text{b}_{text{b}};}
    node at (0,-1cm) {$test$: Not Correct};

    tikzmath{let test=text{b}_{noexpandtext{b}};}
    node at (0,-2cm) {$test$: Corrected with noexpand};

    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer


























    • The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

      – quark67
      yesterday














    5












    5








    5







    Add a noexpand can fix it directly. But I would think the robustify approach makes more sense if this is an ongoing issue.



    documentclass{standalone}
    usepackage{amsmath}
    usepackage{tikz}
    usetikzlibrary{math}

    %%%To fix the text subscript
    %usepackage{etoolbox}
    %makeatletter
    %robustify{text}
    %makeatother

    begin{document}
    begin{tikzpicture}

    node at (0,0) {$text{b}_text{b}$: Correct};

    tikzmath{let test=text{b}_{text{b}};}
    node at (0,-1cm) {$test$: Not Correct};

    tikzmath{let test=text{b}_{noexpandtext{b}};}
    node at (0,-2cm) {$test$: Corrected with noexpand};

    end{tikzpicture}
    end{document}


    enter image description here






    share|improve this answer















    Add a noexpand can fix it directly. But I would think the robustify approach makes more sense if this is an ongoing issue.



    documentclass{standalone}
    usepackage{amsmath}
    usepackage{tikz}
    usetikzlibrary{math}

    %%%To fix the text subscript
    %usepackage{etoolbox}
    %makeatletter
    %robustify{text}
    %makeatother

    begin{document}
    begin{tikzpicture}

    node at (0,0) {$text{b}_text{b}$: Correct};

    tikzmath{let test=text{b}_{text{b}};}
    node at (0,-1cm) {$test$: Not Correct};

    tikzmath{let test=text{b}_{noexpandtext{b}};}
    node at (0,-2cm) {$test$: Corrected with noexpand};

    end{tikzpicture}
    end{document}


    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 16 hours ago









    berkus

    654317




    654317










    answered yesterday









    Steven B. SegletesSteven B. Segletes

    156k9201411




    156k9201411













    • The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

      – quark67
      yesterday



















    • The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

      – quark67
      yesterday

















    The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

    – quark67
    yesterday





    The screenshot doesn't reflect the real output (in my output, with TeX live 2018, the $b_b$ in the middle is the same as the $b_b$ in the top, and therefor "is correct").

    – quark67
    yesterday











    6














    You can see what's going on if you add showtext after the tikzmath declaration:



    > test=macro:
    ->protect unhbox voidb@x hbox {b}_{protect unhbox voidb@x hbox {b}}.


    Indeed, the definition of text is found in amstext.sty:



    % amstext.sty, line 28:
    DeclareRobustCommand{text}{%
    ifmmodeexpandaftertext@elseexpandaftermboxfi}


    You also have to know that tikzmath does full expansion; since text is not found in math mode, it just does mbox. Since at the time of let the meaning of protect is relax, it goes on untouched; then the conditional is expanded and since TeX is not in math mode, you get mbox{b}, which becomes



    leavemodehbox{b}


    and finally unhboxvoidb@xhbox{b}. This should explain the output of show above.



    Possibly you want to evaluate something instead of having b in the argument to text; in this case you need to be careful about what to fully expand and what not.



    tikzmath{let test=noexpandtext{b}_{noexpandtext{b}};}


    will do, but if instead of b you have something like textbf{abc}, this will die horribly anyhow.



    You need noexpand in front of both occurrences of text, in order to suppress its expansion and get the right version when test is indeed used in math mode.






    share|improve this answer






























      6














      You can see what's going on if you add showtext after the tikzmath declaration:



      > test=macro:
      ->protect unhbox voidb@x hbox {b}_{protect unhbox voidb@x hbox {b}}.


      Indeed, the definition of text is found in amstext.sty:



      % amstext.sty, line 28:
      DeclareRobustCommand{text}{%
      ifmmodeexpandaftertext@elseexpandaftermboxfi}


      You also have to know that tikzmath does full expansion; since text is not found in math mode, it just does mbox. Since at the time of let the meaning of protect is relax, it goes on untouched; then the conditional is expanded and since TeX is not in math mode, you get mbox{b}, which becomes



      leavemodehbox{b}


      and finally unhboxvoidb@xhbox{b}. This should explain the output of show above.



      Possibly you want to evaluate something instead of having b in the argument to text; in this case you need to be careful about what to fully expand and what not.



      tikzmath{let test=noexpandtext{b}_{noexpandtext{b}};}


      will do, but if instead of b you have something like textbf{abc}, this will die horribly anyhow.



      You need noexpand in front of both occurrences of text, in order to suppress its expansion and get the right version when test is indeed used in math mode.






      share|improve this answer




























        6












        6








        6







        You can see what's going on if you add showtext after the tikzmath declaration:



        > test=macro:
        ->protect unhbox voidb@x hbox {b}_{protect unhbox voidb@x hbox {b}}.


        Indeed, the definition of text is found in amstext.sty:



        % amstext.sty, line 28:
        DeclareRobustCommand{text}{%
        ifmmodeexpandaftertext@elseexpandaftermboxfi}


        You also have to know that tikzmath does full expansion; since text is not found in math mode, it just does mbox. Since at the time of let the meaning of protect is relax, it goes on untouched; then the conditional is expanded and since TeX is not in math mode, you get mbox{b}, which becomes



        leavemodehbox{b}


        and finally unhboxvoidb@xhbox{b}. This should explain the output of show above.



        Possibly you want to evaluate something instead of having b in the argument to text; in this case you need to be careful about what to fully expand and what not.



        tikzmath{let test=noexpandtext{b}_{noexpandtext{b}};}


        will do, but if instead of b you have something like textbf{abc}, this will die horribly anyhow.



        You need noexpand in front of both occurrences of text, in order to suppress its expansion and get the right version when test is indeed used in math mode.






        share|improve this answer















        You can see what's going on if you add showtext after the tikzmath declaration:



        > test=macro:
        ->protect unhbox voidb@x hbox {b}_{protect unhbox voidb@x hbox {b}}.


        Indeed, the definition of text is found in amstext.sty:



        % amstext.sty, line 28:
        DeclareRobustCommand{text}{%
        ifmmodeexpandaftertext@elseexpandaftermboxfi}


        You also have to know that tikzmath does full expansion; since text is not found in math mode, it just does mbox. Since at the time of let the meaning of protect is relax, it goes on untouched; then the conditional is expanded and since TeX is not in math mode, you get mbox{b}, which becomes



        leavemodehbox{b}


        and finally unhboxvoidb@xhbox{b}. This should explain the output of show above.



        Possibly you want to evaluate something instead of having b in the argument to text; in this case you need to be careful about what to fully expand and what not.



        tikzmath{let test=noexpandtext{b}_{noexpandtext{b}};}


        will do, but if instead of b you have something like textbf{abc}, this will die horribly anyhow.



        You need noexpand in front of both occurrences of text, in order to suppress its expansion and get the right version when test is indeed used in math mode.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 16 hours ago









        Peter Grill

        166k25440753




        166k25440753










        answered yesterday









        egregegreg

        721k8719113210




        721k8719113210






























            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%2f475866%2ftext-subscript-size-in-tikzmath-macro-is-not-correct%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 label and detect the document text images

            Vallis Paradisi

            Tabula Rosettana