<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Quick Start
Note
Step1:  Create a simple standalone document.
Step2:  The extension
Step3:  This is annoying sometimes if you want to look for a specific file outside of the notebook. So, you can prefix it, attaching semantical meaning.
Step4:  Of course, writing TikZ files entails lots of tiny tweaks, resulting in a lot of accumulated cruft. For development, you probably want to use your system temp directory to keep your project directory clean.
Step5:  To make it easier to switch from development to production mode, setting the ITIKZ_TEMP_DIR environmental to any value enables --temp-dir.
Step7:  Sometimes, you want to generate a TikZ document from a string, rather than a cell. You can do that using the line magic.
Step8:  Generally, string-generation is bad. One useful thing you can do without it is use an implicit tikzpicture environment.
Step9:  Note that the resulting tex artifact is a full document so you can use it later when writing a tex document.
Step10:  In an --implicit-pic, it's often useful to
Step11:  Sometimes, tikz-based packages don't use tikzpicture environments. To save a few keystrokes, you may want to use an implicit standalone flag. Note
Step12:  To help ensure that your tikz pictures stay aligned with your data -- and, to reduce the need for properly knowing PGF -- you can use jinja2 templates! For example, lets say you had five noes in a DAG, ${A,B,C,D,F}$. You could figure out positioning and such in the notebook, where your brain lives.
Step13:  Then, you can interpret the cell magic source as a jinja2 template.
Step14:  Which also works with the implicit environments.
Step15:  Sometimes, you'll make mistakes. Debugging transpiled code is hard, especially without a mapping. To help, you can print the interpolated source.
Step16:  Finally, its worth noting that jinja templating assumes a jinja2 file loader set in the $CWD. This means you can stick to the DRY principal with blocks and template extension.
Step17:  Sometimes, you may want to send a collaborator a quick snapshot of your work. But, lots of messaging windows won't accept SVG drag-and-drop. As a time saver, you can rasterize the SVG as a PNG (if you have cairosvg installed).
Step18:  Also, the latex command line error messages tend to be...verbose. By default, only the tail is shown.
Step19:  But, if this isn't enough, you can see the whole message.
Step20:  Finally, if you forget the usage, ask for help.
<ASSISTANT_TASK:>
Python Code:
%load_ext itikz
Explanation: Quick Start
Note: If you're viewing this notebook on nbviewer.jupyter.org some of the SVGs render improperly, even across cell output contexts. The bug is not in itikz.
Installation
Install TeX and pdf2svg
This is platform-dependent. 
See:
Texlive
pdf2svg
Install itikz
sh
pip install itikz
Usage
Load itikz. It's a jupter extension.
End of explanation
%%itikz
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=black] (1, 1) rectangle (2, 2);
\draw[fill=black] (2, 1) rectangle (3, 2);
\draw[fill=black] (3, 1) rectangle (4, 2);
\draw[fill=black] (3, 2) rectangle (4, 3);
\draw[fill=black] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
%%itikz
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=black] (1, 1) rectangle (2, 2);
\draw[fill=black] (2, 1) rectangle (3, 2);
\draw[fill=black] (3, 1) rectangle (4, 2);
\draw[fill=black] (3, 2) rectangle (4, 3);
\draw[fill=black] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
Explanation: Create a simple standalone document.
End of explanation
!ls *.svg *.tex
Explanation: The extension:
Writes the cell as a .tex file; 
Runs pdflatex on the source;
Runs pdf2svg on the generated pdf;
Removes the intermediary artifacts.
By default, the filenames are the md5 hash of the source. The extension uses the hash to see if regeneration is necessessary. If it's not, it just loads the SVG file.
End of explanation
%%itikz --file-prefix conway-
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=black] (1, 1) rectangle (2, 2);
\draw[fill=black] (2, 1) rectangle (3, 2);
\draw[fill=black] (3, 1) rectangle (4, 2);
\draw[fill=black] (3, 2) rectangle (4, 3);
\draw[fill=black] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
!ls *.svg *.tex
Explanation: This is annoying sometimes if you want to look for a specific file outside of the notebook. So, you can prefix it, attaching semantical meaning.
End of explanation
!rm -f *.svg *.tex
%%itikz --temp-dir --file-prefix conway-
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=black] (1, 1) rectangle (2, 2);
\draw[fill=black] (2, 1) rectangle (3, 2);
\draw[fill=black] (3, 1) rectangle (4, 2);
\draw[fill=black] (3, 2) rectangle (4, 3);
\draw[fill=black] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
!ls *.svg *.tex
Explanation: Of course, writing TikZ files entails lots of tiny tweaks, resulting in a lot of accumulated cruft. For development, you probably want to use your system temp directory to keep your project directory clean.
End of explanation
import os
os.environ['ITIKZ_TEMP_DIR'] = '1'
%%itikz --file-prefix conway-
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=blue!10] (1, 1) rectangle (2, 2);
\draw[fill=blue!10] (2, 1) rectangle (3, 2);
\draw[fill=blue!10] (3, 1) rectangle (4, 2);
\draw[fill=blue!10] (3, 2) rectangle (4, 3);
\draw[fill=blue!10] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
!ls *.svg *.tex
del os.environ['ITIKZ_TEMP_DIR']
Explanation: To make it easier to switch from development to production mode, setting the ITIKZ_TEMP_DIR environmental to any value enables --temp-dir.
End of explanation
conway_str = r\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[help lines] grid (5, 5);
\draw[fill=magenta] (1, 1) rectangle (2, 2);
\draw[fill=magenta] (2, 1) rectangle (3, 2);
\draw[fill=magenta] (3, 1) rectangle (4, 2);
\draw[fill=magenta] (3, 2) rectangle (4, 3);
\draw[fill=magenta] (2, 3) rectangle (3, 4);
\end{tikzpicture}
\end{document}
%itikz --temp-dir --file-prefix conway- conway_str
Explanation: Sometimes, you want to generate a TikZ document from a string, rather than a cell. You can do that using the line magic.
End of explanation
%%itikz --file-prefix implicit-demo- --implicit-pic 
\draw[help lines] grid (5, 5);
\draw[fill=magenta!10] (1, 1) rectangle (2, 2);
\draw[fill=magenta!10] (2, 1) rectangle (3, 2);
\draw[fill=magenta!10] (3, 1) rectangle (4, 2);
\draw[fill=magenta!10] (3, 2) rectangle (4, 3);
\draw[fill=magenta!10] (2, 3) rectangle (3, 4);
Explanation: Generally, string-generation is bad. One useful thing you can do without it is use an implicit tikzpicture environment.
End of explanation
!cat implicit-demo-a6fdb3ecbc22048b7f090c20b5039b38.tex
!rm implicit-demo*
Explanation: Note that the resulting tex artifact is a full document so you can use it later when writing a tex document.
End of explanation
%%itikz --temp-dir --implicit-pic --tikz-libraries=quotes,angles --tex-packages=amsfonts --scale=2
% Example from Paul Gaborit
% http://www.texample.net/tikz/examples/angles-quotes/
\draw
    (3,-1) coordinate (a) node[right] {a}
    -- (0,0) coordinate (b) node[left] {b}
    -- (2,2) coordinate (c) node[above right] {c}
    pic["$\alpha$", draw=orange, <->, angle eccentricity=1.2, angle radius=1cm]
    {angle=a--b--c};
    
