Skip to content

Commit

Permalink
Docs: Fixed jinja whitecontrol
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslrodri committed Aug 10, 2024
1 parent 11be3e3 commit 4fb0935
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
35 changes: 16 additions & 19 deletions docs/usage/as-magic.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ conway_str = r"""\documentclass[tikz]{standalone}

To help ensure that TikZ Pictures stay aligned with your data, you can use [Jinja2 templates](https://jinja.palletsprojects.com/en/latest/templates/).

!!! tip
Since [version 0.5](https://jupyter-tikz.readthedocs.io/stable/about/changelog/), Jinja2 templates are enabled by default, so it's no longer necessary to use the `-j` flag. The `jinja2` package is automatically installed during the installation of `jupyter_tikz`.

First, we need to populate some data:

```python
Expand All @@ -678,15 +681,9 @@ Since [version 0.5](https://jupyter-tikz.readthedocs.io/stable/about/changelog/)
| `{% raw %}{% logic/block %}{% endraw %}` | `(** logic/block **)` | `(** for n1 in range(n) **)` |
| `{% raw %}{# comment #}{% endraw %}` | `(~ comment ~)` | `(~ This won’t render ~)` |



!!! tip
Since [version 0.5](https://jupyter-tikz.readthedocs.io/stable/about/changelog/), Jinja2 templates are enabled by default, so it's no longer necessary to use the `-j` flag. The `jinja2` package is automatically installed during the installation of `jupyter_tikz`.


```latex
%%tikz -l=arrows,automata -sc=2
{% raw %}
{%- raw %}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]
\tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
Expand All @@ -703,7 +700,7 @@ Since [version 0.5](https://jupyter-tikz.readthedocs.io/stable/about/changelog/)
(** endfor **)
(** endfor **)
\end{tikzpicture}
{% endraw %}
{% endraw -%}
```

<div class="result" markdown>
Expand All @@ -714,7 +711,7 @@ It also works for full documents and implicit pictures:

```latex
%%tikz -as=f -r -d=200
{% raw %}
{%- raw %}
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,automata}
\definecolor{mymagenta}{RGB}{226,0,116}
Expand All @@ -736,7 +733,7 @@ It also works for full documents and implicit pictures:
(** endfor **)
\end{tikzpicture}
\end{document}
{% endraw %}
{% endraw -%}
```
<div class="result" markdown>
![Using Jinja - Full latex](../assets/tikz/jinja_full.png)
Expand All @@ -754,7 +751,7 @@ Sometimes, you'll make mistakes. Debugging transpiled code is challenging, espec

```latex
%%tikz -pj -l=arrows,automata -sc=2 --save-tex=outputs/jinja_rendered.tikz
{% raw %}
{%- raw %}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]
\tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
Expand All @@ -771,7 +768,7 @@ Sometimes, you'll make mistakes. Debugging transpiled code is challenging, espec
(** endfor -**)
(** endfor **)
\end{tikzpicture}
{% endraw %}
{% endraw -%}
```

<div class="result" style="padding-right: 0;" markdown>
Expand Down Expand Up @@ -843,13 +840,13 @@ In this example, we are going to save the code in the variable `my_frame`:
Now, we can reuse the variable in the code with Jinja:

```latex
%%tikz -as=t --use-jinja
{% raw %}
%%tikz -as=t
{%- raw %}
\begin{tikzpicture}[scale=3]
(* my_frame -*) % This is my_frame that I rendered before
\filldraw (0.5,0.5) circle (.1);
\end{tikzpicture}
{% endraw %}
{% endraw -%}
```

<div class="result" markdown>
Expand All @@ -862,11 +859,11 @@ You can also combine `-sv` with Jinja blocks:

```latex
%%tikz -as=t -sv=node_names -sc=2
{% raw %}
{%- raw %}
(** for name, angle in nodes.items() -**)
\node[color=red] (v(* loop.index0 *)) at((* angle *):1) {$(* name *)$};
(** endfor -**)
{% endraw %}
{% endraw -%}
```
<div class="result" markdown>
![sv + jinja](../assets/tikz/node_name_sv_j.svg)
Expand All @@ -886,7 +883,7 @@ Now, incorporate it into another `tikzpicture`:

```latex
%%tikz -l=arrows,automata -sc=2
{% raw %}
{%- raw %}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm, semithick]
\tikzstyle{every state}=[fill=mymagenta,draw=none,text=white]
Expand All @@ -900,7 +897,7 @@ Now, incorporate it into another `tikzpicture`:
(** endfor **)
(** endfor **)
\end{tikzpicture}
{% endraw %}
{% endraw -%}
```

<div class="result" markdown>
Expand Down
2 changes: 1 addition & 1 deletion notebooks/GettingStarted.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2959,7 +2959,7 @@
}
],
"source": [
"%%tikz -as=t \n",
"%%tikz -as=t\n",
"\\begin{tikzpicture}[scale=3]\n",
" (* my_frame -*) % This is my_frame that I rendered before\n",
" \\filldraw (0.5,0.5) circle (.1);\n",
Expand Down

0 comments on commit 4fb0935

Please sign in to comment.