verb in label or pin of a tikz node











up vote
4
down vote

favorite












The documentation of tikz gives following example containing the verb command in the node text (Section 2.21 Adding Text, v3):



begin{tikzpicture}
draw (0,0) rectangle (2,2);
draw (0.5,0.5) node [fill=yellow!80!black]
{Text at verb!node 1!}
-- (1.5,1.5) node {Text at verb!node 2!};
end{tikzpicture}


If I want to use the label or pin functionality for nodes, it does not work as expected:



documentclass[tikz]{standalone}
begin{document}
begin{tikzpicture}
draw (0,0) rectangle (2,2);
draw (0.5,0.5) node [fill=yellow!80!black]
{Text at verb!a_b!}
-- (1.5,1.5) node[label={verb!a_b!}] {Text at verb!a_b!};
end{tikzpicture}
end{document}


The error message given is ! Missing $ inserted. due to the _ I want to use.










share|improve this question




























    up vote
    4
    down vote

    favorite












    The documentation of tikz gives following example containing the verb command in the node text (Section 2.21 Adding Text, v3):



    begin{tikzpicture}
    draw (0,0) rectangle (2,2);
    draw (0.5,0.5) node [fill=yellow!80!black]
    {Text at verb!node 1!}
    -- (1.5,1.5) node {Text at verb!node 2!};
    end{tikzpicture}


    If I want to use the label or pin functionality for nodes, it does not work as expected:



    documentclass[tikz]{standalone}
    begin{document}
    begin{tikzpicture}
    draw (0,0) rectangle (2,2);
    draw (0.5,0.5) node [fill=yellow!80!black]
    {Text at verb!a_b!}
    -- (1.5,1.5) node[label={verb!a_b!}] {Text at verb!a_b!};
    end{tikzpicture}
    end{document}


    The error message given is ! Missing $ inserted. due to the _ I want to use.










    share|improve this question


























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      The documentation of tikz gives following example containing the verb command in the node text (Section 2.21 Adding Text, v3):



      begin{tikzpicture}
      draw (0,0) rectangle (2,2);
      draw (0.5,0.5) node [fill=yellow!80!black]
      {Text at verb!node 1!}
      -- (1.5,1.5) node {Text at verb!node 2!};
      end{tikzpicture}


      If I want to use the label or pin functionality for nodes, it does not work as expected:



      documentclass[tikz]{standalone}
      begin{document}
      begin{tikzpicture}
      draw (0,0) rectangle (2,2);
      draw (0.5,0.5) node [fill=yellow!80!black]
      {Text at verb!a_b!}
      -- (1.5,1.5) node[label={verb!a_b!}] {Text at verb!a_b!};
      end{tikzpicture}
      end{document}


      The error message given is ! Missing $ inserted. due to the _ I want to use.










      share|improve this question















      The documentation of tikz gives following example containing the verb command in the node text (Section 2.21 Adding Text, v3):



      begin{tikzpicture}
      draw (0,0) rectangle (2,2);
      draw (0.5,0.5) node [fill=yellow!80!black]
      {Text at verb!node 1!}
      -- (1.5,1.5) node {Text at verb!node 2!};
      end{tikzpicture}


      If I want to use the label or pin functionality for nodes, it does not work as expected:



      documentclass[tikz]{standalone}
      begin{document}
      begin{tikzpicture}
      draw (0,0) rectangle (2,2);
      draw (0.5,0.5) node [fill=yellow!80!black]
      {Text at verb!a_b!}
      -- (1.5,1.5) node[label={verb!a_b!}] {Text at verb!a_b!};
      end{tikzpicture}
      end{document}


      The error message given is ! Missing $ inserted. due to the _ I want to use.







      tikz-pgf nodes labels verbatim






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked yesterday









      Hotschke

      2,06311840




      2,06311840






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          documentclass[tikz]{standalone}
          usepackage{fancyvrb} DefineShortVerb{|}
          begin{document}
          SaveVerb{Verb}|a_b|
          begin{tikzpicture}
          draw (0,0) rectangle (2,2);
          draw (0.5,0.5) node [fill=yellow!80!black]{Text at |a_b|} -- (1.5,1.5)
          node[label=UseVerb{Verb}] {Text at |a_b|};
          end{tikzpicture}
          end{document}





          share|improve this answer




























            up vote
            1
            down vote













            I really do not fully understand what's going on but I can offer a workaround. To this end, let me first mention that creating a new savebox and trying it to fill with saveboxverbox{verb!a_b!} fails. However, a lrbox works, so I propose to store the content of the label in a savebox first and then use it.



            documentclass[tikz]{standalone}
            newsaveboxverbox
            begin{document}
            begin{lrbox}{verbox}
            verb!a_b!
            end{lrbox}
            % fails:
            %saveboxverbox{verb!a_b!}
            begin{tikzpicture}
            draw (0,0) rectangle (2,2);
            draw (0.5,0.5) node [fill=yellow!80!black]
            {Text at verb!a_b!}
            -- (1.5,1.5) node[label={useboxverbox}] {Text at verb!a_b!};
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer




























              up vote
              1
              down vote













              Another workaround producing same output as in @marmot answer.



              documentclass[tikz]{standalone}
              begin{document}
              begin{tikzpicture}
              draw (0,0) rectangle (2,2);
              draw (0.5,0.5) node [fill=yellow!80!black]
              {Text at verb!a_b!}
              -- (1.5,1.5) node[label=texttt{astring_b}] {Text at verb!a_b!};
              end{tikzpicture}
              end{document}





              share|improve this answer





















              • texttt{a_b} should also work
                – Herbert
                yesterday






              • 1




                @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                – jfbu
                yesterday












              • I cannot see a problem with _$_$
                – Herbert
                yesterday






              • 1




                @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                – jfbu
                yesterday






              • 1




                @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                – jfbu
                yesterday











              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',
              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%2f459592%2fverb-in-label-or-pin-of-a-tikz-node%23new-answer', 'question_page');
              }
              );

              Post as a guest
































              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              documentclass[tikz]{standalone}
              usepackage{fancyvrb} DefineShortVerb{|}
              begin{document}
              SaveVerb{Verb}|a_b|
              begin{tikzpicture}
              draw (0,0) rectangle (2,2);
              draw (0.5,0.5) node [fill=yellow!80!black]{Text at |a_b|} -- (1.5,1.5)
              node[label=UseVerb{Verb}] {Text at |a_b|};
              end{tikzpicture}
              end{document}





              share|improve this answer

























                up vote
                2
                down vote













                documentclass[tikz]{standalone}
                usepackage{fancyvrb} DefineShortVerb{|}
                begin{document}
                SaveVerb{Verb}|a_b|
                begin{tikzpicture}
                draw (0,0) rectangle (2,2);
                draw (0.5,0.5) node [fill=yellow!80!black]{Text at |a_b|} -- (1.5,1.5)
                node[label=UseVerb{Verb}] {Text at |a_b|};
                end{tikzpicture}
                end{document}





                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  documentclass[tikz]{standalone}
                  usepackage{fancyvrb} DefineShortVerb{|}
                  begin{document}
                  SaveVerb{Verb}|a_b|
                  begin{tikzpicture}
                  draw (0,0) rectangle (2,2);
                  draw (0.5,0.5) node [fill=yellow!80!black]{Text at |a_b|} -- (1.5,1.5)
                  node[label=UseVerb{Verb}] {Text at |a_b|};
                  end{tikzpicture}
                  end{document}





                  share|improve this answer












                  documentclass[tikz]{standalone}
                  usepackage{fancyvrb} DefineShortVerb{|}
                  begin{document}
                  SaveVerb{Verb}|a_b|
                  begin{tikzpicture}
                  draw (0,0) rectangle (2,2);
                  draw (0.5,0.5) node [fill=yellow!80!black]{Text at |a_b|} -- (1.5,1.5)
                  node[label=UseVerb{Verb}] {Text at |a_b|};
                  end{tikzpicture}
                  end{document}






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  Herbert

                  264k23400712




                  264k23400712






















                      up vote
                      1
                      down vote













                      I really do not fully understand what's going on but I can offer a workaround. To this end, let me first mention that creating a new savebox and trying it to fill with saveboxverbox{verb!a_b!} fails. However, a lrbox works, so I propose to store the content of the label in a savebox first and then use it.



                      documentclass[tikz]{standalone}
                      newsaveboxverbox
                      begin{document}
                      begin{lrbox}{verbox}
                      verb!a_b!
                      end{lrbox}
                      % fails:
                      %saveboxverbox{verb!a_b!}
                      begin{tikzpicture}
                      draw (0,0) rectangle (2,2);
                      draw (0.5,0.5) node [fill=yellow!80!black]
                      {Text at verb!a_b!}
                      -- (1.5,1.5) node[label={useboxverbox}] {Text at verb!a_b!};
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer

























                        up vote
                        1
                        down vote













                        I really do not fully understand what's going on but I can offer a workaround. To this end, let me first mention that creating a new savebox and trying it to fill with saveboxverbox{verb!a_b!} fails. However, a lrbox works, so I propose to store the content of the label in a savebox first and then use it.



                        documentclass[tikz]{standalone}
                        newsaveboxverbox
                        begin{document}
                        begin{lrbox}{verbox}
                        verb!a_b!
                        end{lrbox}
                        % fails:
                        %saveboxverbox{verb!a_b!}
                        begin{tikzpicture}
                        draw (0,0) rectangle (2,2);
                        draw (0.5,0.5) node [fill=yellow!80!black]
                        {Text at verb!a_b!}
                        -- (1.5,1.5) node[label={useboxverbox}] {Text at verb!a_b!};
                        end{tikzpicture}
                        end{document}


                        enter image description here






                        share|improve this answer























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          I really do not fully understand what's going on but I can offer a workaround. To this end, let me first mention that creating a new savebox and trying it to fill with saveboxverbox{verb!a_b!} fails. However, a lrbox works, so I propose to store the content of the label in a savebox first and then use it.



                          documentclass[tikz]{standalone}
                          newsaveboxverbox
                          begin{document}
                          begin{lrbox}{verbox}
                          verb!a_b!
                          end{lrbox}
                          % fails:
                          %saveboxverbox{verb!a_b!}
                          begin{tikzpicture}
                          draw (0,0) rectangle (2,2);
                          draw (0.5,0.5) node [fill=yellow!80!black]
                          {Text at verb!a_b!}
                          -- (1.5,1.5) node[label={useboxverbox}] {Text at verb!a_b!};
                          end{tikzpicture}
                          end{document}


                          enter image description here






                          share|improve this answer












                          I really do not fully understand what's going on but I can offer a workaround. To this end, let me first mention that creating a new savebox and trying it to fill with saveboxverbox{verb!a_b!} fails. However, a lrbox works, so I propose to store the content of the label in a savebox first and then use it.



                          documentclass[tikz]{standalone}
                          newsaveboxverbox
                          begin{document}
                          begin{lrbox}{verbox}
                          verb!a_b!
                          end{lrbox}
                          % fails:
                          %saveboxverbox{verb!a_b!}
                          begin{tikzpicture}
                          draw (0,0) rectangle (2,2);
                          draw (0.5,0.5) node [fill=yellow!80!black]
                          {Text at verb!a_b!}
                          -- (1.5,1.5) node[label={useboxverbox}] {Text at verb!a_b!};
                          end{tikzpicture}
                          end{document}


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          marmot

                          74.6k482157




                          74.6k482157






















                              up vote
                              1
                              down vote













                              Another workaround producing same output as in @marmot answer.



                              documentclass[tikz]{standalone}
                              begin{document}
                              begin{tikzpicture}
                              draw (0,0) rectangle (2,2);
                              draw (0.5,0.5) node [fill=yellow!80!black]
                              {Text at verb!a_b!}
                              -- (1.5,1.5) node[label=texttt{astring_b}] {Text at verb!a_b!};
                              end{tikzpicture}
                              end{document}





                              share|improve this answer





















                              • texttt{a_b} should also work
                                – Herbert
                                yesterday






                              • 1




                                @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                                – jfbu
                                yesterday












                              • I cannot see a problem with _$_$
                                – Herbert
                                yesterday






                              • 1




                                @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                                – jfbu
                                yesterday






                              • 1




                                @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                                – jfbu
                                yesterday















                              up vote
                              1
                              down vote













                              Another workaround producing same output as in @marmot answer.



                              documentclass[tikz]{standalone}
                              begin{document}
                              begin{tikzpicture}
                              draw (0,0) rectangle (2,2);
                              draw (0.5,0.5) node [fill=yellow!80!black]
                              {Text at verb!a_b!}
                              -- (1.5,1.5) node[label=texttt{astring_b}] {Text at verb!a_b!};
                              end{tikzpicture}
                              end{document}





                              share|improve this answer





















                              • texttt{a_b} should also work
                                – Herbert
                                yesterday






                              • 1




                                @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                                – jfbu
                                yesterday












                              • I cannot see a problem with _$_$
                                – Herbert
                                yesterday






                              • 1




                                @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                                – jfbu
                                yesterday






                              • 1




                                @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                                – jfbu
                                yesterday













                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              Another workaround producing same output as in @marmot answer.



                              documentclass[tikz]{standalone}
                              begin{document}
                              begin{tikzpicture}
                              draw (0,0) rectangle (2,2);
                              draw (0.5,0.5) node [fill=yellow!80!black]
                              {Text at verb!a_b!}
                              -- (1.5,1.5) node[label=texttt{astring_b}] {Text at verb!a_b!};
                              end{tikzpicture}
                              end{document}





                              share|improve this answer












                              Another workaround producing same output as in @marmot answer.



                              documentclass[tikz]{standalone}
                              begin{document}
                              begin{tikzpicture}
                              draw (0,0) rectangle (2,2);
                              draw (0.5,0.5) node [fill=yellow!80!black]
                              {Text at verb!a_b!}
                              -- (1.5,1.5) node[label=texttt{astring_b}] {Text at verb!a_b!};
                              end{tikzpicture}
                              end{document}






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered yesterday









                              jfbu

                              44.1k65143




                              44.1k65143












                              • texttt{a_b} should also work
                                – Herbert
                                yesterday






                              • 1




                                @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                                – jfbu
                                yesterday












                              • I cannot see a problem with _$_$
                                – Herbert
                                yesterday






                              • 1




                                @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                                – jfbu
                                yesterday






                              • 1




                                @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                                – jfbu
                                yesterday


















                              • texttt{a_b} should also work
                                – Herbert
                                yesterday






                              • 1




                                @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                                – jfbu
                                yesterday












                              • I cannot see a problem with _$_$
                                – Herbert
                                yesterday






                              • 1




                                @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                                – jfbu
                                yesterday






                              • 1




                                @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                                – jfbu
                                yesterday
















                              texttt{a_b} should also work
                              – Herbert
                              yesterday




                              texttt{a_b} should also work
                              – Herbert
                              yesterday




                              1




                              1




                              @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                              – jfbu
                              yesterday






                              @Herbert this is what I had done initially but notice that it does not give same result in OT1 default encoding.
                              – jfbu
                              yesterday














                              I cannot see a problem with _$_$
                              – Herbert
                              yesterday




                              I cannot see a problem with _$_$
                              – Herbert
                              yesterday




                              1




                              1




                              @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                              – jfbu
                              yesterday




                              @Herbert try it out with tt font. I told you it gives different result, and I don't see why I would have said so if not.
                              – jfbu
                              yesterday




                              1




                              1




                              @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                              – jfbu
                              yesterday




                              @Herbert I think we have a quiproquo here. I am talking about comparing string_ with _. Notice that the OP is asking for verb|a_b|. You can reproduce same with texttt{astring_b} not with texttt{a_b} in OT1 encoding.
                              – jfbu
                              yesterday


















                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f459592%2fverb-in-label-or-pin-of-a-tikz-node%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest




















































































                              Popular posts from this blog

                              How to change which sound is reproduced for terminal bell?

                              Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                              Can I use Tabulator js library in my java Spring + Thymeleaf project?