Escaping within lstlisting adds a space

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I'm basing my code on Overlay red rectangles on top of verbatim text in order to grab draw arrows over the source code.



I've successfully incorporated the solution into my code, however one problem appears: when I escape within lstlisting, it inserts a space in the source code.



LaTeX source



beginlstlisting
@Template(`This is a /@tikz[remember picture] node (view-left) ;@/ value /@tikz[remember picture] node (view-right) ;@/.`)
class Component
value/@tikz[remember picture] node (code-right) ;@/ = 21

endlstlisting
begintikzpicture[remember picture, overlay]
node (view) at ($(view-left)!.5!(view-right)$) ;
draw (view.south) edge [bend left] (code-right.south east);
endtikzpicture


Result



The rendered result which shows additional spaces where escaping was done.



Problem



  • There are two spaces between a and in the template (one was intentional, there's an extra one).

  • A space between in . in template.

  • Double space after value in the code.

Why do they appear and how can I get rid of them?







share|improve this question


























    up vote
    2
    down vote

    favorite












    I'm basing my code on Overlay red rectangles on top of verbatim text in order to grab draw arrows over the source code.



    I've successfully incorporated the solution into my code, however one problem appears: when I escape within lstlisting, it inserts a space in the source code.



    LaTeX source



    beginlstlisting
    @Template(`This is a /@tikz[remember picture] node (view-left) ;@/ value /@tikz[remember picture] node (view-right) ;@/.`)
    class Component
    value/@tikz[remember picture] node (code-right) ;@/ = 21

    endlstlisting
    begintikzpicture[remember picture, overlay]
    node (view) at ($(view-left)!.5!(view-right)$) ;
    draw (view.south) edge [bend left] (code-right.south east);
    endtikzpicture


    Result



    The rendered result which shows additional spaces where escaping was done.



    Problem



    • There are two spaces between a and in the template (one was intentional, there's an extra one).

    • A space between in . in template.

    • Double space after value in the code.

    Why do they appear and how can I get rid of them?







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm basing my code on Overlay red rectangles on top of verbatim text in order to grab draw arrows over the source code.



      I've successfully incorporated the solution into my code, however one problem appears: when I escape within lstlisting, it inserts a space in the source code.



      LaTeX source



      beginlstlisting
      @Template(`This is a /@tikz[remember picture] node (view-left) ;@/ value /@tikz[remember picture] node (view-right) ;@/.`)
      class Component
      value/@tikz[remember picture] node (code-right) ;@/ = 21

      endlstlisting
      begintikzpicture[remember picture, overlay]
      node (view) at ($(view-left)!.5!(view-right)$) ;
      draw (view.south) edge [bend left] (code-right.south east);
      endtikzpicture


      Result



      The rendered result which shows additional spaces where escaping was done.



      Problem



      • There are two spaces between a and in the template (one was intentional, there's an extra one).

      • A space between in . in template.

      • Double space after value in the code.

      Why do they appear and how can I get rid of them?







      share|improve this question














      I'm basing my code on Overlay red rectangles on top of verbatim text in order to grab draw arrows over the source code.



      I've successfully incorporated the solution into my code, however one problem appears: when I escape within lstlisting, it inserts a space in the source code.



      LaTeX source



      beginlstlisting
      @Template(`This is a /@tikz[remember picture] node (view-left) ;@/ value /@tikz[remember picture] node (view-right) ;@/.`)
      class Component
      value/@tikz[remember picture] node (code-right) ;@/ = 21

      endlstlisting
      begintikzpicture[remember picture, overlay]
      node (view) at ($(view-left)!.5!(view-right)$) ;
      draw (view.south) edge [bend left] (code-right.south east);
      endtikzpicture


      Result



      The rendered result which shows additional spaces where escaping was done.



      Problem



      • There are two spaces between a and in the template (one was intentional, there's an extra one).

      • A space between in . in template.

      • Double space after value in the code.

      Why do they appear and how can I get rid of them?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 27 at 21:26









      siracusa

      3,4471926




      3,4471926










      asked Aug 26 at 17:33









      Lazar Ljubenović

      31918




      31918




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Instead of enclosing the tikzpicture in a box of width 0, as @egreg suggests, it is probably easier to work with overlay, which is made for this, or to use the tizkmark library.



          documentclassarticle
          usepackagelistings
          usepackagetikz
          usetikzlibrarytikzmark,calc

          lstset
          basicstyle=ttfamilysmall,
          columns=fullflexible,
          escapeinside=/@@/



          begindocument

          beginlstlisting
          @Template(`This is a /@tikz[remember picture,overlay] node (view-left) ;@/ value /@tikz[remember picture,overlay] node (view-right) ;@/.`)
          class Component
          value/@tikz[remember picture,overlay] node (code-right) ;@/ = 21

          endlstlisting
          begintikzpicture[remember picture, overlay]
          node (view) at ($(view-left)!.5!(view-right)$) ;
          draw (view.south) edge [bend left] (code-right.south east);
          endtikzpicture

          beginlstlisting
          @Template(`This is a /@tikzmarkview-left@/ value /@tikzmarkview-right@/.`)
          class Component
          value/@tikzmarkcode-right@/ = 21

          endlstlisting
          begintikzpicture[remember picture, overlay]
          node (view) at ($(pic cs:view-left)!.5!(pic cs:view-right)$) ;
          draw (view.south) to[bend left] ([yshift=-2mm]pic cs:code-right);
          endtikzpicture

          enddocument


          enter image description here






          share|improve this answer



























            up vote
            3
            down vote













            Enclose the TikZ picture in a zero width box:



            documentclassarticle
            usepackagelistings
            usepackagetikz
            usetikzlibrarycalc

            lstset
            basicstyle=ttfamily,
            columns=fullflexible,
            escapeinside=/@@/,

            newcommandfoo[1]%
            makebox[0pt]begintikzpicture[remember picture]
            node (#1) ;
            endtikzpicture%


            begindocument

            beginlstlisting
            @Template(`This is a /@fooview-left@/ value /@fooview-right@/.`)
            class Component
            value/@foocode-right@/ = 21

            endlstlisting
            begintikzpicture[remember picture, overlay]
            node (view) at ($(view-left)!.5!(view-right)$) ;
            draw (view.south) edge [bend left] (code-right.south east);
            endtikzpicture

            enddocument


            enter image description here






            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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f447828%2fescaping-within-lstlisting-adds-a-space%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote



              accepted










              Instead of enclosing the tikzpicture in a box of width 0, as @egreg suggests, it is probably easier to work with overlay, which is made for this, or to use the tizkmark library.



              documentclassarticle
              usepackagelistings
              usepackagetikz
              usetikzlibrarytikzmark,calc

              lstset
              basicstyle=ttfamilysmall,
              columns=fullflexible,
              escapeinside=/@@/



              begindocument

              beginlstlisting
              @Template(`This is a /@tikz[remember picture,overlay] node (view-left) ;@/ value /@tikz[remember picture,overlay] node (view-right) ;@/.`)
              class Component
              value/@tikz[remember picture,overlay] node (code-right) ;@/ = 21

              endlstlisting
              begintikzpicture[remember picture, overlay]
              node (view) at ($(view-left)!.5!(view-right)$) ;
              draw (view.south) edge [bend left] (code-right.south east);
              endtikzpicture

              beginlstlisting
              @Template(`This is a /@tikzmarkview-left@/ value /@tikzmarkview-right@/.`)
              class Component
              value/@tikzmarkcode-right@/ = 21

              endlstlisting
              begintikzpicture[remember picture, overlay]
              node (view) at ($(pic cs:view-left)!.5!(pic cs:view-right)$) ;
              draw (view.south) to[bend left] ([yshift=-2mm]pic cs:code-right);
              endtikzpicture

              enddocument


              enter image description here






              share|improve this answer
























                up vote
                4
                down vote



                accepted










                Instead of enclosing the tikzpicture in a box of width 0, as @egreg suggests, it is probably easier to work with overlay, which is made for this, or to use the tizkmark library.



                documentclassarticle
                usepackagelistings
                usepackagetikz
                usetikzlibrarytikzmark,calc

                lstset
                basicstyle=ttfamilysmall,
                columns=fullflexible,
                escapeinside=/@@/



                begindocument

                beginlstlisting
                @Template(`This is a /@tikz[remember picture,overlay] node (view-left) ;@/ value /@tikz[remember picture,overlay] node (view-right) ;@/.`)
                class Component
                value/@tikz[remember picture,overlay] node (code-right) ;@/ = 21

                endlstlisting
                begintikzpicture[remember picture, overlay]
                node (view) at ($(view-left)!.5!(view-right)$) ;
                draw (view.south) edge [bend left] (code-right.south east);
                endtikzpicture

                beginlstlisting
                @Template(`This is a /@tikzmarkview-left@/ value /@tikzmarkview-right@/.`)
                class Component
                value/@tikzmarkcode-right@/ = 21

                endlstlisting
                begintikzpicture[remember picture, overlay]
                node (view) at ($(pic cs:view-left)!.5!(pic cs:view-right)$) ;
                draw (view.south) to[bend left] ([yshift=-2mm]pic cs:code-right);
                endtikzpicture

                enddocument


                enter image description here






                share|improve this answer






















                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  down vote



                  accepted






                  Instead of enclosing the tikzpicture in a box of width 0, as @egreg suggests, it is probably easier to work with overlay, which is made for this, or to use the tizkmark library.



                  documentclassarticle
                  usepackagelistings
                  usepackagetikz
                  usetikzlibrarytikzmark,calc

                  lstset
                  basicstyle=ttfamilysmall,
                  columns=fullflexible,
                  escapeinside=/@@/



                  begindocument

                  beginlstlisting
                  @Template(`This is a /@tikz[remember picture,overlay] node (view-left) ;@/ value /@tikz[remember picture,overlay] node (view-right) ;@/.`)
                  class Component
                  value/@tikz[remember picture,overlay] node (code-right) ;@/ = 21

                  endlstlisting
                  begintikzpicture[remember picture, overlay]
                  node (view) at ($(view-left)!.5!(view-right)$) ;
                  draw (view.south) edge [bend left] (code-right.south east);
                  endtikzpicture

                  beginlstlisting
                  @Template(`This is a /@tikzmarkview-left@/ value /@tikzmarkview-right@/.`)
                  class Component
                  value/@tikzmarkcode-right@/ = 21

                  endlstlisting
                  begintikzpicture[remember picture, overlay]
                  node (view) at ($(pic cs:view-left)!.5!(pic cs:view-right)$) ;
                  draw (view.south) to[bend left] ([yshift=-2mm]pic cs:code-right);
                  endtikzpicture

                  enddocument


                  enter image description here






                  share|improve this answer












                  Instead of enclosing the tikzpicture in a box of width 0, as @egreg suggests, it is probably easier to work with overlay, which is made for this, or to use the tizkmark library.



                  documentclassarticle
                  usepackagelistings
                  usepackagetikz
                  usetikzlibrarytikzmark,calc

                  lstset
                  basicstyle=ttfamilysmall,
                  columns=fullflexible,
                  escapeinside=/@@/



                  begindocument

                  beginlstlisting
                  @Template(`This is a /@tikz[remember picture,overlay] node (view-left) ;@/ value /@tikz[remember picture,overlay] node (view-right) ;@/.`)
                  class Component
                  value/@tikz[remember picture,overlay] node (code-right) ;@/ = 21

                  endlstlisting
                  begintikzpicture[remember picture, overlay]
                  node (view) at ($(view-left)!.5!(view-right)$) ;
                  draw (view.south) edge [bend left] (code-right.south east);
                  endtikzpicture

                  beginlstlisting
                  @Template(`This is a /@tikzmarkview-left@/ value /@tikzmarkview-right@/.`)
                  class Component
                  value/@tikzmarkcode-right@/ = 21

                  endlstlisting
                  begintikzpicture[remember picture, overlay]
                  node (view) at ($(pic cs:view-left)!.5!(pic cs:view-right)$) ;
                  draw (view.south) to[bend left] ([yshift=-2mm]pic cs:code-right);
                  endtikzpicture

                  enddocument


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 26 at 18:09









                  marmot

                  55.8k461121




                  55.8k461121




















                      up vote
                      3
                      down vote













                      Enclose the TikZ picture in a zero width box:



                      documentclassarticle
                      usepackagelistings
                      usepackagetikz
                      usetikzlibrarycalc

                      lstset
                      basicstyle=ttfamily,
                      columns=fullflexible,
                      escapeinside=/@@/,

                      newcommandfoo[1]%
                      makebox[0pt]begintikzpicture[remember picture]
                      node (#1) ;
                      endtikzpicture%


                      begindocument

                      beginlstlisting
                      @Template(`This is a /@fooview-left@/ value /@fooview-right@/.`)
                      class Component
                      value/@foocode-right@/ = 21

                      endlstlisting
                      begintikzpicture[remember picture, overlay]
                      node (view) at ($(view-left)!.5!(view-right)$) ;
                      draw (view.south) edge [bend left] (code-right.south east);
                      endtikzpicture

                      enddocument


                      enter image description here






                      share|improve this answer
























                        up vote
                        3
                        down vote













                        Enclose the TikZ picture in a zero width box:



                        documentclassarticle
                        usepackagelistings
                        usepackagetikz
                        usetikzlibrarycalc

                        lstset
                        basicstyle=ttfamily,
                        columns=fullflexible,
                        escapeinside=/@@/,

                        newcommandfoo[1]%
                        makebox[0pt]begintikzpicture[remember picture]
                        node (#1) ;
                        endtikzpicture%


                        begindocument

                        beginlstlisting
                        @Template(`This is a /@fooview-left@/ value /@fooview-right@/.`)
                        class Component
                        value/@foocode-right@/ = 21

                        endlstlisting
                        begintikzpicture[remember picture, overlay]
                        node (view) at ($(view-left)!.5!(view-right)$) ;
                        draw (view.south) edge [bend left] (code-right.south east);
                        endtikzpicture

                        enddocument


                        enter image description here






                        share|improve this answer






















                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          Enclose the TikZ picture in a zero width box:



                          documentclassarticle
                          usepackagelistings
                          usepackagetikz
                          usetikzlibrarycalc

                          lstset
                          basicstyle=ttfamily,
                          columns=fullflexible,
                          escapeinside=/@@/,

                          newcommandfoo[1]%
                          makebox[0pt]begintikzpicture[remember picture]
                          node (#1) ;
                          endtikzpicture%


                          begindocument

                          beginlstlisting
                          @Template(`This is a /@fooview-left@/ value /@fooview-right@/.`)
                          class Component
                          value/@foocode-right@/ = 21

                          endlstlisting
                          begintikzpicture[remember picture, overlay]
                          node (view) at ($(view-left)!.5!(view-right)$) ;
                          draw (view.south) edge [bend left] (code-right.south east);
                          endtikzpicture

                          enddocument


                          enter image description here






                          share|improve this answer












                          Enclose the TikZ picture in a zero width box:



                          documentclassarticle
                          usepackagelistings
                          usepackagetikz
                          usetikzlibrarycalc

                          lstset
                          basicstyle=ttfamily,
                          columns=fullflexible,
                          escapeinside=/@@/,

                          newcommandfoo[1]%
                          makebox[0pt]begintikzpicture[remember picture]
                          node (#1) ;
                          endtikzpicture%


                          begindocument

                          beginlstlisting
                          @Template(`This is a /@fooview-left@/ value /@fooview-right@/.`)
                          class Component
                          value/@foocode-right@/ = 21

                          endlstlisting
                          begintikzpicture[remember picture, overlay]
                          node (view) at ($(view-left)!.5!(view-right)$) ;
                          draw (view.south) edge [bend left] (code-right.south east);
                          endtikzpicture

                          enddocument


                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 26 at 18:05









                          egreg

                          680k8318083056




                          680k8318083056



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f447828%2fescaping-within-lstlisting-adds-a-space%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery