Commits

Antonio Alvarado Hernández committed f0d65b3

Added some LaTeX examples using TikZ

These codes include examples of:

* creating an IS-LM model plot
* creating a railroad syntax diagram
* using TikZ inside a Pandoc's Markdown document

Comments (0)

Files changed (5)

LaTeX/TikZ/HelloTikZ.cmd

+@pandoc --include-in-header=HelloTikZ.pinc --latex-engine=lualatex -Sso HelloTikZ.pdf HelloTikZ.md

LaTeX/TikZ/HelloTikZ.md

+% An example document combining Pandoc and TikZ
+% Antonio Alvarado Hernández
+% \today
+
+Heading 1
+=========
+
+The __TikZ__ code could be located just here...
+
+\begin{figure}[htbp]
+\centering
+\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
+\tikzstyle{init}=[pin edge={to-,thin,black}]
+\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
+    \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
+    \node (b) [left of=a,node distance=2cm, coordinate] {a};
+    \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
+    \node [coordinate] (end) [right of=c, node distance=2cm]{};
+    \path[->] (b) edge node {$a$} (a);
+    \path[->] (a) edge node {$v$} (c);
+    \draw[->] (c) edge node {$p$} (end) ;
+\end{tikzpicture}
+\caption{Hello, world! This is my first embedded TikZ code}
+\end{figure}
+
+... and then, it returns right here!

LaTeX/TikZ/HelloTikZ.pinc

+% this \LaTeX code initializes the TikZ package
+
+\usepackage{tikz}
+\usetikzlibrary{arrows}
+
+% EOF

LaTeX/TikZ/is-lm.tex

