-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for externalizing tikz images. #34
base: master
Are you sure you want to change the base?
Conversation
This commit will cause all the tikz images to be generated first in the tikz-cache folder before being included in the main PDF file. There are several issues that need to be resolved for this to work: - Whatever command is being used to compile the document (e.g. `latexmk` or `pdflatex` needs to have the `-shell-escape` flag added. - The tikz-cache folder is not auto-generated, so it is being tracked in version control to avoid users cloning the repo and seeing mysterious error messages when compiling. No cached tikz files should be added to this directory. - The \newenvironment command used in our custom circuit and plot environments does not play well with the externalizing library. These were modified to use the environ library which solves the problem as described [here](https://tex.stackexchange.com/a/15614) - This caching significantly improves the compile time when figures are already cached, but the first compile takes much longer since the image compilation is single-threaded. However, it is possible to use tikzexternalize in `list and make` mode which allows you to use `make -j` to compile all the images using multiple threads. This requires running the pdflatex commands manually without some more complex configuration of a latexmkrc file. Only attempt this if you know what you are doing. Otherwise, just wait a couple minutes for the compilation.
36021e4
to
7b46c1f
Compare
Closes #32 |
I'm leaving this as a draft PR for now to allow people to test out the workflow and see if they like it. A couple things to point out:
Some issues I have observed so far:
The solution to both problems is probably some combination of switching to make and using the |
Hi, could you explain a bit about "add the -shell-escape flag "? I'm using vs code + latex workshop and default keyboard shortcuts. How should I set the flag? Thanks! |
For sure! I use the same setup. Basically Latex Workshop uses "recipes" to define how the latex file should be built. The recipe specifies the commands you need to type into the command line to build the project. There were a number of default recipes included for me, and I added a new one to called To do this, I created a workspace-specific settings file at {
"latex-workshop.latex.tools": [
{
"name": "latexmk-shell-esc",
"command": "latexmk",
"args": [
"-shell-escape", // <---- this line is the one that's important
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"-pdf",
"-outdir=%OUTDIR%",
"%DOC%"
],
"env": {}
},
],
"latex-workshop.latex.recipes": [
{
"name": "latexmk-shell-esc",
"tools": [
"latexmk-shell-esc"
]
}
]
} I think I may have needed to reload the extension, but after that, I had the new recipe available to me. Let me know if this works for you! |
This commit will cause all the tikz images to be generated first in the
tikz-cache folder before being included in the main PDF file. There are
several issues that need to be resolved for this to work:
version control to avoid users cloning the repo and seeing mysterious
error messages when compiling. No cached tikz files should be added to
this repository.
environments does not play well with the externalizing library. These
were modified to use the environ library which solves the problem as
described here
already cached, but the first compile takes much longer since the image
compilation is single-threaded. However, it is possible to use
tikzexternalize in
list and make
mode which allows you to usemake -j
to compile all the images using multiple threads. This requiresrunning the pdflatex commands manually without some more complex
configuration of a latexmkrc file. Only attempt this if you know what
you are doing. Otherwise, just wait a couple minutes for the
compilation.