Tikz - highlight text in an image












6















How can I highlight text in an image with tikz by using a rectangle and have the rest of the page filled with a grey (or opaque black) tone, see example below (taken from here)?



enter image description here



You can see a screenshot taken from GIMP where I just highlight text using the rectangle selector tool. How can I achieve a similar effect using tikz in xetex (without the yellow dashed lines at the borders)?



My code I have so far is:



begin{tikzpicture}[remember picture, overlay]
node [anchor=south west,inner sep=0] (A) at (0,0) {includegraphics[width=linewidth, height=paperheight]{image}}{};
fill [draw=none, fill=black, fill opacity=0.3]
(0,0) --
(A.north west) -- (A.north east) -- (A.south east) --
(0,0) -- (0,0) -- cycle;
filldraw [fill=white, draw=white, fill opacity=.3] (3.2,3.2) rectangle (14.6,10.5);
end{tikzpicture}


The issue I run into with this code is that filling the whole page with an opaque black and filling the rectangle with an opaque white leads to an opaque grey.










share|improve this question























  • Related Question: Highlighting part of an image.

    – Peter Grill
    8 hours ago
















6















How can I highlight text in an image with tikz by using a rectangle and have the rest of the page filled with a grey (or opaque black) tone, see example below (taken from here)?



enter image description here



You can see a screenshot taken from GIMP where I just highlight text using the rectangle selector tool. How can I achieve a similar effect using tikz in xetex (without the yellow dashed lines at the borders)?



My code I have so far is:



begin{tikzpicture}[remember picture, overlay]
node [anchor=south west,inner sep=0] (A) at (0,0) {includegraphics[width=linewidth, height=paperheight]{image}}{};
fill [draw=none, fill=black, fill opacity=0.3]
(0,0) --
(A.north west) -- (A.north east) -- (A.south east) --
(0,0) -- (0,0) -- cycle;
filldraw [fill=white, draw=white, fill opacity=.3] (3.2,3.2) rectangle (14.6,10.5);
end{tikzpicture}


The issue I run into with this code is that filling the whole page with an opaque black and filling the rectangle with an opaque white leads to an opaque grey.










share|improve this question























  • Related Question: Highlighting part of an image.

    – Peter Grill
    8 hours ago














6












6








6








How can I highlight text in an image with tikz by using a rectangle and have the rest of the page filled with a grey (or opaque black) tone, see example below (taken from here)?



enter image description here



You can see a screenshot taken from GIMP where I just highlight text using the rectangle selector tool. How can I achieve a similar effect using tikz in xetex (without the yellow dashed lines at the borders)?



My code I have so far is:



begin{tikzpicture}[remember picture, overlay]
node [anchor=south west,inner sep=0] (A) at (0,0) {includegraphics[width=linewidth, height=paperheight]{image}}{};
fill [draw=none, fill=black, fill opacity=0.3]
(0,0) --
(A.north west) -- (A.north east) -- (A.south east) --
(0,0) -- (0,0) -- cycle;
filldraw [fill=white, draw=white, fill opacity=.3] (3.2,3.2) rectangle (14.6,10.5);
end{tikzpicture}


The issue I run into with this code is that filling the whole page with an opaque black and filling the rectangle with an opaque white leads to an opaque grey.










share|improve this question














How can I highlight text in an image with tikz by using a rectangle and have the rest of the page filled with a grey (or opaque black) tone, see example below (taken from here)?



enter image description here



You can see a screenshot taken from GIMP where I just highlight text using the rectangle selector tool. How can I achieve a similar effect using tikz in xetex (without the yellow dashed lines at the borders)?



My code I have so far is:



begin{tikzpicture}[remember picture, overlay]
node [anchor=south west,inner sep=0] (A) at (0,0) {includegraphics[width=linewidth, height=paperheight]{image}}{};
fill [draw=none, fill=black, fill opacity=0.3]
(0,0) --
(A.north west) -- (A.north east) -- (A.south east) --
(0,0) -- (0,0) -- cycle;
filldraw [fill=white, draw=white, fill opacity=.3] (3.2,3.2) rectangle (14.6,10.5);
end{tikzpicture}