\node[rotate=10] (r) at (2.5, 0.65) {Something about in $\mathbb{R}^2$};
Explanation: In an --implicit-pic, it's often useful to:
Set the \tikzpicture[scale=X] via --scale=&lt;X&gt; while iterating.
Set the \usepackage{X,Y,Z} via --tex-packages=&lt;X,Y,Z&gt;
Set the \usetizlibrary{X,Y,Z} via --tiz-libraries=&lt;X,Y,Z&gt;
End of explanation
%%itikz --temp-dir --implicit-standalone --tex-packages=smartdiagram,amsfonts
\smartdiagramset{uniform sequence color=true,
sequence item border color=black,
sequence item font size=\footnotesize,
sequence item text color=white
}
\smartdiagram[sequence diagram]{
    $\mathbb{N}$,
    $\mathbb{Z}$,
    $\mathbb{Q}$,
    $\mathbb{R}$,
    $\mathbb{I}$,
    $\mathbb{C}$
}
Explanation: Sometimes, tikz-based packages don't use tikzpicture environments. To save a few keystrokes, you may want to use an implicit standalone flag. Note: You have to use --tex-packages=tikz in this environment if you need tikz itself!
End of explanation
node_names = "ABCDEF"
nodes = {s: int(365/len(node_names) * i) for i, s in enumerate(node_names)}
n = len(nodes)
nodes
Explanation: To help ensure that your tikz pictures stay aligned with your data -- and, to reduce the need for properly knowing PGF -- you can use jinja2 templates! For example, lets say you had five noes in a DAG, ${A,B,C,D,F}$. You could figure out positioning and such in the notebook, where your brain lives.
End of explanation
%%itikz --as-jinja --temp-dir
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,automata}
\definecolor{mymagenta}{RGB}{226,0,116}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                    semithick]
  \tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
  
  {% for name, angle in nodes.items() -%}
       \node[color=mymagenta] (v{{loop.index0}}) at ({{angle}}:1) {${{name}}$};
  {% endfor -%}
  
  {% for n1 in range(n) -%}
      {% for n2 in range(n) -%}
         {%if n1 < n2 -%}
             \path (v{{n1}}) edge (v{{n2}});
         {% endif -%}
      {% endfor -%}
  {% endfor -%}
