- Overview
- Installation
- Project organization
- Exporting diagrams as PDF and EPS files
- Creating a single document with all generated diagrams
- Clearing outputs
- Creating your own TikZ diagrams
This project has two main goals:
- Make it easier for new users of TikZ to create diagrams. Creating diagrams for LaTeX using TikZ can be challenging, and often the easiest way to learn it is to build off of what others have done. This project is an organization of all the TikZ diagrams I have created throughout the years. The source code for producing the diagrams contains many comments for what each bit of the code is doing.
- Provide an easy way to export PDF and EPS files of diagrams so they don't have to be recompiled in larger documents. Complicated TikZ diagrams can severely affect compilation times, so it is often better (especially for larger documents) to include them as PDF files (although you should note that this may increase the file size of your document). Included in this project is a simple script (
export_diagrams.sh
) that traverses thesrc/
folder of this project and exports all TikZ diagrams to PDF and (if specified) EPS files. See the section titled Exporting diagrams as PDF and EPS files for more information.
- TeX Live. This will serve as our LaTeX compiler.
- For macOS, I am using the MacTeX distribution.
- Once the installation is complete, close any terminal windows you have open and open a new terminal. This should ensure that the LaTeX distribution is added to your PATH environment variable (should be done automatically). This will be relevant when building a document using the LaTeX Workshop VS Code extension (see step 6 of the Setup section below).
- If the above step does not work, restart your computer and try again.
- Visual Studio Code (VS Code).
- Git. Cloning the repository + revision control.
pdftops
. Converting frompdf
toeps
.-
First, check if
pdftops
is already installed (sometimes installed in LaTeX distributions) by runningwhich pdftops
to locate its executable.
-
If
pdftops
is not installed, you can installer it by installing Poppler. For example, in a terminal on macOS, I performed this installation viabrew install poppler
-
-
In a terminal, navigate to a folder in which you would like to clone the
tikz_diagrams
repository. -
Clone the
tikz_diagrams
repository.git clone https://github.com/tamaskis/tikz_diagrams.git
-
Open the
tikz_diagrams
project in VS Code. -
Grant permissions to execute the provided scripts.
chmod +x export_diagrams.sh chmod +x create_doc.sh chmod +x clear_outputs.sh
-
Try executing
create_doc.sh
../create_doc.sh
-
If the above step did not work, then the
PATH
environment variable was not set correctly during your installation of a LaTeX distribution. See this page for more information.
All .tex
files creating diagrams are contained within the src/
folder. Within the src/
folder, they are organized into separate subfolders, each representing different categories.
- tikz_diagrams/
|- .vscode/
| |- extensions.json # recommend extensions
| |- settings.json # configure the project in VS Code
|- src/
| |- .images/
| | |- licenses/ # licenses for third-party images
| | |- IMAGE_SOURCES.md # lists sources for each image
| | |- image_creation.pptx # PowerPoint document used to create some custom images
| | |- image_1.eps
| | |- image_2.png
| | |- ...
| |- .preamble/
| | |- third_party/ # third-party TikZ tools that need to be manually added to a project
| | |- tikz_diagrams_template.sty # style template used by all .tex files defining TikZ diagrams
| |- subfolder_1/
| | |- diagram_1.tex
| | |- diagram_2.tex
| | |- ...
| |- subfolder_2/
| | |- diagram_3.tex
| | |- diagram_4.tex
| | |- ...
| |- ...
|- clear_outputs.sh # script that deletes the `pdf_outputs/` and `eps_outputs/` folders.
|- create_doc.sh # script that creates the tikz_diagrams.pdf file
|- export_diagrams.sh # script that exports diagrams to PDF and EPS
|- README.md # this file
|- tikz_diagrams.pdf # all TikZ diagrams defined in this project compiled into a single PDF diagrams
./export_diagrams.sh # exports all diagrams in all folders to PDF files
./export_diagrams.sh --eps # exports all diagrams to both PDF and EPS files
./export_diagrams.sh --folder my_folder # exports all diagrams in my_folder to PDF files
./export_diagrams.sh --folder my_folder --eps # exports all diagrams in my_folder to both PDF and EPS files
./export_diagrams.sh --file my_folder/my_file # exports diagram in my_file to a PDF file
./export_diagrams.sh --file my_folder/my_file --eps # exports diagram in my_file to both a PDF and an EPS file
- All PDF files are output to
pdf_outputs
. - All EPS files are output to
eps_outputs
.
-
To generate all diagrams as PDF files, run
./export_diagrams.sh
The PDF files will be saved to
pdf_outputs/
. -
To also generate all diagrams as EPS files, run
./export_diagrams.sh --eps
Like before, the PDF files will be saved to
pdf_outputs/
, while this time we also save EPS files toeps_outputs/
. -
To export only the diagrams in
src/aerospace/
,./export_diagrams.sh --folder aerospace
To also export them as EPS files,
./export_diagrams.sh --folder aerospace --eps
-
To only export the diagram defined by
src/aerospace/cylindrical_eclipse_model.tex
,./export_diagrams.sh --file aerospace/cylindrical_eclipse_model.tex
To also export it as an EPS file,
./export_diagrams.sh --file aerospace/cylindrical_eclipse_model.tex --eps
To compile all TikZ diagrams defined in the src/
folder into a single LaTeX document, run the create_doc.sh
script:
./create_doc.sh # compiles all diagrams currently existing in pdf_outputs/ into a single document
./create_doc.sh --clean # rebuilds all diagrams defined in src/ and compiles them into a single document
This script
- Deletes the existing version of
tikz_diagrams.pdf
. - Deletes the existing
pdf_outputs/
andeps_outputs/
folders and regenerates ALL diagrams if the--clean
option is specified. - Combine all PDF diagrams in the
pdf_outputs/
folder into a single, organized PDF document,tikz_diagrams.pdf
.
To clear all outputs, you can execute the clear_outputs.sh
bash script.
./clear_outputs.sh
This will delete both the pdf_outputs/
and eps_outputs/
folders (if they exist).
% ---------
% Preamble.
% ---------
% Document type.
\documentclass{article}
% Import custom style.
\usepackage{../.preamble/tikz_diagrams_template}
% Color theme (black, red, blue, green, orange, purple, gold).
\colortheme{blue}
% ---------
% Document.
% ---------
\begin{document}
% -----------------
% TikZ environment.
% -----------------
\begin{tikzpicture}
% INSERT YOUR TIKZ CODE HERE
\end{tikzpicture}
\end{document}
Many of the TikZ diagrams are set up to compatible with many color "themes". The choice of color theme is specified in each individual .tex
file in the src/
folder. For example,
% Color theme (black, red, blue, green, orange, purple, gold).
\colortheme{blue}
The choices for the color theme are:
black
red
blue
green
orange
purple
gold
To create a new TikZ diagram that supports the color themes specified above, all you need to do is the following:
-
After any
\usepackage
imports and before\begin{document}
, include\colortheme{insert your color theme choice here}
-
In the code defining your TikZ diagram, the following custom colors are available for your use:
Color Description color_theme
the color specified by the \colortheme{} command in step 1 above shade_color
a shaded (i.e. lighter) version of color_theme
verylightgray
a generic light gray color that is lighter than the built-in lightgray
These colors are all defined in
src/.preamble/tikz_diagrams_template.sty
.As an example, we could draw a circle outlined in blue and shaded with a lighter blue by first specifying the color theme using
\colortheme{blue}
and then in the TikZ environment using
\draw[color_theme,fill=shade_color](0,0)circle(1);
The template for this project is provided by src/.preamble/tikz_diagrams_template.sty
. This style template is imported into every .tex
file in the src/
folder. This style template includes the following additional features beyond "vanilla" TikZ:
Feature | Description/Source | Example |
---|---|---|
3D drawing | tikz-3dplot |
least_squares_derivation_1 |
3D circles | tikz-3dplot-circleofsphere . Note that this package is not available on CTAN, so it is included directly in this project as src/.preamble/third_party/tikz-3dplot-circleofsphere.sty and imported into src/.preamble/tikz_diagrams_template.sty . |
geocentric_right_ascension_and_declination |
rotating coordinate systems using 3-2-1 Euler angles (instead of 3-2-3) | \tdseteulerxyz command defined in src/.preamble/tikz_diagrams_template.sty (see https://tex.stackexchange.com/questions/118069/how-to-draw-an-euler-angle-rotation-sequence-with-tikz) |
airplane_body_frame |
parameterization and function plotting | pgfplots |
continuous_function |
better arrow(head)s | mylatex arrowhead style defined in src/.preamble/tikz_diagrams_template.sty (see https://tex.stackexchange.com/questions/51555/changing-arrowheads-size-in-pgfplots-axes) |
normal_shock |
patterns | TikZ patterns library |
coupled_mass_spring_damper_system |
decorations.marking | TikZ decorations.marking sub-library |
hohmann_transfer |
math characters | amsmath , amsfonts , and mathdots |
bivariate_grid |
other special characters | wasysym |
keplerian_orbital_elements |
circled characters | \circled command defined in src/.preamble/tikz_diagrams_template.sty |
oblique_shock |
While this project aims to be a more bare-bones approach to building basic TikZ diagrams, there is a rich ecosystem out there for building more complicated TikZ diagrams. Check out Awesome TikZ for a fairly comprehensive list of other TikZ libraries.