The issue I run into with this code is that filling the whole page with an opaque black and filling the rectangle with an opaque white leads to an opaque grey.







tikz-pgf graphics xetex includegraphics






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 11 hours ago









Til HundTil Hund

586215




586215













  • Related Question: Highlighting part of an image.

    – Peter Grill
    8 hours ago



















  • Related Question: Highlighting part of an image.

    – Peter Grill
    8 hours ago

















Related Question: Highlighting part of an image.

– Peter Grill
8 hours ago





Related Question: Highlighting part of an image.

– Peter Grill
8 hours ago










2 Answers
2






active

oldest

votes


















5














Depending on what format the images are, no tikz required:



documentclass{article}
usepackage{graphicx,stackengine,trimclip}
begin{document}
stackinset{l}{150pt}{b}{130pt}{%
clipbox{150pt 130pt 100pt 50pt}{includegraphics{example-image.jpg}}%
}{%
includegraphics[decodearray={.3 .5 .3 .5 .3 .5}]{example-image.jpg}%
}
end{document}


enter image description here



Depending on the color palette, the decodearray may need tweaking:



documentclass{article}
usepackage{graphicx,stackengine,trimclip}
begin{document}
stackinset{l}{20pt}{b}{40pt}{%
clipbox{20pt 40pt 15pt 15pt}{includegraphics{example-grid-100x100bp.png}}%
}{%
includegraphics[decodearray={.3 .6 .3 .6 .3 .6}]{example-grid-100x100bp.jpg}%
}
end{document}


decodearray will not work for cmyk color schemes, and only a limited number of image formats (jpeg being one).



enter image description here