\end{tikzpicture}
\end{document}
Explanation: Then, you can interpret the cell magic source as a jinja2 template.
End of explanation
%%itikz --as-jinja --temp-dir --tex-packages=tikz --tikz-libraries=arrows,automata --implicit-standalone
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                    semithick]
  \tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
  
  {% for name, angle in nodes.items() -%}
       \node[color=red] (v{{loop.index0}}) at ({{angle}}:1) {${{name}}$};
  {% endfor -%}
  
  {% for n1 in range(n) -%}
      {% for n2 in range(n) -%}
         {%if n1 < n2 -%}
             \path (v{{n1}}) edge (v{{n2}});
         {% endif -%}
      {% endfor -%}
  {% endfor -%}
\end{tikzpicture}
Explanation: Which also works with the implicit environments.
End of explanation
%%itikz --as-jinja --print-jinja --temp-dir --as-jinja --tex-packages=tikz --tikz-libraries=arrows,automata --implicit-standalone
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                    semithick]
  \tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
  
  {% for name, angle in nodes.items() -%}
       \node[color=red] (v{{loop.index0}}) at ({{angle}}:1) {${{name}}$};
  {% endfor -%}
  
  {% for n1 in range(n) -%}
      {% for n2 in range(n) -%}
         {%if n1 < n2 -%}
             \path (v{{n1}}) edge (v{{n2}});
         {% endif -%}
      {% endfor -%}
  {% endfor %}
\end{tikzpicture}
Explanation: Sometimes, you'll make mistakes. Debugging transpiled code is hard, especially without a mapping. To help, you can print the interpolated source.
End of explanation
%%writefile dag_demo.tex
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,automata}
\definecolor{mymagenta}{RGB}{226,0,116}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                    semithick]
  \tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
  
{% block content %}
{% endblock %}
\end{tikzpicture}
\end{document}
!ls dag_demo.tex
%%itikz --as-jinja --temp-dir
{% extends "dag_demo.tex" %}
{% block content %}
{% for name, angle in nodes.items() %}
       \node[color=mymagenta] (v{{loop.index0}}) at ({{angle}}:1) {${{name}}$};
{% endfor -%}
  
{% for n1 in range(n) %}
    {% for n2 in range(n) %}
        {%if n1 < n2 %}
            \path (v{{n1}}) edge (v{{n2}});
        {% endif %}
    {% endfor -%}
{% endfor %}
{% endblock %}
!rm dag_demo.tex # ignore this, it's just housekeeping
Explanation: Finally, its worth noting that jinja templating assumes a jinja2 file loader set in the $CWD. This means you can stick to the DRY principal with blocks and template extension.
End of explanation
%%itikz --implicit-pic --temp-dir --rasterize
\draw[fill=black] (1, 1) rectangle (2, 2);
\draw[fill=black] (2, 1) rectangle (3, 2);
\draw[fill=black] (3, 1) rectangle (4, 2);
\draw[fill=black] (3, 2) rectangle (4, 3);
\draw[fill=black] (2, 3) rectangle (3, 4);
Explanation: Sometimes, you may want to send a collaborator a quick snapshot of your work. But, lots of messaging windows won't accept SVG drag-and-drop. As a time saver, you can rasterize the SVG as a PNG (if you have cairosvg installed).
End of explanation
%%itikz --implicit-pic
4$
Explanation: Also, the latex command line error messages tend to be...verbose. By default, only the tail is shown.
End of explanation
%%itikz --implicit-pic --full-error
4$
Explanation: But, if this isn't enough, you can see the whole message.
End of explanation
%itikz -h
Explanation: Finally, if you forget the usage, ask for help.
End of explanation
<END_TASK>