+% IS-LM diagram
+% Author: Rasmus Pank Roulund
+% Retrieved from: http://www.texample.net/tikz/examples/is-lm-diagram/
+% Retrieved at: 2013-05-06
+\documentclass{minimal}
+\usepackage{tikz}
+\usetikzlibrary{arrows,calc}
+\usepackage{relsize}
+\newcommand\LM{\ensuremath{\mathit{LM}}}
+\newcommand\IS{\ensuremath{\mathit{IS}}}
+\begin{document}
+
+\begin{tikzpicture}[
+        scale=2,
+        IS/.style={blue, thick},
+        LM/.style={red, thick},
+        axis/.style={very thick, ->, >=stealth', line join=miter},
+        important line/.style={thick}, dashed line/.style={dashed, thin},
+        every node/.style={color=black},
+        dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,
+            outer sep=-1pt},
+    ]
+    % axis
+    \draw[axis,<->] (2.5,0) node(xline)[right] {$Y$} -|
+                    (0,2.5) node(yline)[above] {$i$};
+    % IS-LM diagram
+    \draw[LM] (0.2,0.3) coordinate (LM_1) parabola (1.8,1.8)
+        coordinate (LM_2) node[above] {\LM};
+    \draw[IS] (0.2,1.8) coordinate (IS_1) parabola[bend at end]
+         (1.8,.3) coordinate (IS_2) node[right] {\IS};
+    %Intersection is calculated "manually" since Tikz does not offer
+    %intersection calculation for parabolas
+    \node[dot,label=above:$A$] at (1,.68) (int1) {};
+    %shifted IS-LM diagram
+    \draw[xshift=.7cm, LM, red!52] (0.2,0.2) parabola (1.8,1.7)
+        node[above] {\LM'};
+    \draw[xshift=.4cm, yshift=.3cm, IS, blue!60] (0.2,1.8)
+        parabola[bend at end] (1.8,.3)
+        node[right] {\IS'};
+    %Intersection of shifted IS-LM
+    \path[xshift=.36cm, yshift=.35cm] (.98,.7)
+        node[dot,label=above:{$B$}] (int2) {};
+    \path[xshift=.805cm] (1,.68) node[dot,label=above:$C$] (int3) {};
+    %arrows between intersections
+    \draw[->, very thick, black, >=stealth']
+        ($(int1)+1/2*(-.80,1)$) -- ($(int2)+1/2*(-.8,1)$)
+        node[sloped, above, midway] {$\mathsmaller{\Delta G > 0}$};
+    \draw[->, very thick, black, >=stealth']
+        ($(int2)+2*(.14,.2)$) -- ($(int2)!.2cm!270:(int2)+(.9,0)$)
+        node[sloped,above, midway] {$\mathsmaller{\Delta M>0}$};
+
+    \begin{scope}[xshift=4cm]
+        %E-diagram
+        \draw[axis,<->] (0,2.5) node(eyline)[above] {$i$} |-
+                        (2.5,0) node(exline)[right] {$E$};
+
+        \draw[important line, green, xshift=.5cm]
+            (.2,.2) coordinate (es) -- (1.5,1.5) coordinate (ee)
+            node [above right] {Interest rate parity};
+    \end{scope}
+    %Lines connecting IS LM coordinates and E coordinates
+    \draw[dashed]
+        let
+            % Store the intersection point in \p1 for later retrieval.
+            % A convenient feature of the let operation is that we can
+            % access the x and y component of the coordinate directly
+            % using the \x1 and \y1 syntax.
+            \p1=(intersection of int2--[xshift=1]int2 and es--ee)
+        in
+            (0,\y1) node[left]{$i'$} -|  (\x1,0)
+            node[pos=0.5,dot,label=above:$B'$] {} node[below] {$E'$};
+
+    \draw[dashed line] let
+        \p1=(intersection of int3--[xshift=1]int3 and es--ee)
+            in
+        (0,\y1) node[left]{$i\phantom{'}$} -| (\x1,0)
+        node[dot,label=above:$C'$,pos=0.5] {} node[below] {$E$};
+
+\end{tikzpicture}
+\end{document}
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:

LaTeX/TikZ/syntax-diagram.tex

+% Mobile ad-hoc network
+% Author: Dr. Ludger Humbert
+% Source: https://haspe.homeip.net/projekte/ddi/browser/tex/pgf2
+% https://haspe.homeip.net/projekte/ddi/browser/tex/pgf2/Python_if-then-elif-else.tex $:
+% Retrieved from: http://www.texample.net/tikz/examples/python-if-then-else-syntax-diagram/
+% Retrieved at: 2013-05-06
+
+\documentclass{article}
+\usepackage[ngerman]{babel}
+
+\usepackage{tikz}
+\usepackage{verbatim}
+
+\begin{comment}
+:Title: Python if-then-else syntax diagram
+
+A `syntax diagram`_ (or railroad diagram) for a if-then-elif-else expression in Python.
+
+.. _syntax diagram: http://en.wikipedia.org/wiki/Syntax_diagram
+
+:Author: Dr. `Ludger Humbert`_
+:Source: `https://haspe.homeip.net/projekte/ddi/browser/tex/pgf2`__
+
+.. __: https://haspe.homeip.net/projekte/ddi/browser/tex/pgf2
+.. _Ludger Humbert: https://haspe.homeip.net/cgi-bin/pyblosxom.cgi
+
+\end{comment}
+\usepackage{xxcolor}
+
+
+\usetikzlibrary{chains,matrix,scopes,decorations.shapes,arrows,shapes}
+
+% fuer Railroad-Diagramme
+\tikzset{
+  nonterminal/.style={
+    % The shape:
+    rectangle,
+    % The size:
+    minimum size=6mm,
+    % The border:
+    very thick,
+    draw=red!50!black!50,         % 50% red and 50% black,
+                                  % and that mixed with 50% white
+    % The filling:
+    top color=white,              % a shading that is white at the top...
+    bottom color=red!50!black!20, % and something else at the bottom
+    % Font
+    font=\itshape
+  },
+  terminal/.style={
+    % The shape:
+    rounded rectangle,
+    minimum size=6mm,
+    % The rest
+    very thick,draw=black!50,
+    top color=white,bottom color=black!20,
+    font=\ttfamily},
+  skip loop/.style={to path={-- ++(0,#1) -| (\tikztotarget)}}
+}
+{
+  \tikzset{terminal/.append style={text height=1.5ex,text depth=.25ex}}
+  \tikzset{nonterminal/.append style={text height=1.5ex,text depth=.25ex}}
+}
+
+
+\renewcommand\familydefault{\sfdefault}
+
+\listfiles
+
+\begin{document}
+
+
+%% if_stmt ::= "if" expression ":" suite
+%%                ( "elif" expression ":" suite )*
+%%                ["else" ":" suite]
+%%
+\hspace{-35ex}
+\begin{tikzpicture}[point/.style={coordinate},>=stealth',thick,draw=black!50,
+                    tip/.style={->,shorten >=0.007pt},every join/.style={rounded corners},
+                    hv path/.style={to path={-| (\tikztotarget)}},
+                    vh path/.style={to path={|- (\tikztotarget)}},
+                    text height=1.5ex,text depth=.25ex]     % um die Hoehe des Punktes festzuzurren
+  \matrix[ampersand replacement=\&,column sep=4mm] {
+    \node (p1)  [point]  {}; \&    \node (ifs)    [terminal]     {if};             \&
+    \node (p2)  [point]  {}; \&    \node (expr1)  [nonterminal]  {expr};           \&
+    \node (p3)  [point]  {}; \&    \node (colon1) [terminal]     {:};              \&
+    \node (p4)  [point]  {}; \&    \node (suite1) [nonterminal]  {suite};          \&
+    \node (p5)  [point]  {}; \&    \node (p6)     [point]  {};                     \&
+    \node (p6a) [point]  {}; \&    \node (p6b)    [point]  {};                     \&
+    \node (p7)  [point]  {}; \&    \node (elif)   [terminal]     {elif};           \&
+    \node (p8)  [point]  {}; \&    \node (expr2)  [nonterminal]  {expr};           \&
+    \node (p9)  [point]  {}; \&    \node (colon2) [terminal]     {:};              \&
+    \node (p10) [point]  {}; \&    \node (suite2) [nonterminal]  {suite};          \&
+    \node (p11) [point]  {}; \&    \node (p12)    [point]  {};                     \&
+    \node (p12a)[point]  {}; \&    \node (p12b)   [point]  {};                     \&
+    \node (p13) [point]  {}; \&    \node (else)   [terminal]     {else};           \&
+    \node (p14) [point]  {}; \&    \node (colon3) [terminal]     {:};              \&
+    \node (p15) [point]  {}; \&    \node (suite3) [nonterminal]  {suite};          \&
+    \node (p16) [point]  {}; \&    \node (p17)    [point]       {};\\
+  };
+
+  { [start chain]
+    \chainin (p1);
+    \chainin (ifs)    [join=by tip];
+    \chainin (p2)     [join];
+    \chainin (expr1)  [join=by tip];
+    \chainin (p3)     [join];
+    \chainin (colon1) [join=by tip];
+    \chainin (p4)     [join];
+    \chainin (suite1) [join=by tip];
+    \chainin (p7)     [join];
+    \chainin (elif)   [join=by tip];
+    \chainin (p8)     [join];
+    \chainin (expr2)  [join=by tip];
+    \chainin (p9)     [join];
+    \chainin (colon2) [join=by tip];
+    \chainin (p10)    [join];
+    \chainin (suite2) [join=by tip];
+    \chainin (p12a)   [join,join=with p6 by {skip loop=-11mm,tip}];
+    \chainin (p13)    [join];
+    \chainin (else)   [join=by tip];
+    \chainin (p14)    [join];
+    \chainin (colon3) [join=by tip];
+    \chainin (p15)    [join];
+    \chainin (suite3) [join=by tip];
+    \chainin (p16)    [join];
+    \chainin (p17)    [join=by tip];
+    \chainin (p16)    [join,join=with p12b by {skip loop=-11mm,tip}];
+    \chainin (p6b)    [join=with p11 by {skip loop=11mm,tip}];
+  }
+\end{tikzpicture}
+
+
+
+\end{document}
+