share|improve this answer

































    5














    Here is a recipe and an application. First the recipe, using this answer.




    1. Add a grid on top.

    2. Draw the contour you want to highlight.

    3. Use the contour in an even odd rule fill (and drop the grid).


    On purpose I used a document in which you may not want to use a horizontal box.



    documentclass[tikz,border=3.14mm]{standalone}
    begin{document}
    foreach X in {0,1,2}
    {begin{tikzpicture}
    node[anchor=south west,inner sep=0] (image) at (0,0)
    {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
    % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
    begin{scope}[x={(image.south east)},y={(image.north west)}]
    path[use as bounding box] (-0.1,-0.1) rectangle (1,1);
    % ^^^ only for animation
    ifnumX<2
    draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    foreach x in {0,1,...,9} { node [anchor=north] at (x/10,0) {0.x}; }
    foreach y in {0,1,...,9} { node [anchor=east] at (0,y/10) {0.y}; }
    fi
    ifnumX=1
    draw (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle;
    fi
    ifnumX=2
    fill[even odd rule,opacity=0.4]
    (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
    (0,0) rectangle (1,1);
    fi
    end{scope}
    end{tikzpicture}}
    end{document}


    enter image description here



    Of course, in the end you drop all the auxiliary stuff to arrive at



    documentclass[tikz,border=3.14mm]{standalone}
    begin{document}
    begin{tikzpicture}
    node[anchor=south west,inner sep=0] (image) at (0,0)
    {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
    % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
    begin{scope}[x={(image.south east)},y={(image.north west)}]
    fill[even odd rule,opacity=0.4]
    (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
    (0,0) rectangle (1,1);
    end{scope}
    end{tikzpicture}
    end{document}


    enter image description here



    enter image description here



    Whether or not my choice of the highlighted text has anything to do with a wall at the border to Mexico, I do not want to elaborate on.






    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%2f475681%2ftikz-highlight-text-in-an-image%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














      Depending on what format the images are, no tikz required:



      documentclass{article}
      usepackage{graphicx,stackengine,trimclip}
      begin{document}
      stackinset{l}{150pt}{b}{130pt}{%
      clipbox{150pt 130pt 100pt 50pt}{includegraphics{example-image.jpg}}%
      }{%
      includegraphics[decodearray={.3 .5 .3 .5 .3 .5}]{example-image.jpg}%
      }
      end{document}


      enter image description here



      Depending on the color palette, the decodearray may need tweaking:



      documentclass{article}
      usepackage{graphicx,stackengine,trimclip}
      begin{document}
      stackinset{l}{20pt}{b}{40pt}{%
      clipbox{20pt 40pt 15pt 15pt}{includegraphics{example-grid-100x100bp.png}}%
      }{%
      includegraphics[decodearray={.3 .6 .3 .6 .3 .6}]{example-grid-100x100bp.jpg}%
      }
      end{document}


      decodearray will not work for cmyk color schemes, and only a limited number of image formats (jpeg being one).



      enter image description here






      share|improve this answer






























        5














        Depending on what format the images are, no tikz required:



        documentclass{article}
        usepackage{graphicx,stackengine,trimclip}
        begin{document}
        stackinset{l}{150pt}{b}{130pt}{%
        clipbox{150pt 130pt 100pt 50pt}{includegraphics{example-image.jpg}}%
        }{%
        includegraphics[decodearray={.3 .5 .3 .5 .3 .5}]{example-image.jpg}%
        }
        end{document}


        enter image description here



        Depending on the color palette, the decodearray may need tweaking:



        documentclass{article}
        usepackage{graphicx,stackengine,trimclip}
        begin{document}
        stackinset{l}{20pt}{b}{40pt}{%
        clipbox{20pt 40pt 15pt 15pt}{includegraphics{example-grid-100x100bp.png}}%
        }{%
        includegraphics[decodearray={.3 .6 .3 .6 .3 .6}]{example-grid-100x100bp.jpg}%
        }
        end{document}


        decodearray will not work for cmyk color schemes, and only a limited number of image formats (jpeg being one).



        enter image description here






        share|improve this answer




























          5












          5








          5







          Depending on what format the images are, no tikz required:



          documentclass{article}
          usepackage{graphicx,stackengine,trimclip}
          begin{document}
          stackinset{l}{150pt}{b}{130pt}{%
          clipbox{150pt 130pt 100pt 50pt}{includegraphics{example-image.jpg}}%
          }{%
          includegraphics[decodearray={.3 .5 .3 .5 .3 .5}]{example-image.jpg}%
          }
          end{document}


          enter image description here



          Depending on the color palette, the decodearray may need tweaking:



          documentclass{article}
          usepackage{graphicx,stackengine,trimclip}
          begin{document}
          stackinset{l}{20pt}{b}{40pt}{%
          clipbox{20pt 40pt 15pt 15pt}{includegraphics{example-grid-100x100bp.png}}%
          }{%
          includegraphics[decodearray={.3 .6 .3 .6 .3 .6}]{example-grid-100x100bp.jpg}%
          }
          end{document}


          decodearray will not work for cmyk color schemes, and only a limited number of image formats (jpeg being one).



          enter image description here






          share|improve this answer















          Depending on what format the images are, no tikz required:



          documentclass{article}
          usepackage{graphicx,stackengine,trimclip}
          begin{document}
          stackinset{l}{150pt}{b}{130pt}{%
          clipbox{150pt 130pt 100pt 50pt}{includegraphics{example-image.jpg}}%
          }{%
          includegraphics[decodearray={.3 .5 .3 .5 .3 .5}]{example-image.jpg}%
          }
          end{document}


          enter image description here



          Depending on the color palette, the decodearray may need tweaking:



          documentclass{article}
          usepackage{graphicx,stackengine,trimclip}
          begin{document}
          stackinset{l}{20pt}{b}{40pt}{%
          clipbox{20pt 40pt 15pt 15pt}{includegraphics{example-grid-100x100bp.png}}%
          }{%
          includegraphics[decodearray={.3 .6 .3 .6 .3 .6}]{example-grid-100x100bp.jpg}%
          }
          end{document}


          decodearray will not work for cmyk color schemes, and only a limited number of image formats (jpeg being one).



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 10 hours ago

























          answered 11 hours ago









          Steven B. SegletesSteven B. Segletes

          156k9201411




          156k9201411























              5














              Here is a recipe and an application. First the recipe, using this answer.




              1. Add a grid on top.

              2. Draw the contour you want to highlight.

              3. Use the contour in an even odd rule fill (and drop the grid).


              On purpose I used a document in which you may not want to use a horizontal box.



              documentclass[tikz,border=3.14mm]{standalone}
              begin{document}
              foreach X in {0,1,2}
              {begin{tikzpicture}
              node[anchor=south west,inner sep=0] (image) at (0,0)
              {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
              % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
              begin{scope}[x={(image.south east)},y={(image.north west)}]
              path[use as bounding box] (-0.1,-0.1) rectangle (1,1);
              % ^^^ only for animation
              ifnumX<2
              draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
              foreach x in {0,1,...,9} { node [anchor=north] at (x/10,0) {0.x}; }
              foreach y in {0,1,...,9} { node [anchor=east] at (0,y/10) {0.y}; }
              fi
              ifnumX=1
              draw (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle;
              fi
              ifnumX=2
              fill[even odd rule,opacity=0.4]
              (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
              (0,0) rectangle (1,1);
              fi
              end{scope}
              end{tikzpicture}}
              end{document}


              enter image description here



              Of course, in the end you drop all the auxiliary stuff to arrive at



              documentclass[tikz,border=3.14mm]{standalone}
              begin{document}
              begin{tikzpicture}
              node[anchor=south west,inner sep=0] (image) at (0,0)
              {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
              % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
              begin{scope}[x={(image.south east)},y={(image.north west)}]
              fill[even odd rule,opacity=0.4]
              (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
              (0,0) rectangle (1,1);
              end{scope}
              end{tikzpicture}
              end{document}


              enter image description here



              enter image description here



              Whether or not my choice of the highlighted text has anything to do with a wall at the border to Mexico, I do not want to elaborate on.






              share|improve this answer




























                5














                Here is a recipe and an application. First the recipe, using this answer.




                1. Add a grid on top.

                2. Draw the contour you want to highlight.

                3. Use the contour in an even odd rule fill (and drop the grid).


                On purpose I used a document in which you may not want to use a horizontal box.



                documentclass[tikz,border=3.14mm]{standalone}
                begin{document}
                foreach X in {0,1,2}
                {begin{tikzpicture}
                node[anchor=south west,inner sep=0] (image) at (0,0)
                {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                begin{scope}[x={(image.south east)},y={(image.north west)}]
                path[use as bounding box] (-0.1,-0.1) rectangle (1,1);
                % ^^^ only for animation
                ifnumX<2
                draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
                foreach x in {0,1,...,9} { node [anchor=north] at (x/10,0) {0.x}; }
                foreach y in {0,1,...,9} { node [anchor=east] at (0,y/10) {0.y}; }
                fi
                ifnumX=1
                draw (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle;
                fi
                ifnumX=2
                fill[even odd rule,opacity=0.4]
                (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                (0,0) rectangle (1,1);
                fi
                end{scope}
                end{tikzpicture}}
                end{document}


                enter image description here



                Of course, in the end you drop all the auxiliary stuff to arrive at



                documentclass[tikz,border=3.14mm]{standalone}
                begin{document}
                begin{tikzpicture}
                node[anchor=south west,inner sep=0] (image) at (0,0)
                {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                begin{scope}[x={(image.south east)},y={(image.north west)}]
                fill[even odd rule,opacity=0.4]
                (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                (0,0) rectangle (1,1);
                end{scope}
                end{tikzpicture}
                end{document}


                enter image description here



                enter image description here



                Whether or not my choice of the highlighted text has anything to do with a wall at the border to Mexico, I do not want to elaborate on.






                share|improve this answer


























                  5












                  5








                  5







                  Here is a recipe and an application. First the recipe, using this answer.




                  1. Add a grid on top.

                  2. Draw the contour you want to highlight.

                  3. Use the contour in an even odd rule fill (and drop the grid).


                  On purpose I used a document in which you may not want to use a horizontal box.



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  foreach X in {0,1,2}
                  {begin{tikzpicture}
                  node[anchor=south west,inner sep=0] (image) at (0,0)
                  {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                  % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                  begin{scope}[x={(image.south east)},y={(image.north west)}]
                  path[use as bounding box] (-0.1,-0.1) rectangle (1,1);
                  % ^^^ only for animation
                  ifnumX<2
                  draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
                  foreach x in {0,1,...,9} { node [anchor=north] at (x/10,0) {0.x}; }
                  foreach y in {0,1,...,9} { node [anchor=east] at (0,y/10) {0.y}; }
                  fi
                  ifnumX=1
                  draw (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle;
                  fi
                  ifnumX=2
                  fill[even odd rule,opacity=0.4]
                  (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                  (0,0) rectangle (1,1);
                  fi
                  end{scope}
                  end{tikzpicture}}
                  end{document}


                  enter image description here



                  Of course, in the end you drop all the auxiliary stuff to arrive at



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  begin{tikzpicture}
                  node[anchor=south west,inner sep=0] (image) at (0,0)
                  {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                  % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                  begin{scope}[x={(image.south east)},y={(image.north west)}]
                  fill[even odd rule,opacity=0.4]
                  (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                  (0,0) rectangle (1,1);
                  end{scope}
                  end{tikzpicture}
                  end{document}


                  enter image description here



                  enter image description here



                  Whether or not my choice of the highlighted text has anything to do with a wall at the border to Mexico, I do not want to elaborate on.






                  share|improve this answer













                  Here is a recipe and an application. First the recipe, using this answer.




                  1. Add a grid on top.

                  2. Draw the contour you want to highlight.

                  3. Use the contour in an even odd rule fill (and drop the grid).


                  On purpose I used a document in which you may not want to use a horizontal box.



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  foreach X in {0,1,2}
                  {begin{tikzpicture}
                  node[anchor=south west,inner sep=0] (image) at (0,0)
                  {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                  % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                  begin{scope}[x={(image.south east)},y={(image.north west)}]
                  path[use as bounding box] (-0.1,-0.1) rectangle (1,1);
                  % ^^^ only for animation
                  ifnumX<2
                  draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
                  foreach x in {0,1,...,9} { node [anchor=north] at (x/10,0) {0.x}; }
                  foreach y in {0,1,...,9} { node [anchor=east] at (0,y/10) {0.y}; }
                  fi
                  ifnumX=1
                  draw (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle;
                  fi
                  ifnumX=2
                  fill[even odd rule,opacity=0.4]
                  (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                  (0,0) rectangle (1,1);
                  fi
                  end{scope}
                  end{tikzpicture}}
                  end{document}


                  enter image description here



                  Of course, in the end you drop all the auxiliary stuff to arrive at



                  documentclass[tikz,border=3.14mm]{standalone}
                  begin{document}
                  begin{tikzpicture}
                  node[anchor=south west,inner sep=0] (image) at (0,0)
                  {includegraphics[width=0.9textwidth]{Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence,_LOC.jpg}};
                  % ^^^ https://upload.wikimedia.org/wikipedia/commons/4/4e/Dunlap_broadside_copy_of_the_United_States_Declaration_of_Independence%2C_LOC.jpg
                  begin{scope}[x={(image.south east)},y={(image.north west)}]
                  fill[even odd rule,opacity=0.4]
                  (0.11,0.4) -- (0.37,0.404) -- (0.37,0.414) -- (0.11,0.41) -- cycle
                  (0,0) rectangle (1,1);
                  end{scope}
                  end{tikzpicture}
                  end{document}


                  enter image description here



                  enter image description here



                  Whether or not my choice of the highlighted text has anything to do with a wall at the border to Mexico, I do not want to elaborate on.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 10 hours ago









                  marmotmarmot

                  102k4119228




                  102k4119228






























                      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%2f475681%2ftikz-highlight-text-in-an-image%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

                      Magento 2 controller redirect on button click in phtml file

                      Polycentropodidae