How to externalize TikZ pictures












6















I have an article with many TikZ pictures. In order to make the code more clear and to save compilation time, I want to remove the TikZ code from the main document. I read that this is possible with the tikzlibrary "external". (for example see this question).

But I am not sure, where to write which commands?



What do I write in the file/the files which consists only of the code for the tikz pictures?

What and where do I write in the main document in order to import the pictures?










share|improve this question





























    6















    I have an article with many TikZ pictures. In order to make the code more clear and to save compilation time, I want to remove the TikZ code from the main document. I read that this is possible with the tikzlibrary "external". (for example see this question).

    But I am not sure, where to write which commands?



    What do I write in the file/the files which consists only of the code for the tikz pictures?

    What and where do I write in the main document in order to import the pictures?










    share|improve this question



























      6












      6








      6


      2






      I have an article with many TikZ pictures. In order to make the code more clear and to save compilation time, I want to remove the TikZ code from the main document. I read that this is possible with the tikzlibrary "external". (for example see this question).

      But I am not sure, where to write which commands?



      What do I write in the file/the files which consists only of the code for the tikz pictures?

      What and where do I write in the main document in order to import the pictures?










      share|improve this question
















      I have an article with many TikZ pictures. In order to make the code more clear and to save compilation time, I want to remove the TikZ code from the main document. I read that this is possible with the tikzlibrary "external". (for example see this question).

      But I am not sure, where to write which commands?



      What do I write in the file/the files which consists only of the code for the tikz pictures?

      What and where do I write in the main document in order to import the pictures?







      tikz-pgf graphics tikz-external






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 at 11:10









      sheß

      2,06511436




      2,06511436










      asked Apr 1 at 10:34









      klirkklirk

      1685




      1685






















          1 Answer
          1






          active

          oldest

          votes


















          7














          There are two questions hidden in your post, they have two answers that are basically orthogonal:



          Speeding up compilation by using tikzexternalize:



          You don't actually have to write them into separate files to save compilation time. You can leave your code almost unchanged, that's the beauty of it. This is the simplest possible setup with externalization



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          begin{tikzpicture}
          node {real complex figure};
          end{tikzpicture}
          end{document}


          This will only run if your LaTeX is set up to run with shell escape (see here for example)



          Having tidy code, by writing TikZ code into separte files:



          Of course you can also store the begin{tikzpicture}...end{tikzpicture} code in an external .tex or .tikz file and use input to include it. But that is a matter of taste and does not effect compilation performance.



          You could write



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          input{tikzfigure1.tikz}
          end{document}


          and
          into tikzfigure1.tikz:



          begin{tikzpicture}  
          node {real complex figure};
          end{tikzpicture}


          I tend to define my own command to include tikz files, instead of using input in order to take care of one more thing:



          newcommand{inputtikz}[1]{%
          tikzsetnextfilename{#1}%
          input{#1.tikz}%
          }


          This will make sure that the externalization is based on the file name (instead of the order) so that it doesn't get confused if you change the orders of TikZ pictures in your document.






          share|improve this answer





















          • 2





            Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

            – klirk
            Apr 1 at 12:57






          • 2





            Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

            – sheß
            Apr 1 at 13:11












          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%2f482557%2fhow-to-externalize-tikz-pictures%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          7














          There are two questions hidden in your post, they have two answers that are basically orthogonal:



          Speeding up compilation by using tikzexternalize:



          You don't actually have to write them into separate files to save compilation time. You can leave your code almost unchanged, that's the beauty of it. This is the simplest possible setup with externalization



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          begin{tikzpicture}
          node {real complex figure};
          end{tikzpicture}
          end{document}


          This will only run if your LaTeX is set up to run with shell escape (see here for example)



          Having tidy code, by writing TikZ code into separte files:



          Of course you can also store the begin{tikzpicture}...end{tikzpicture} code in an external .tex or .tikz file and use input to include it. But that is a matter of taste and does not effect compilation performance.



          You could write



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          input{tikzfigure1.tikz}
          end{document}


          and
          into tikzfigure1.tikz:



          begin{tikzpicture}  
          node {real complex figure};
          end{tikzpicture}


          I tend to define my own command to include tikz files, instead of using input in order to take care of one more thing:



          newcommand{inputtikz}[1]{%
          tikzsetnextfilename{#1}%
          input{#1.tikz}%
          }


          This will make sure that the externalization is based on the file name (instead of the order) so that it doesn't get confused if you change the orders of TikZ pictures in your document.






          share|improve this answer





















          • 2





            Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

            – klirk
            Apr 1 at 12:57






          • 2





            Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

            – sheß
            Apr 1 at 13:11
















          7














          There are two questions hidden in your post, they have two answers that are basically orthogonal:



          Speeding up compilation by using tikzexternalize:



          You don't actually have to write them into separate files to save compilation time. You can leave your code almost unchanged, that's the beauty of it. This is the simplest possible setup with externalization



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          begin{tikzpicture}
          node {real complex figure};
          end{tikzpicture}
          end{document}


          This will only run if your LaTeX is set up to run with shell escape (see here for example)



          Having tidy code, by writing TikZ code into separte files:



          Of course you can also store the begin{tikzpicture}...end{tikzpicture} code in an external .tex or .tikz file and use input to include it. But that is a matter of taste and does not effect compilation performance.



          You could write



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          input{tikzfigure1.tikz}
          end{document}


          and
          into tikzfigure1.tikz:



          begin{tikzpicture}  
          node {real complex figure};
          end{tikzpicture}


          I tend to define my own command to include tikz files, instead of using input in order to take care of one more thing:



          newcommand{inputtikz}[1]{%
          tikzsetnextfilename{#1}%
          input{#1.tikz}%
          }


          This will make sure that the externalization is based on the file name (instead of the order) so that it doesn't get confused if you change the orders of TikZ pictures in your document.






          share|improve this answer





















          • 2





            Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

            – klirk
            Apr 1 at 12:57






          • 2





            Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

            – sheß
            Apr 1 at 13:11














          7












          7








          7







          There are two questions hidden in your post, they have two answers that are basically orthogonal:



          Speeding up compilation by using tikzexternalize:



          You don't actually have to write them into separate files to save compilation time. You can leave your code almost unchanged, that's the beauty of it. This is the simplest possible setup with externalization



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          begin{tikzpicture}
          node {real complex figure};
          end{tikzpicture}
          end{document}


          This will only run if your LaTeX is set up to run with shell escape (see here for example)



          Having tidy code, by writing TikZ code into separte files:



          Of course you can also store the begin{tikzpicture}...end{tikzpicture} code in an external .tex or .tikz file and use input to include it. But that is a matter of taste and does not effect compilation performance.



          You could write



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          input{tikzfigure1.tikz}
          end{document}


          and
          into tikzfigure1.tikz:



          begin{tikzpicture}  
          node {real complex figure};
          end{tikzpicture}


          I tend to define my own command to include tikz files, instead of using input in order to take care of one more thing:



          newcommand{inputtikz}[1]{%
          tikzsetnextfilename{#1}%
          input{#1.tikz}%
          }


          This will make sure that the externalization is based on the file name (instead of the order) so that it doesn't get confused if you change the orders of TikZ pictures in your document.






          share|improve this answer















          There are two questions hidden in your post, they have two answers that are basically orthogonal:



          Speeding up compilation by using tikzexternalize:



          You don't actually have to write them into separate files to save compilation time. You can leave your code almost unchanged, that's the beauty of it. This is the simplest possible setup with externalization



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          begin{tikzpicture}
          node {real complex figure};
          end{tikzpicture}
          end{document}


          This will only run if your LaTeX is set up to run with shell escape (see here for example)



          Having tidy code, by writing TikZ code into separte files:



          Of course you can also store the begin{tikzpicture}...end{tikzpicture} code in an external .tex or .tikz file and use input to include it. But that is a matter of taste and does not effect compilation performance.



          You could write



          documentclass{article}
          usepackage{tikz}
          usetikzlibrary{external}
          tikzexternalize[prefix=figures/]
          begin{document}
          input{tikzfigure1.tikz}
          end{document}


          and
          into tikzfigure1.tikz:



          begin{tikzpicture}  
          node {real complex figure};
          end{tikzpicture}


          I tend to define my own command to include tikz files, instead of using input in order to take care of one more thing:



          newcommand{inputtikz}[1]{%
          tikzsetnextfilename{#1}%
          input{#1.tikz}%
          }


          This will make sure that the externalization is based on the file name (instead of the order) so that it doesn't get confused if you change the orders of TikZ pictures in your document.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 1 at 11:29

























          answered Apr 1 at 10:49









          sheßsheß

          2,06511436




          2,06511436








          • 2





            Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

            – klirk
            Apr 1 at 12:57






          • 2





            Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

            – sheß
            Apr 1 at 13:11














          • 2





            Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

            – klirk
            Apr 1 at 12:57






          • 2





            Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

            – sheß
            Apr 1 at 13:11








          2




          2





          Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

          – klirk
          Apr 1 at 12:57





          Thanks, this was really helpful. Something I want to add though: In order to make this work I needed to change two things: Remove spaces from the name of my .tex file, i.e. "file a.tex" to "filea.tex" and to change the command for pdf latex to "pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex"

          – klirk
          Apr 1 at 12:57




          2




          2





          Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

          – sheß
          Apr 1 at 13:11





          Ok, makes sense. I never have spaces in file names anyways, but I see how this could lead to problems there. I edited a remark about --shell-escape into my answer

          – sheß
          Apr 1 at 13:11


















          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%2f482557%2fhow-to-externalize-tikz-pictures%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 send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?