%!TEX root = tzplot-doc.tex
%\begin{document}

%%%==================================
\part{Getting Started}
%%%==================================
\label{p:gettingstarted}

%%==================================
\chapter{An Intuitive Introduction I: Basics}
\label{ci:introI}

All drawing macros provided in this package work within |tikzpicture| environment, just like any other \Tikz\ commands.

%%------------------------------------------------------------
\section{Lines: Basics: \protect\cmd{\tzline(0,0)(3,1)}}
\label{si:lines}

To draw a line from $(0,0)$ to $(3,1)$, just do |\tzline(0,0)(3,1)|.

\begin{tzcode}{.3}
% \tzline
\begin{tikzpicture}
\tzhelplines(4,2)
\tzline(0,0)(3,1)
\end{tikzpicture}
\end{tzcode}

You can use \Tikz\ options to change the style of a line.

\begin{tzcode}{.3}
% \tzline: change line style
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline(0,0)(3,1)
\tzline[dashed](0,1)(3,2)
\tzline[->,blue,thick](0,3)(4,1)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzline[dashed](0,1)(3,2) % works like:
 \draw [dashed] (0,1) -- (3,2);
\end{tztikz}


%%------------------------------------------------------------
\section{Dots: Basics}
\label{si:dots}

\subsection{A circle dot: \protect\cmd{\tzcdot(0,0)}}
\label{ssi:tzcdot}

\icmd{\tzcdot}|(0,0)| prints a `circle dot' \tikz \tzcdot(0,0);, with the \xem{radius} |1.2pt| by default, at the point |(0,0)|. The starred version \icmd{\tzcdot*} prints a filled dot \tikz \tzcdot*(0,0);.

\begin{tzcode}{.3}
% \tzcdot: circle dot
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcdot(0,0)
\tzcdot*(3,1)
\tzcdot [red]  (0,1)(3pt) % radius=3pt
\tzcdot*[green](3,2)(3pt) % radius=3pt
\end{tikzpicture}
\end{tzcode}

You can change of the size of a dot by specifying the \xem{radius} of the circle, like, for example, |\tzcdot(0,0)(3pt)|.

\begin{tztikz}
\tzcdot*[green](3,2)(3pt) % is an abbreviation for:
 \draw [fill,green] (3,2) circle (3pt);
\end{tztikz}

\begin{tzcode}{.3}
% \tzcdot
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcdot(0,0)              \tzcdot*(3,1)
\tzcdot[red](0,1)(2mm)    % radius=2mm
\tzcdot*[green](3,2)(3pt) % radius=3pt
\tzline(0,0)(3,1)
\tzline(0,1)(3,2)
\end{tikzpicture}
\end{tzcode}


\subsection{A circle node dot: \protect\cmd{\tzdot(0,0)}}
\label{ssi:tzdot}

\icmd{\tzdot} draws a `circle node dot' at a specified coordinate.
The starred version \icmd{\tzdot*} prints a filled dot. The default size (\xem{diameter} or |minimum size|) is |2.4pt|.

\begin{tzcode}{.3}
% \tzdot: node dot
\begin{tikzpicture}
\tzhelplines(4,3)
\tzdot(0,0)               \tzdot*(3,1)
\tzdot[red](0,1)(4mm)     % minimum size=4mm
\tzdot*[green](3,2)(6pt)  % minimum size=6pt
\tzline(0,0)(3,1)
\tzline(0,1)(3,2)
\end{tikzpicture}
\end{tzcode}


The size (\xem{diameter} or |minimum size|) of a node dot can be changed by the second (or the last) parenthesis option, like |(6pt)|.

\begin{tzcode}{.3}
% \tzcdot
\begin{tikzpicture}
\tzhelplines(4,3)
\tzdot(0,0)(5pt)         \tzdot*(3,1)
\tzdot[red](0,1)(4mm)    \tzdot*[green](3,2)(6pt)
\tzline(0,0)(3,1)
\tzline(0,1)(3,2)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzdot[green](0,0)(6pt) % works like:
 \draw [green] (0,0) node [tzdot,minimum size=6pt] {};
 % tzdot style is predefined
\end{tztikz}


\subsection{Difference between \protect\cmd{\tzcdot} and \protect\cmd{\tzdot}}
\label{ssi:difference}

A `circle dot' drawn by |\tzcdot| is affected by |xscale| or |yscale| in \Tikz, but a `circle node dot' drawn by |\tzdot| is not.
Note also that |\tzcdot| controls the \xem{radius} of a circle dot (following \Tikz\ practice), while |\tzdot| controls the \xem{diameter} of a circle node dot.

\begin{tzcode}{.3}
% \tzdot: size not changed by scaling
\begin{tikzpicture}[xscale=.5,yscale=1.1] %%
\tzhelplines(4,3)
\tzdot(0,0)              \tzdot*(3,1)
\tzdot[red](0,1)(4mm)    \tzdot*[green](3,2)(6pt)
\tzline(0,0)(3,1)
\tzline(0,1)(3,2)
\end{tikzpicture}
\end{tzcode}


\remark
The circle dots drawn by |\tzcdot| are affected by \Tikz\ |scale| factors. It gets bigger or smaller by |scale|.
Let us see what happens to circle dots, especially when |xscale| and |yscale| are not symmetric.

\begin{tzcode}{.3}
% \tzcdot: distorted
\begin{tikzpicture}[xscale=.5,yscale=1.1] %%
\tzhelplines(4,3)
\tzcdot(0,0)              \tzcdot*(3,1)
\tzcdot[red](0,1)(2mm)    \tzcdot*[green](3,2)(3pt)
\tzline(0,0)(3,1)
\tzline(0,1)(3,2)
\end{tikzpicture}
\end{tzcode}




%%------------------------------------------------------------
\section{Coordinates: Basics: \protect\cmd{\tzcoor(0,0)(A)}}
\label{si:coordinates}

To define a coordinate, use \icmd{\tzcoor} with a coordinate followed by its name in parentheses.

\begin{tztikz}
\tzcoor(0,0)(A) % works like:
 \path (0,0) coordinate (A);
 % or
 \coordinate (A) at (0,0);
\end{tztikz}

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoor(0,0)(A)      \tzcoor(60:3cm)(B)
\tzline[->](A)(B)
\tzdot(A)(5pt)
\tzcoor(0,1)(C)      \tzcoor(4,2)(D)
\tzline[dashed](C)(D)
\end{tikzpicture}
\end{tzcode}

The starred version \icmd{\tzcoor*} prints a filled node dot at a specified coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoor(0,0)(A)      \tzcoor(60:3cm)(B)
\tzline[->](A)(B)
\tzdot(A)(5pt)
\tzcoor*(0,1)(C)     \tzcoor*[fill=none](4,2)(D)
\tzline[dashed](C)(D)
\end{tikzpicture}
\end{tzcode}

%%------------------------------------------------------------
\section{Curves: Basics}
\label{si:curves}

\subsection{\protect\cmd{\tzto(0,0)(4,2)}}
\label{ssi:tzto}

\icmd{\tzto} connects two points with a line or a curve using the |to| operation of \Tikz.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzto(0,0)(4,2)
\tzto[bend right,dashed](0,1)(3,2)
\tzto[out=90,in=-90,->,blue](0,2)(4,1)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzto[bend right](0,1)(3,2) % works like:
 \draw [bend right] (0,1) to (3,2);
\end{tztikz}

\subsection{\protect\cmd{\tzbezier}}
\label{ssi:tzbezier}

\icmd{\tzbezier} draws a B\'{e}zier curve with \xem{one or two} control points from the first coordinate to the last coordinate.
The style |tzshowcontrols| predefined in the package reveals the control point(s).

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzbezier[blue,thick](0,0)(2,0)(4,2)
\tzbezier[->,tzshowcontrols](0,2)(1,3)(3,0)(4,1)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzbezier[blue](0,0)(2,0)(4,2)        % works like:
 \draw [blue] (0,0) .. controls (2,0) .. (4,2);
\tzbezier(0,2)(1,3)(3,0)(4,1)         % works like:
 \draw (0,2) .. controls (1,3) and (3,0) .. (4,1);
\end{tztikz}

\subsection{\protect\cmd{\tzparabola}}
\label{ssi:tzparabola}

\icmd{\tzparabola} draws a parabola controlled by several options of \Tikz's |parabola| operation.
The macro \icmd{\tzparabola} accepts \xem{two or three} coordinate arguments to draw a parabola and the parabola bends at the second coordinate if it exists.

\begin{tztikz}
\tzparabola(0,0)(2,4)      % works like:
 \draw (0,0) parabola (2,4);
\tzparabola(2,0)(3,3)(4,1) % works like:
 \draw (2,0) parabola bend (3,3) (4,1);
\end{tztikz}


\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,4)
\tzparabola(0,0)(2,4)
\tzparabola[bend at end,dashed](0,0)(2,4)
\tzparabola(2,0)(3,3)(4,1)
\tzparabola[bend pos=.33,dashed](1,0)(4,4)
\end{tikzpicture}
\end{tzcode}





%%------------------------------------------------------------
\section{Adding text: Nodes and placement}
\label{si:addingtext}

\subsection{\protect\cmd{\tznode(3,1)\{text\}[right]}}
\label{ssi:tznode}

With \icmd{\tznode}|(<coor>){<text>}[<node opt>]|, you can put some text at a specified position.
The starred version \icmd{\tznode*} draws the node perimeter, which is a |rectangle| by default.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tznode(0,0){A}
\tznode*(1,1){text}
\tzdot*(2,2)
\tznode(2,2){Text}[above right,blue]
\end{tikzpicture}
\end{tzcode}


\begin{tztikz}
\tznode(0,0){A}                       % works like:
 \node at (0,0) {A};
\tznode(2,2){Text}[above right,blue]  % works like:
 \draw (2,2) node [above right,blue] {Text};
\end{tztikz}

\subsection{Review: Main nodes and label nodes in \Tikz}
\label{ssi:mainnodes}

In \Tikz, there are two kinds of nodes: main nodes and label nodes.

When a \iisw{main node} with text in it is placed at a specific point, its \iisw{label node} with a label in it is optionally placed in the \xem{direction} of a designated \xem{angle} relative to the main node.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tznode*(2,1){main node}
      [scale=2,label={[draw,red]90:label node}]
\tznode*(3,3){A}[label={above:a},label={0:r}]
\end{tikzpicture}
\end{tzcode}

Instead of angles, you can use the corresponding placement words. In \Tikz, for example, |above| is replaced by |90| degree, |right| by |0| degree, |below left| by |-135| degree, and the like. Note that the angle expression \xem{cannot} be used for placing main nodes.

\xmedskip1
\remark
\begin{itemize}
\item
In this package, macros related to `dots' or `coordinates' (like |\tzcdot|, |tzdot|, and |\tzcoor|) can optionally have `label nodes,' while macros related to `lines' and `curves' (like |\tzline|, |\tzto|, |\tzbezier| and |\tzparabola|) optionally have `main nodes' or `text nodes.'
\item
There is one exception: |\tzshoworigin|. |\tzshoworigin| can have a label, but its location is controlled by positional words such as |below left| but not by |<angle>|.
(See Section \ref{s:tzshoworigin} on page \pageref{s:tzshoworigin} for more details.)
\end{itemize}

\subsection{Abbreviations of \Tikz\ basic placement option styles: \texttt{a}, \texttt{r}, \texttt{ar}, \texttt{bl}, etc.}
\label{ssi:abbreviations}

You can use \isw{abbreviations} (or aliases) |a| for |above|, |c| for |centered|, |r| for |right|, |bl| for |below left|, and so on to place \iisw{main node}\xem{s}.
(Again, you \xem{cannot} use angels to place main nodes.)

\begin{tzcode}{.3}
\begin{tikzpicture}[font=\ttfamily,text=blue]
\tzhelplines[thick](2,2)
\tznode(1,1){centered}[draw]  % default: centered
\tznode(1,2){a} [a]    \tznode(1,0){b} [b]
\tznode(0,1){l} [l]    \tznode(2,1){r} [r]
\tznode(0,2){al}[al]   \tznode(2,2){ar}[ar]
\tznode(0,0){bl}[bl]   \tznode(2,0){br}[br]
\end{tikzpicture}
\end{tzcode}

%%------------------------------------------------------------
\section{Labeling dots and coordinates}
\label{si:labelingdots}

\subsection{\protect\cmd{\tzdot}, \protect\cmd{\tzcdot}}
\label{ssi:labeling:tzdot}

To add a label to a dot generated by |\tzdot| or |\tzcdot|, you should specify, \xem{right after a coordinate}, |{<label>}| followed by |[<angle>]| (|90| degree or |above| by default in \Tikz).

\textsc{Remember} that the order of the arguments is |(<coor>){<label>}[<angle>]|.
To change the size of a dot, you need to specify the last option |(<dimension>)| after all the other arguments.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzdot*(1,1){A}  % default: 90 or above
\tzdot(2,1){B}[0](4pt)
\tzcdot*(1,2){C}[180](2pt)
\tzcdot(3,2){D}[45]
\tzdot*(4,0){E}[[red,draw]180](4pt)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzcdot*(1,2){C}[180](2pt) % works like:
 \draw[fill] (1,2) circle (2pt) node [label={180:C}] {};
\end{tztikz}

\subsection{\protect\cmd{\tzcoor}}
\label{ssi:tzcoor}

\icmd{\tzcoor} can add a label to a coordinate. Just append the optional arguments |{<label>}| and |[<angle>]| after the two mandatory parenthesis arguments.

\remark
\textsc{Remember} the order of arguments is |(<coor>)(<name>){<label>}[<angle>]|.

\begin{tzdef}
% syntax: simplified
\tzcoor(<coor>)(<coor name>){<label>}[[<label opt>]<angle>]
% defaults
 (<m>)(<m>){}[]
% <m> means `mandatory'
\end{tzdef}

You can see the full syntax of |\tzcoor| in Section \ref{s:tzcoor} on page \pageref{s:tzcoor}.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,2)
\tzcoor(1,1)(A){A}  % default: 90 or above
\tzcoor(2,1)(B){B}[[red]0]
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzcoor(1,1)(B){B}[0]  % works like:
 \draw (1,1) coordinate (B) node [label={0:B}] {};
\tzcoor(1,1)(B){B}[[red]0]  % works like:
 \draw (1,1) coordinate (B) node [label={[red]0:B}] {};
\end{tztikz}

\subsection{\protect\cmd{\tzcoor*}}
\label{ssi:tzcoor*}

The starred version \icmd{\tzcoor*} designates a coordinate and prints a node dot with a label around the designated point like |\tzdot*| does.

\begin{tzdef}
% syntax: simflified
\tzcoor*[<dot opt>](<coor>)(<coor name>){<label>}[[<label opt>]<angle>](<dot size>)
\end{tzdef}

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoor(1,1)(A){A}  % default: 90 or above
\tzcoor(2,1)(B){B}[0]
\tzcoor*(1,2)(C){C}[180](4pt)
\tzcoor*[fill=none](3,2)(D){D}[45]
\tzcoor*(4,0)(E){E}[[red,draw]180](4pt)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzcoor*(1,2)(C){C}[180](4pt)  % works as follows:
 \tzcoor(1,2)(C)
 \tzdot*(C){C}[180](4pt)
\end{tztikz}

%%------------------------------------------------------------
\section{Adding text next to lines or curves}
\label{si:texttolines}

\subsection{\protect\cmd{\tzline}}
\label{ssi:texttotzline}

\icmd{\tzline} accepts two mandatory coordinates.
To add text to a line segment, just specify the optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} the two coordinates. The |[<node opt>]| is |[above,midway]|, by default.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline(0,0){route A}(3,0)
\tzline[dashed](1,1){route B}(4,1)
\tzline[blue]
      (0,3) {plan C} [below,near end] (3,3)
\end{tikzpicture}
\end{tzcode}

The optional argument |{<text>}| \xem{following the second coordinate} can also be used as a name of the graph. By default, it is placed at the second coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline(0,3)(4,0){demand}
\tzline(0,0)(3,3){supply}[r]
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzto}}
\label{ssi:texttotzto}

To add text to a line or a curve drawn by \icmd{\tzto}, just specify the optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} the two coordinates. By default, the |[<node opt>]| is |[above,midway]|.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzto(0,0){route A}(3,0)
\tzto[dashed,bend left](1,1){route B}(4,1)
\tzto[blue,bend right]
    (0,3) {plan C} [below,near end] (3,3)
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzto(0,0){route A}(3,0) % works like:
 \draw (0,3) to node [above] {route A} (3,0);
\end{tztikz}

The optional argument |{<text>}| \xem{following the second coordinate} can also be used as a name of the graph. By default, it is placed at the second coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzto[bend right=15](0,3)(4,0){demand}
\tzto[bend right=10](0,0)(3,3){supply}[r]
\end{tikzpicture}
\end{tzcode}



\subsection{\protect\cmd{\tzbezier}}
\label{ssi:texttotzbezier}

\icmd{\tzbezier} accepts three or four coordinates as arguments.
You can add text to the curve drawn by |\tzbezier| using the optional arguments |{<text>}| and |[<node opt>]| after the last coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzbezier(0,2)(1,3)(3,0)(4,1){curve}[r]
\tzbezier[red,yshift=-5mm]
        (0,2)(1,3)(3,0)(4,1){curve}[midway]
\tzbezier[green,text=blue,yshift=-10mm]
        (0,2)(1,3)(3,0)(4,1){curve}[b,near end]
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzparabola}}
\label{ssi:texttotzparabola}

You can add text to a parabola drawn by |\tzparabola| using the optional arguments |{<text>}| and |[<node opt>]| \xem{following the last coordinate}.
The text is placed at (by default) or around the last coordinate according to |[<node opt>]|.


\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzparabola(0,2)(1,.5)(3,2){$AC$}[r]
\tzparabola[bend at end,blue](0,0)(4,3){$u(x)$}[r,red]
\end{tikzpicture}
\end{tzcode}


%%==================================
\chapter{An Intuitive Introduction II: Repetition of Coordinates}
\label{ci:introII}

%%------------------------------------------------------------
\section{Linking many coordinates: Semicolon versions}
\label{si:liknmanycoordinates}

\subsection{\protect\cmd{\tzlines}: Connected line segments}
\label{ssi:tzlines}

\icmd{\tzlines} connects with line segments an arbitrary number of coordinates. The coordinate iteration must end with a semicolon |;|.
Here, the \xem{semicolon} `|;|' indicates \xem{the end of repetition} of coordinates.
Let us call this kind of macro a \iisw{semicolon version} macro.

\remark: Without the semicolon |;|, an error occurs with the the \iisw{error message}:
 \begin{verbatim}
 ! Package tzplot Error: You may have forgotten a semicolon here or above!
 \end{verbatim}

\begin{tzdef}
% syntax: minimal
\tzlines[<opt>](<coor>)(<coor>)..repeated..(<coor>);
% syntax: simplified
\tzlines[<opt>]"<path name>"
       (<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
% defaults
 []""(<m>){}[]..repeated..(){}[];
% <m> means mandatory
\end{tzdef}


\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzlines(0,0)(1,2)(3,0)
       (4,1)(2,2)(3,3)
       (0,3)(0,1)(4,2) ; % semicolon
\end{tikzpicture}
\end{tzcode}

With the optional argument |{<text>}| followed by |[<node opt>]| \xem{in-between two coordinates}, you can print |{<text>}| at or around the middle point of the corresponding line segment in accordance with |[<node opt>]| (by default |[midway]|).

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzlines[dashed,->](0,0){up}[l]
                  (1,2){down}[r]
                  (3,0){up}[r]
                  (4,1) ;       % semicolon
\end{tikzpicture}
\end{tzcode}

The optional argument |{<text>}| \xem{following the last coordinate} can be used as a name of the whole connected line segments. The |{<text>}| is placed at (by default) or around the last coordinate according to |[<node opt>]|.

\begin{tzcode}{.3}
\begin{tikzpicture}[sloped,auto]
\tzhelplines(4,3)
\tzlines[dashed,->](0,0){up}
                  (1,2){down}
                  (3,0){up}
                  (4,1){Weight}[r,blue] ; % semicolon
\end{tikzpicture}
\end{tzcode}

\textsc{Remember} the repeating pattern is the triple |(<coor>){<text>}[<node opt>]| in that order.
DO NOT FORGET to indicate when the repetition ends by typing a semicolon. So it will look like |(){}[]..repeated..(){}[];|.

\subsection{\protect\cmd{\tzpolygon}, \protect\cmd{\tzpolygon*}: Closed paths}
\label{ssi:tzpolygon}

\icmd{\tzpolygon} draws closed line segments. |\tzpolygon| is also one of semicolon versions, meaning that it has to end with a semicolon |;|.
In fact, |\tzpolygon| is a closed version of |\tzlines|.

The starred version |\tzpolygon*| does the same thing as |\tzpolygon| except for one thing.
|\tzpolygon*|, by default, fills the interior of the polygon with |black!50| with |fill opacity=.3| but with |text opacity=1|. (Changing the |fill opacity| is not an issue in this introduction. See Section \ref{ss:tzpolygon} on page \pageref{ss:tzpolygon} for more details.)

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzpolygon(1,3)(0,2)(2,0)(3,1)(4,2)(2,3); % semicolon
\end{tikzpicture}
\end{tzcode}

The optional arguments |{<text>}| and |[<node opt>]| \xem{in-between} two coordinates prints |<text>| according to |[<node opt>]| (by default |[midway]|) around the middle point of the corresponding line segment.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzpolygon*[green,thick](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
\tzpolygon[dashed]
 (0,0){up}[l] (1,2){down}[r] (3,0){up}[r] (4,1);
\end{tikzpicture}
\end{tzcode}

The options |{<text>}| and |[<node opt>]| following the last coordinate can be used as a name of the connected line segments.

The entire repetition will look like |(<coor>){<text>}[<node opt>] ..repeated.. (){}[];|.
DO NOT FORGET to indicate when the repetition ends by typing a semicolon.

\begin{tzcode}{.3}
\begin{tikzpicture}[sloped,auto]
\tzhelplines(4,3)
\tzpolygon[dashed]
 (0,0){up} (1,2){down} (3,0){up} (4,1){Weight}[r] ;
\end{tikzpicture}
\end{tzcode}

\subsection{\protect\cmd{\tzpath*}: Filling area}
\label{ssi:tzpath}

\icmd{\tzpath} accepts an arbitrary number of coordinates to form a path, like |\tzlines| does, but the path is invisible. This is a \xem{semicolon version} macro, so the coordinate iteration must be ended by a semicolon |;|.
With |[draw]| option you can visualize the invisible path.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzpath[draw](1,3)(0,2)(2,0)
            (3,1)(4,2)(2,3); % semicolon
\end{tikzpicture}
\end{tzcode}

You can fill the interior of a path formed by |\tzpath| (after being closed) with color or pattern, in usual \Tikz\ way.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline[blue](0,3)(4,0)
\tzpath[pattern=crosshatch]
      (1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
\tzpath[pattern=bricks,preaction={fill=brown}]
      (0,0) (1,2) (3,0) (4,1);
\end{tikzpicture}
\end{tzcode}

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline[blue](0,3)(4,0)
\tzpath[fill,green]
      (1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
\tzpath[fill]
      (0,0) (1,2) (3,0) (4,1);
\end{tikzpicture}
\end{tzcode}



The starred version \icmd{\tzpath*} takes the default options |fill=black!50|, |fill opacity=.3|, and |text opacity=1| to fill the area.

\begin{tzdef}
% syntax: simplified
\tzpath*[<opt>](<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
% defaults
*[fill=black!50,fill opacity=.3,text opacity=1](<m>){}[]..repeated..(){}[];
% <m> means mandatory
\end{tzdef}

The macros |\tzpath| and |\tzpath*| are much more flexible. See Section \ref{s:tzpath} on page \pageref{s:tzpath} for more details.


\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline[blue](0,3)(4,0)
\tzpath*[green](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);
\tzpath*(0,0) (1,2) (3,0) (4,1);
\end{tikzpicture}
\end{tzcode}

How to change the |fill opacity| with |\tzpath*| is not discussed in this introduction, but one example is given below. (See Section \ref{s:tzpath*} on page \pageref{s:tzpath*} for more details.)

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline[blue](0,3)(4,0)
\tzpath*[green](1,3)(0,2)(2,0)(3,1)(4,2)(2,3);{1} %%
\tzpath*(0,0) (1,2) (3,0) (4,1);{.7}              %%
\end{tikzpicture}
\end{tzcode}



%%------------------------------------------------------------
\section{Many dots: Semicolon versions}
\label{si:manydots}

\subsection{\protect\cmd{\tzcdots(*)}}
\label{ssi:tzcdots}

\icmd{\tzcdots} accepts an arbitrary number of coordinates to print circle dots, but the coordinate repetition must be ended by |;| (semicolon version).
\icmd{\tzcdots*} prints filled circle dots.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcdots(0,0)(1,1)(2,1)(3,2)(4,3);
\tzcdots*[red](0,3)(1,3)(2,3)(3,3)(4,2); % semicolon
\end{tikzpicture}
\end{tzcode}

Each coordinate can be labeled by specifying the optional argument |{<label>}| followed by |[<angle>]|. You can also change the size (\xem{radius}) of the dots by specifying the \xem{last} parenthesis option |(<dot radius>)| \xem{after} the semicolon.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcdots(0,0)(1,1){B}(2,1)(3,2){D}[-90](4,3);(5pt)
\tzcdots*[fill=red](0,3){A}
                  (1,3){B}
                  (2,3){C}[-90]
                  (3,3)
                  (4,2){E}[[blue]0];(3pt) % radius
\end{tikzpicture}
\end{tzcode}



\subsection{\protect\cmd{\tzdots(*)}}
\label{ssi:tzdots}

\icmd{\tzdots} accepts an arbitrary number of coordinates to print circle node dots, but the repetition must be ended by |;| (semicolon version).
\icmd{\tzdots*} prints filled circle node dots.

\begin{tzdef}
% syntax: minimum
\tzdots*(<coor>)(<coor>)..repeated..(<coor>);
% syntax: simplified
\tzdots*[<opt>](<coor>){<label>}[<angle>]..repeated..
              (<coor>){<label>}[<angle>]; (<dot size>)
% defaults
*[tzdot=2.4pt](<m>){}[]..repeated..(){}[]; (2.4pt)
% <m> means mandatory
\end{tzdef}


\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzdots(0,0)(1,1)(2,1)(3,2)(4,3);
\tzdots*[red](0,3)(1,3)(2,3)(3,3)(4,2); % semicolon
\end{tikzpicture}
\end{tzcode}

Each coordinate can be labeled by specifying the optional argument |{<label>}| followed by |[<angle>]|. You can also change the size (\xem{diameter}) of the dots by specifying the \xem{last} parenthesis argument |(<dot size>)| \xem{after} the semicolon.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzdots(0,0)(1,1){B}(2,1)(3,2){D}[-90](4,3);(10pt)
\tzdots*[fill=red](0,3){A}
                 (1,3){B}
                 (2,3){C}[-90]
                 (3,3)
                 (4,2){E}[[blue]0];(6pt) % diameter
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{Many coordinates: Semicolon versions}
\label{si:manycoordinates}

\subsection{\protect\cmd{\tzcoors}, \protect\cmd{\tzcoors*}}
\label{ssi:tzcoors}

|\tzcoor| accepts \xem{a pair} of mandatory arguments in parentheses: |(<coor>)(<name>)|.
The semicolon version macro \icmd{\tzcoors} accepts \xem{an arbitrary number of pairs} to define multiple coordinates. A semicolon `|;|' is necessary to indicate when the repetition ends.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoors(0,0)(A)
       (1,1)(B)
       (2,1)(C)
       (3,3)(D)
       (4,2)(E);
\tzlines(A)(B)(C)(D)(E); % semicolon
\end{tikzpicture}
\end{tzcode}

The options |{<label>}| and |[<angle>]| following \xem{each pair} of |(<coor>)| and |(<name>)| allow you to put |<label>| in the direction of |<angle>| around the coordinate.
Here, the repeating pattern is the quadruple |(<coor>)(<name>){<label>}[<angle>]|. The first two parenthesis arguments are mandatory and others are optional. The pattern is repeated until |\tzcoors| meets a semicolon |;|.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoors(0,0)(A){A}
        (1,1)(B)
        (2,1)(C){C}[0]
        (3,3)(D){D}[180]
        (4,2)(E){E}[-90];
\tzlines(A)(B)(C)(D)(E);
\end{tikzpicture}
\end{tzcode}


The starred version \icmd{\tzcoors*} does one more thing: to print node dots.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoors*(0,0)(A){A}
        (1,1)(B)
        (2,1)(C){C}[0]
        (3,3)(D){D}[180]
        (4,2)(E){E}[-90];
\end{tikzpicture}
\end{tzcode}



\subsection{\protect\cmd{\tzcoorsquick}}
\label{ssi:tzcoorsquick}

\icmd{\tzcoorsquick} is just to see the array of many coordinates at a glance.
|\tzcoorsquick| works like |\tzcoors|, but it automatically prints the name of each coordinate as its label, right at the point, by default.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoorsquick(0,0)(A)
            (1,1)(Best)
            (2,1)(Case)
            (3,3)(Done)
            (4,2)(End); % semicolon
\end{tikzpicture}
\end{tzcode}

\subsection{\protect\cmd{\tzcoorsquick*}}
\label{ssi:tzcoorsquick*}

The starred version \icmd{\tzcoorsquick*} prints node dots and automatically puts the labels |above| (in the direction of |90| degree from) them, by default.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoorsquick*(0,0)(A)
             (1,1)(Best)
             (2,1)(Case)
             (3,3)(Done)
             (4,2)(End){END!}[[blue]0];
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{\texttt{plot coordinates}: Semicolon versions}
\label{si:plotcoordinates}

\subsection{\protect\cmd{\tzplot*}: Mark dots with \texttt{[mark=*]}}
\label{ssi:tzplot*}

\icmd{\tzplot*} accepts an arbitrary number of coordinates to print bullets with the \xem{radius} (|mark size| in \Tikz) of |2pt|, which is the initial value in \Tikz. Since this is a semicolon version, the repetition of coordinates must be ended by |;|.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzplot*(0,0)
       (1,1)
       (2,1)
       (3,3)
       (4,2) ; % semicolon
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzplot*(0,0)(1,1)(2,1); % works like:
 \draw [mark=*] plot coordinates {(0,0)(1,1)(2,1)};
\end{tztikz}

Each coordinate can be labeled by specifying the optional argument |{<text>}| followed by |[<angle>]|. With the option |[mark=o]| you can print hollow dots. You can also change the \xem{radius} of the marks by specifying the \xem{last} parenthesis argument |(<mark size>)| \xem{after} the semicolon.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzplot*[mark=o](0,0){A}
               (1,1){Best}
               (2,1){Case}
               (3,3){Done}
               (4,2){END!}[[blue]0] ; (1.2pt)
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzplot}: Lines with \texttt{[tension=0]}}
\label{ssi:tzplot:lines}

\icmd{\tzplot} accepts an arbitrary number of coordinates and draws line segments connecting them. The repetition of coordinates must be ended by |;| (semicolon version).

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzplot(0,0)
      (1,1)
      (2,1)
      (3,3){Done}
      (4,2){END!}[[blue]0];
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzplot(0,0)(1,1)(2,1); % works like:
 \draw plot coordinates {(0,0)(1,1)(2,1)};
\end{tztikz}


\subsection{\protect\cmd{\tzplot*[draw]}: Lines with dots}

\icmd{\tzplot*}|[draw]| prints bullet marks at the specified coordinates and draws line segments connecting them. The repetition of coordinates must be ended by |;| (semicolon version).

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzplot*[draw](0,0)
       (1,1)
       (2,1)
       (3,3)
       (4,2){END!}[[blue]0];
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzplotcurve}: Curves with \texttt{[smooth,tension=1]}}
\label{ssi:tzplotcurve}

\icmd{\tzplotcurve} plots any number of coordinates with the default option |[smooth,tension=1]|, resulting in a \xem{curve} connecting the specified coordinates.
The repetition of coordinates must be ended by |;| (semicolon version).

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzplotcurve(0,0)
           (1,1)
           (2,1)
           (3,3)
           (4,2){END!}[[blue]0] ; % semicolon
\end{tikzpicture}
\end{tzcode}

\begin{tzdef}
% syntax: simplified
\tzplotcurve[<opt>]{<tension>}"<path name>"
           (<coor>){<label>}[<angle>]..repeated..(<coor>){<label>}[<angle>];
% defaults
 [smooth,tension=1]{1}""(<m>){}[]..repeated..(){}[];
% <m> means mandatory
\end{tzdef}

\begin{tztikz}
\tzplotcurve(0,0)(1,1)(2,1); % works like:
 \draw [smooth,tension=1] plot coordinates {(0,0)(1,1)(2,1)};
\end{tztikz}

You can change the tension value by specifying the optional argument |{<tension>}|, before the first coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzcoor(.5,.5)(A)
\tzplotcurve[blue]{2}(1,3)(A)(4,0);
\tzplotcurve[thick](1,3)(A)(4,0); % default: tension=1
\tzplotcurve[red]{.55}(1,3)(A)(4,0); % TikZ default
\tzplotcurve[dashed]{0}(1,3)(A)(4,0);
\end{tikzpicture}
\end{tzcode}




%%==================================
\chapter{An Intuitive Introduction III: Plotting Functions}
\label{ci:introIII}


%%------------------------------------------------------------
\section{Axes}
\label{si:axes}

\subsection{\protect\cmd{\tzaxes}}
\label{ssi:tzaxes}

\begin{tzdef}
% syntax: simplified
\tzaxes[<opt>]<x-shift,y-shift>(<x1,y1>)(<x2,y2>)
                              {<x-text>}[<x-opt>]{<y-text>}[<y-opt>]
% defaults
 [->]<0,0>(0,0)(<m>){}[right]{}[above]
% <m> means mandatory
\end{tzdef}

\icmd{\tzaxes} draws the x-axis from |<x1>| to |<x2>| and the y-axis from |<y1>| to |<y2>|.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzaxes(-1,-1)(8,5) % basics
\end{tikzpicture}
\end{tzcode}

If |(<x1,y1>)| is omitted, it is regarded as |(0,0)|.
And optionally the names of x-axis and y-axis can be printed at a specified place (by default, |[right]| for x-axis and |[above]| for y-axis).

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzaxes[draw=blue](8,5){$x$}{$y$} %%
\end{tikzpicture}
\end{tzcode}

With the optional argument |<x-shift,y-shift>|, the axes are shifted accordingly. Two axes intersect at |(<x-shift,y-shift>)|, by default |(0,0)|.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzaxes(-1,-1)(8,5){$Q$}[b]{$P$}[l]
\tzaxes[dashed,-]<2,1>(-1,-1)(8,5) % shift
\end{tikzpicture}
\end{tzcode}

\subsection{\protect\cmd{\tzaxes*}}
\label{ssi:tzaxes*}

The starred version \icmd{\tzaxes*} is just to set the current state to a \iisw{bounding box} when the |\tzaxes| macro execution is completed. Use |\tzaxes*| before any larger graphics.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzaxes*(8,5){$x$}{$f(x)$} % bounding box
\tzhelplines(-2,-1)(10,8)
\tzto[out=90,in=-135,dashed](-2,8)(12,-2)
\tzbezier[blue](-1,-1)(3,-2)(7,12)(10,10)
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzshoworigin}, \protect\cmd{\tzshoworigin*}}
\label{ssi:tzshoworigin}

\icmd{\tzshoworigin} prints `$0$' (roughly) at the bottom left of the origin.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzshoworigin
\tzaxes(-1,-1)(8,5)
\end{tikzpicture}
\end{tzcode}

\icmd{\tzshoworigin*} prints a \xem{node dot} with the size of |2.4pt| (by default) at the origin.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzshoworigin*
\tzaxes(-1,-1)(8,5)
\end{tikzpicture}
\end{tzcode}

|\tzshoworigin*(<coor>){<text>}[<node opt>]| prints a node dot and text around |(<coor>)|, by default |(0,0)|. (Notice that the place where the |<text>| is printed at is not by |<angle>|. Instead, you can use the \xem{abbreviations} of \Tikz\ basic placement options such as |a|, |l|, |br|, ect. See Section \ref{s:stylenames}, for more details.)

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzshoworigin*{$O_1$}
\tzaxes(-1,-1)(8,5)
\tzaxes[blue]<7,4>(8,5)(-1,-1)
\tzshoworigin*(7,4){$O_2$}[ar]
\end{tikzpicture}
\end{tzcode}

Notice that, in the previous example, the two axes intersect at |(7,4)| by the shift option |<7,4>|.

\subsection{\protect\cmd{\tzaxisx}, \protect\cmd{\tzaxisy}}
\label{ssi:tzaxesx}

\icmd{\tzaxisx} draws an x-axis from |<x1>| to |<x2>|.

\begin{tzdef}
% syntax: simplified
\tzaxisx[<opt>]<y-shift>{<x1>}{<x2>}{<text>}[<node opt>]
% defaults
 [->,>=stealth]<0>{<m>}{<m>}{}[right]
\end{tzdef}

\icmd{\tzaxisy} works similarly for the y-axis, except for the axis label position: |above| by default.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzaxisx{-1}{8}{$x$}
\tzaxisy[draw=blue,thick]{-1}{5}{$y$}
\tzaxisx[dashed,-]<2>{-1}{8}
\tzaxisy[thick,<->]<1>{-1}{5}
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{Ticks}
\label{si:tikzs}

\subsection{\protect\cmd{\tzticks}}
\label{ssi:tzticks}

\icmd{\tzticks}|{<x-tick places>}{<y-tick places>}| prints tick labels for x- and y-axis at specified places, which are comma separated.
By default, tick labels are the numbers specified.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
\tzhelplines(8,5)
\tzshoworigin
\tzaxes(-1,-1)(8,5)
\tzticks{1,2,...,8} % x-ticks
       {1,2,...,5} % y-ticks
\end{tikzpicture}
\end{tzcode}

You can change the numbered labels, for example |{2,4,7}|, to any other form, by doing like, for example, |{2/mylabel,4,7}|. (Internally, |\tzticks| uses the |foreach| operation of \Tikz.)

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
\tzhelplines(8,5)
\tzshoworigin
\tzaxes(-1,-1)(8,5)
\tzticks{2/x,4/y,5.5/$z_1$,7}
       {1,2.5/$\frac25$,4}
\end{tikzpicture}
\end{tzcode}

\subsection{\protect\cmd{\tzticks*}}
\label{ssi:tzticks*}

The starred version \icmd{\tzticks*} prints tick marks from |0pt| to |3pt| by default, without printing tick labels.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(8,5)
\tzshoworigin
\tzaxes(-1,-1)(8,5)
\tzticks*{1,2,...,7}
        {1,2,3,4}
\end{tikzpicture}
\end{tzcode}

You can change the length of tick marks, for example, like |(-2pt:3pt)| and |(-5pt:10pt)| as shown in the following example.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5]
\tzhelplines(-1,-1)(8,5)
\tzaxes(-1,-1)(8,5)
\tzticks*(-2pt:3pt){1,2,...,7}
        (-5pt:10pt){1,2,3,4}
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzticksx(*)}, \protect\cmd{\tzticksy(*)}}
\label{ssi:tztikcsx}

\icmd{\tzticksx} and \icmd{\tzticksy} prints x-tick labels and y-tick labels, respectively.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
\tzhelplines(8,5)
\tzaxes(-1,-1)(8,5)
\tzticksx{1/x,3/y,5/z,7}
\tzticksy(-5pt:10pt){1,2,4/k}
\end{tikzpicture}
\end{tzcode}

\icmd{\tzticksx*} and \icmd{\tzticksy*} suppress tick labels for their corresponding axes, like |\tzticks*|.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(8,5)
\tzaxes(-1,-1)(8,5)
\tzticksx*{1/x,3/y,5/z,7}
\tzticksy*(-5pt:10pt){1,2,4/k}
\end{tikzpicture}
\end{tzcode}

You can see more details on |\tzticks| and its friends in Chaper \ref{c:ticks} on page \pageref{c:ticks}.


%%------------------------------------------------------------
\section{Projections on the axes}
\label{si:projections}


\subsection{\protect\cmd{\tzprojx(*)}, \protect\cmd{\tzprojy(*)}}
\label{ssi:tzprojx}

\icmd{\tzprojx} draws a \xem{dotted line} (by default) from a specified coordinate to its projection point on the x-axis and prints text around (|[below]| by default) the projection point.

|\tzprojy| works similarly but for the projection point on the y-axis.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzaxes(4,3)
\tzdot*(3,2){$(x_1,x_2)$}[45]
\tzprojx(3,2){$x_1$}
\tzprojy[solid,->,draw=blue](3,2){$x_2$}[bl]
\end{tikzpicture}
\end{tzcode}

\icmd{\tzprojx*} does one more thing. It prints a node dot (with |\tzdot*|) at a specified coordinate. |\tzprojy*| works similarly but for the projection point on the y-axis.


\begin{tzcode}{.3}
\begin{tikzpicture}
%\tzhelplines(4,3)
\tzaxes(4,3)
\tznode(3,2){$(x_1,x_2)$}[ar]
\tzprojx*(3,2){$x_1$}[xshift=-3pt]
\tzprojy[->,dashed,draw=red](3,2){$x_2$}
\tzprojx*(1.5,2.5){$a$}
\tzprojy*(2.5,1.5){$b$}
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzproj(*)}}
\label{ssi:tzproj}

\icmd{\tzproj} combines |\tzprojx| and |\tzprojy|.
And \icmd{\tzproj*} combines |\tzprojx*| and |\tzprojy*|.


\begin{tzcode}{.3}
\begin{tikzpicture}
%\tzhelplines(4,3)
\tzaxes(4,3)
\tznode(3,2){$(x_1,x_2)$}[ar]
\tzproj[<->,solid,draw=red](3,2){$x_1$}{$x_2$}
\tzproj*(1.5,2.5){$a$}[xshift=3pt,text=blue]{$b$}
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{Plot functions}
\label{si:plotfunctions}

\subsection{\protect\cmd{\tzfn}}
\label{ssi:tzfn}

\icmd{\tzfn}|{<fn of \x>}[<a:b>]| plots a function of $x$ over the specified domain $[a:b]$, which means that $a\leq x \leq b$.
Optionally, you can add |{<text>}| with |[<node opt>]| as shown in the following example.

\begin{tzdef}
% syntax: simplified
\tzfn[<opt>]"<path name>"{<fn of \x>}[<a:b>]{<text>}[<node dot>]
% defaults
 []""{<m>}[<m>]{}[]
% <m>: mandatory
\end{tzdef}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines(5,5)
\tzaxes(5,5)
\tzfn{(\x-1)^2}[0:3]               % y=(x-1)^2
\def\Gx{(\x-2)^2+1}
\tzfn[dashed]{\Gx}[1:4]{$g(x)$}[r] % g(x)=(x-2)^2+1
\tzfn[red]{sin(\x r)+3}[0:2*pi]    % y=sin x
\end{tikzpicture}
\end{tzcode}

\begin{tztikz}
\tzfn[dashed]{(\x-2)^2+1}[1:4]{$g(x)$}[r] % works like:
 \draw [dashed] plot [domain=1:4] (\x,{(\x-2)^2+1}) node [right] {$g(x)$};
\end{tztikz}

You can name a path formed by |\tzfn| by specifying the optional argument |"<path name>"| right before the mandatory curly brace argument |{<fn of \x>}|. The name of a path is used to find intersection points.


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7,font=\footnotesize]
\tzhelplines(5,5)
\tzaxes(5,5){$x$}{$y$}
\def\bgt{4-\x}
\def\IC{3/\x}
\def\ICa{4/\x}
\tzfn"bgt"{\bgt}[0:4]       % name path = bgt
\tzfn[blue]"IC"{\IC}[.75:4] % name path = IC
\tzfn[red]{\ICa}[1:4] % name path = ICa (automatically)
\end{tikzpicture}
\end{tzcode}

\remark
If the curly brace mandatory argument consists of \xem{only a macro name} like |{\Foo}|, the macro name |Foo| (without the backslash) is automatically assigned to the \xem{name of the path}. (See Section \ref{ss:tzfn:namepath} on page \pageref{ss:tzfn:namepath}, for more details.)

\subsection{\protect\cmd{\tzhfnat}, \protect\cmd{\tzhfn}: Horizontal lines}
\label{ssi:tzhfn}

\icmd{\tzhfnat} accepts a value of $y$ and draws a horizontal line (the graph of a constant function) at $y$ from left to right of the \ixxw{current bounding box}, by default, unless you specify the optional argument |[<from:to>]|.

\begin{tzdef}
% syntax
\tzhfnat[<opt>]"<path name>"{<y-val>}[<from:to>]{<text>}[<node opt>]
% defaults
 []""{<m>}[west:east (of current bounding box)]{}[]
\end{tzdef}

\icmd{\tzhfn}|(<coor>)| accepts a coordinate, instead of the value of $y$, to draw a horizontal line at the value of $y$ coordinate of |(<coor>)|, ignoring the value of $x$ coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzhfnat{0}                               % value of y
\tzhfnat[dashed]{1}[1:4]{Two}[l,at start] % value of y
\tzcoors(0,2)(A)(0,3)(B);
\tzhfn[blue](A)[0:3]{Three}[b,near end]   % coordinate
\tzhfn[->](B)[0:3]{Four}[r]               % cooridnate
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzvfnat}, \protect\cmd{\tzvfn}: Vertical lines}
\label{ssi:tzvfn}

\icmd{\tzvfnat} draws a vertical line at $x$ from bottom to top of the |current bounding box| by default.

\begin{tzdef}
% syntax: simplified
\tzvfnat[<opt>]"<path name>"{<x-vale>}[<from:to>]{<text>}[<pos>]
% defaults
 []""{<m>}[south:north (of current bounding box)]{}[]
\end{tzdef}

\icmd{\tzvfn}|(<coor>)| accepts a coordinate, instead of the value of $x$. It draws a vertical line at the value of $x$ coordinate of |(<coor>)|, ignoring the value of $y$ coordinate.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzvfnat{0}
\tzvfnat[dashed]{1}[1:3]{Two}[b,at start]
\tzvfn[blue](2,0)[0:3]{Three}[a,near end,sloped]
\tzvfn[->](3,0)[0:3]{Four}[r]
\end{tikzpicture}
\end{tzcode}



\subsection{\protect\cmd{\tzLFn}: Linear functions}
\label{ssi:tzLFn}

\icmd{\tzLFn}|(<coor1>)(<coor2>)...| draws a \xem{linear function} passing through two points: |(<coor1>)| and |(<coor2>)|.
|\tzLFn(<coor1>){<slope>}...| draws a linear function passing through one point, |(<coor1>)|,  with the slope of |<slope>|. If two coordinates and a slope are all specified the option |{<slope>}| is ignored. The domain in the form of |[a:b]| is also a required argument.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7,font=\footnotesize]
\tzhelplines(5,5)
\tzaxes(-1,-1)(5,5)
\tzdots*(1,1)(3,2);
\tzLFn(1,1)(3,2)[0:4]{two points}[r]
\tzLFn(1,1){1.5}[0:3]{one point and a slope}[r]
\end{tikzpicture}
\end{tzcode}



%%------------------------------------------------------------
\section{Intersection points}
\label{si:intersections}

\subsection{Naming paths}
\label{ssi:namingpaths}

In \Tikz, you can find \xem{intersection} points when two \xem{named paths} intersect. The name of a path is usually given by the option |[name path=<path name>]| in \Tikz.

With the package \pkg{tzplot}, you can name a path by specifying an optional argument within quotation marks such as |"<path name>"|.
(Of course, you can also name a path in usual \Tikz\ way, like |[name path=<path name>]|.)

In this package, all macros (with a few exceptions) related to lines and curves accept this quote optional argument to name paths as follows:

\begin{verbatim}
   \tzline[<opt>]"<path name>"(<coor>)...
   \tzlines...   "<path name>"(<coor>)...
   \tzto...      "<path name>"(<coor>)...
   \tzfn...      "<path name>"{<fn of \x>}...
   \tzLFn...     "<path name>"(<coor>)...
   and more...
\end{verbatim}

\begin{tztikz}
\tzline[dashed]"foo"(1,1)(3,3) % works like
 \draw [dashed,name path=foo](1,1) -- (3,3);
\end{tztikz}

In most cases, the quote optional arguments for naming paths are placed \xem{immediately before the first mandatory argument} of the |tzplot| macros.

\subsection{\protect\cmd{\tzXpoint(*)}: Intersection points of two paths}
\label{ssi:tzXpoint}

For example, \icmd{\tzXpoint}|{path1}{path2}(A)| finds intersection points of |path1| and |path2| and names the first intersection point |(A)|. This intersection point can be referred to as |(A)| or |(A-1)|. If there are two or more intersection points found, they are called |(A)=(A-1)|, |(A-2)|, |(A-3)|, and so on.

\begin{tzcode}{.3}
\begin{tikzpicture}
\tzhelplines(4,3)
\tzline"AA"(0,0)(3,2)
\tzline"BB"(0,3)(3,0)
\tzXpoint{AA}{BB}(X)
\tzdot*(X){E}
\end{tikzpicture}
\end{tzcode}

\icmd{\tzXpoint*} prints a node dot at the first intersection point.
You can label the point by specifying |{<text>}| and |[<angle>]| after the specified intersection name.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7,font=\footnotesize]
\tzhelplines(5,5)
\tzaxes(5,5){$x$}{$y$}
\def\bgt{4-\x}
\def\IC{3/\x}
\tzfn"bgt"{\bgt}[0:4]           % name path = bgt
\tzfn[blue]"IC"{\IC}[.75:4]     % name path = IC
\tzXpoint*{bgt}{IC}(E){$A$}[45] % first intersection
\tzdot(E-2){$B$}[45](5pt)       % second intersection
\end{tikzpicture}
\end{tzcode}

\remark
You have to expect \Tikz\ to take a few seconds (or less) to find intersection points.

\subsection{\protect\cmd{\tzvXpointat(*)}, \protect\cmd{\tzvXpoint(*)}: Vertical intersection points}
\label{ssi:tzvXpoint}

To find vertical intersection points at $x$ to a curve, you should specify a path name and either the value of $x$ or the coordinate $(x,y)$. Here the $y$ coordinate is ignored.

\icmd{\tzvXpointat}|{<path>}{<x>}(A)| finds vertical intersection points of |<path>| at  $x=\texttt{<x>}$ and names it |(A)|.
The starred version \icmd{\tzvXpointat*} additionally prints a node dot at the (first) intersection point.

The macro \icmd{\tzvXpoint} uses |(<coor>)|, while |\tzvXpointat| uses the value of $x$. Here the $y$ coordinate of |(<coor>)| is not important. |\tzvXpoint| is useful when you do not know the exact value of $x$ coordinate of |(<coor>)|.
The starred version \icmd{\tzvXpoint*} additionally prints a node dot at the (first) intersection point.


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7,font=\scriptsize]
\tzhelplines(5,5)
\tzaxes(5,5)
\def\Fx{(\x-1)^2}
\tzfn\Fx[0:3] % name path = Fx (automatically)
\tzvXpointat{Fx}{2.5}(A)
\tzvXpoint{Fx}(2.8,1)(B) % y=1 is ignored
\tzproj*[->](A){$2.5$}{$f(2.5)$}
\tzdot(B){$B$}[0]
\end{tikzpicture}
\end{tzcode}


\subsection{\protect\cmd{\tzhXpointat(*)}, \protect\cmd{\tzhXpoint(*)}: Horizontal intersection points}
\label{ssi:tzhXpoint}

\icmd{\tzhXpointat}|{<path>}{<y>}(A)| works like |\tzvXpointat{<path>}{<x>}(A)|, but it uses the value of $y$ instead of $x$.
The starred version \icmd{\tzhXpointat*} additionally prints a node dot at the (first) intersection point.

\icmd{\tzhXpoint} uses |(<coor>)|, while |\tzhXpointat| uses the value of $y$.
Here the $x$ coordinate of |(<coor>)| is ignored.
The starred version \icmd{\tzhXpoint*} prints a node dot at the (first) intersection point.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7,font=\scriptsize]
\tzhelplines(5,5)
\tzaxes(5,5)
\def\Fx{(\x-1)^2}
\tzfn\Fx[0:3] % name path = Fx (automatically)
\tzhXpointat{Fx}{2.5}(A)
\tzhXpoint{Fx}(1,2.8)(B) % x=1 is ignored
\tzproj*[<-](A){$f^{-1}(2.5)$}{$y=2.5$}
\tzdot(B){$B$}[0]
\end{tikzpicture}
\end{tzcode}

You can see more details on |\tzXpoint| and its friends in Chapter \ref{c:intersections} on page \pageref{c:intersections}.


%%------------------------------------------------------------
\section{Tangent lines and secant lines}
\label{si:tangentlines}

\subsection{\protect\cmd{\tztangentat}}
\label{ssi:tztangentat}

\icmd{\tztangentat}|{<path>}{<x>}[<a:b>]| draws a tangent line to |<path>| at $x=\texttt{<x>}$ over $x\in [a,b]$.
The domain is a mandatory argument and should be of the form |[<from:to>]|.

\begin{tzdef}
% syntax: simplified
\tztangentat{<path>}{<x>}[<domain>]{<text>}[<node opt>]
% defaults
 []{<m>}{<m>}[<m>]{}[]
% <m> means mandatory
\end{tzdef}


\remark
The slope of a tangent line drawn by |\tztangentat| is just approximate.

The line is drawn on the |behind| layer, by default.

You can also add some text next to the tangent line by specifying the optional arguments |{<text>}| and |[<node opt>]|, after the domain.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines(5,5)
\tzparabola[thick,blue]"curve"(0,1)(2,3)(4,2)
\tzvXpointat*{curve}{1}
\tzvXpointat*{curve}{3}
\tztangentat{curve}{1}[0:3]
\tztangentat[red]{curve}{3}[1:5]{tangent at $x=3$}[b]
\end{tikzpicture}
\end{tzcode}

\subsection{\protect\cmd{\tztangent}}
\label{ssi:tztangent}

\icmd{\tztangent} works like |\tztangentat|, but it accepts a coordinate instead of the value of $x$.

|\tztangent{<path>}(<coor>)| draws a tangent line to |<path>| at the $x$ coordinate of |(<coor>)|. Here, the $y$ coordinate of |(<coor>)| is ignored. The line is drawn on the |behind| layer, by default.


\begin{tzdef}
% syntax: simplified
\tztangent{<path>}(<coor>)[<from:to>]{<text>}[<node opt>]
% defaults
 []{<m>}(<m>)[<m>]{}[]
\end{tzdef}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines(5,5)
\tzparabola[thick,blue]"curve"(0,1)(2,3)(4,2)
\tzvXpoint*{curve}(1,0)(A){A}[135]
\tzvXpoint*{curve}(3,0)(B){B}[45]
\tztangent{curve}(A)[0:3]
\tztangent[red]{curve}(B)[1:5]{tangent at $B$}[b]
\end{tikzpicture}
\end{tzcode}


See Section \ref{s:tangent} on page \pageref{s:tangent} for more details on |\tztangent| and |\tztangentat|.


\subsection{\protect\cmd{\tzsecantat}, \protect\cmd{\tzsecant}}
\label{ssi:tzsecant}

\icmd{\tzsecantat}|{<path>}{<x1>}{<x2>}| draws a secant line segment of |<path>| from $x_1=\texttt{<x1>}$ to $x_2=\texttt{<x2>}$ on the |behind| layer, by default.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines(5,5)
\tzaxes*(5,5)
\tzparabola"curve"(0,1)(2,3)(5,1)
\tzsecantat{curve}{1}{2}
\tzsecantat[red]{curve}{1}{3}
\tzsecantat[blue]{curve}{1}{4}
\end{tikzpicture}
\end{tzcode}

\icmd{\tzsecant} works like |\tzsecantat|, but it accepts two coordinates instead of two values of $x$.

|\tzsecant{<path>}(<coor1>)(<coor2>)| draws a secant line segment of |<path>| from the $x$ coordinate of |(<coor1>)| to the $x$ coordinate of |(<coor2>)|, ignoring $y$ values of the coordinates, on the |behind| layer by default.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines(5,5)
\tzaxes(5,5)
\tzparabola"curve"(0,1)(2,3)(5,1)
\tzsecant{curve}(1,0)(2,0)
\tzsecant[red]{curve}(1,0)(3,0)
\tzsecant[blue,dashed]{curve}(1,0)(4,0)
\end{tikzpicture}
\end{tzcode}


You can extend or shorten a secant line by specifying the domain |[<from:to>]|, which is an optional argument.
If you specify the domain, |\tzsecant| draws a secant line over the domain.
You can also add some text next to the secant line by specifying the optional arguments |{<text>}| and |[<node opt>]|.

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.7]
\tzhelplines[use as bounding box](5,5)
\tzaxes(5,5)
\tzparabola"curve"(0,1)(2,3)(5,1)
\tzsecant{curve}(1,0)(2,0)
\tzsecant[red]{curve}(1,0)(3,0)[0:5]{secant}[r]
\tzsecantat[blue,dashed]{curve}{1}{4}[0:5]{blue}[r]
\end{tikzpicture}
\end{tzcode}

See Section \ref{s:secant} on page \pageref{s:secant} for more details on |\tzsecant| and |\tzsecantat|.

%%==================================
\chapter{Examples: Economics}
\label{ci:examples}

%%------------------------------------------------------------
\section{Markets}
\label{si:markets}

\subsection{Market equilibrium: step by step}
\label{ssi:mkteqm}

\paragraph{Step 1} Determine the size of the graph.

\begin{tzcode}{.3}
\begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
% to avoid `dimension too large' error: x/y=0.05cm
\tzhelplines[step=.5cm](110,110)
\tzaxes(110,110){$Q$}{$P$}
%\tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
%\tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
%\tzXpoint*{dem}{supp}(eqm){$E$}
%\tzproj(eqm){$Q^*$}{$P^*$}
\end{tikzpicture}
\end{tzcode}

\paragraph{Step 2} Draw the demand and supply curves.
Here, we are using |\tzto|.

\begin{tzcode}{.3}
\begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
% to avoid `dimension too large' error: x/y=0.05cm
\tzhelplines[step=.5cm](110,110)
\tzaxes(110,110){$Q$}{$P$}
\tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
\tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
%\tzXpoint*{dem}{supp}(eqm){$E$}
%\tzproj(eqm){$Q^*$}{$P^*$}
\end{tikzpicture}
\end{tzcode}

\paragraph{Step 3} Find an equilibrium point and name it. Use the starred version |\tzXpoint*| to print a dot and then label the point.

\begin{tzcode}{.3}
\begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
% to avoid `dimension too large' error: x/y=0.05cm
\tzhelplines[step=.5cm](110,110)
\tzaxes(110,110){$Q$}{$P$}
\tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
\tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
\tzXpoint*{dem}{supp}(eqm){$E$}
%\tzproj(eqm){$Q^*$}{$P^*$}
\end{tikzpicture}
\end{tzcode}

\tmpclearpage

\paragraph{Step 4} If necessary, use |\tzproj| to draw projection lines with text around the projection points.

\begin{tzcode}{.3}
\begin{tikzpicture}[x=0.05cm,y=0.05cm,scale=.7]
% to avoid `dimension too large' error: x/y=0.05cm
%\tzhelplines[step=.5cm](110,110)
\tzaxes(110,110){$Q$}{$P$}
\tzto[bend right=15]"dem"(0,100)(100,0){$D$}[a]
\tzto[bend right=15]"supp"(0,10)(100,90){$S$}[ar]
\tzXpoint*{dem}{supp}(eqm){$E$}
\tzproj(eqm){$Q^*$}{$P^*$}
\end{tikzpicture}
\end{tzcode}

\subsection{Tax incidence: step by step}
\label{ssi:taxincidence}

\begin{enumerate}[{Step} 1{:}]
\item Determine the size of the graph.
\end{enumerate}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.035,font=\scriptsize]
\tzhelplines[step=10cm](120,120)
\tzaxes(120,120){$Q$}{$P$}
\end{tikzpicture}
\end{tzcode}


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.035,font=\scriptsize]
%\tzhelplines[step=10cm](120,120)
\tzaxes(120,120){$Q$}{$P$}
% step 2
\def\demA{100-\x}
\def\suppA{10+\x}
\tzfn\demA[0:100]{$D$}[ar]      % name path = \demA
\tzfn\suppA[0:90]{$S$}[r]       % name path = \suppA
\tzXpoint*{demA}{suppA}(E){$E$}
% step 3
\tzfn[dashed]"suppB"{\suppA+20}[0:80]{$S'$}[ar]
\tzXpoint*{demA}{suppB}(newE){$E'$}
\tzproj(newE){$Q$}{$P_d$}
% step 4
\tzvXpoint{suppA}(newE)(vX)
% step 5
\tzprojy(vX){$P_s$}
\tzprojy(E){$P^c$}
% step 6
\tzpath*[red](E)(newE)(vX);
% step 7
\tznode($(E)!10cm!(E-|0,0)$){}[pin={-70:SWL}]
\end{tikzpicture}
\end{tzcode}


\begin{enumerate}\addtocounter{enumi}{1}\renewcommand{\labelenumi}{{Step} \theenumi{:}}\firmlist
\item Define functions and plot them. And then, find an intersection point.
\item Draw the shifted supply curve and find new equilibrium point. And then, project the point on each axis.
\item To illustrate the social welfare loss (SWL), find a vertical intersection point of the original supply curve using new equilibrium point.
\item Project both of the old equilibrium point and the vertical intersection point onto the $y$ axis and add text.
\item Fill the area of the social welfare loss with color.
\item Add text `SWL' at the appropriate place.
\end{enumerate}


%%------------------------------------------------------------
\section{Firms}
\label{si:firms}

\subsection{Cost curves}
\label{ssi:costcurves}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.4,font=\scriptsize]
\tzhelplines(10,10)
\tzaxes(10,10){$q$}{$AC$\\$AVC$\\$MC$}[align=center]
\tzparabola"MC"(.5,4)(2,2)(6,9){$MC$}[a]
\tzhXpointat{MC}{5}(A)
\tzhXpointat{MC}{3}(B) % (B-2) will be used!
\tzdots*(A)(B-2);
\tzparabola(2,7)(A)(8,9){$AC$}[r]
\tzparabola(1,4.5)(B-2)(8,8){$AVC$}[r]
\end{tikzpicture}
\end{tzcode}

\subsection{Equilibrium of a competitive firm}
\label{ssi:competitive}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.4,font=\scriptsize]
%\tzhelplines(10,10)
\tzaxes(10,10){$q$}{$P$\\$AC$\\$MC$}[align=center]
\tzparabola"MC"(2,2)(6,9){$MC$}[a]
\tzhXpointat{MC}{4}(A) % point (A) on MC at q=4
\tzparabola"AC"(2,7)(A)(8,9){$AC$}[r] % (A): minAC
\tzhfnat[blue]"price"{6}[0:9]{$P$}[l,at start]
\tzXpoint*{price}{MC}(E)
\tzprojx(E){$q^*$}
\tzvXpoint{AC}(E)(ACeqm) % point on AC in eqmuilibrium
\tzprojy(ACeqm){$AC(q^*)$}
\tzpath*[red](E-|0,0)(E)(ACeqm)(ACeqm-|0,0);
\tznode(2,5){$\pi^*$}
\end{tikzpicture}
\end{tzcode}


\subsection{Monopoly equilibrium}
\label{ssi:monopoly}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(10,10)
\tzaxes(10,10){$Q$}{$P$}
\def\DD{8-\x}
\def\MR{8-2*\x}
\def\MC{\x}
\tzfn\DD[0:8]{$D$}[ar]
\tzfn\MR[0:4.5]{$MR$}[r]
\tzfn\MC[0:7]{$MC$}[r]
\tzXpoint*{MR}{MC}(E)
\tzvXpoint*{DD}(E)(EE)
\tzproj(EE){$Q^M$}{$P^M$}
\tzXpoint{DD}{MC}(C)
\tzpath*(EE)(C)(E);
\tznode(C){\tiny SWL}[l]
\tzpath*[blue](0,8)(EE)(EE-|0,0);
\tznode(1,6){C.S.}
\tzpath[pattern=horizontal lines](0,0)(E)(E-|0,0);
\tznode(1,2){P.S.}
\end{tikzpicture}
\end{tzcode}

%%------------------------------------------------------------
\section{Consumers: Budget lines and indifference curves}
\label{si:consumers}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.3,font=\scriptsize]
%\tzhelplines(15,12)
\tzaxes(15,12){$x$}{$y$}
\def\bgt{-3/4*\x+9} % 3x+4y=36
\tzfn\bgt[0:12]
\tzvXpoint*{bgt}(6,0)(A){A}[45]
\tzplotcurve"ICC"(3,9)(A)(12,3); % trial and error
\tzproj(A){$x^*$}{$y^*$}
\tzticks{12}{9}
\end{tikzpicture}
\end{tzcode}


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.15,font=\scriptsize]
%\tzhelplines(35,25)
\tzaxes(35,25){$x$}{$y$}
\def\bgt{-2/3*\x+20} % 2x+3y=60
\def\IC{150/\x}      % u(x,y)=xy
\tzfn\bgt[0:30]
\tzfn\IC[7:30]
\tzcoor*(15,10)(E){$E$}[45]
\tzproj(E)
\tzticks{15,30}{10,20}
\tzvXpointat*[red]{IC}{12}(A)
\tztangent[blue,densely dashed]{IC}(A)[5:20]
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{Production Possibility Curves}
\label{si:PPC}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
\tzhelplines(9,8)
\tzaxes(9,8){$X$}{$Y$}
\tzto[out=-10,in=105]"PPC"(0,7)(6,0){PPC}[ar]
\tzvXpointat*{PPC}{2}(E)
\tztangent[blue]"tan"{PPC}(E)[0:8]
\tzvXpointat*{tan}{4}(F)
\tzplotcurve[densely dashed,red](2,7)(F)(8,4);
\end{tikzpicture}
\end{tzcode}




%%------------------------------------------------------------
\section{Edgeworth box}
\label{si:edgeworth}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(9,7)
\tzaxes(9,7){$x_1$}{$y_1$}
\tzaxes<8,6>(8,6)(-1,-1){$x_2$}[l]{$y_2$}[b]
\tzshoworigin{$O_1$}
\tzshoworigin(8,6){$O_2$}[ar]
\tzto[bend right](2,5)(7,2){$u_1$}[r]
\tzto[bend left](1,4)(6,1){$u_2$}[b]
\end{tikzpicture}
\end{tzcode}


%%------------------------------------------------------------
\section{Growth}
\label{si:growth}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(10,8)
\tzshoworigin
\tzaxes*(10,8){$k$}{$y$} % bounding box
\def\Fk{3*(\x)^(1/3)}
\def\sFk{2*(\x)^(1/3)}
\def\ndk{7/9*\x}
\tzfn\Fk[0:9]{$y=f(k)$}[r]       % name path=Fk
\tzfn\sFk[0:9]{$sf(k)$}[r]       % name path=sFk
\tzfn\ndk[0:9]{$(n+\delta)k$}[r] % name path=ndk
\tzXpoint*{sFk}{ndk}(E)[2]{$E$}[135] % (E)=(E-2)
\tzvXpoint*{Fk}(E)(YE)           % 2nd X point
\tzproj(YE){$k^*$}{$y^*$}
\tzvXpointat*{Fk}{2}(A)
\tzvXpointat*{sFk}{2}(B)
\tzvXpointat*{ndk}{2}(C)
\tzproj(A){$k_0$}{$y_0$}
\tzprojy(B){$sf(k_0)$}
\tzprojy(C){$(n+\delta)k_0$}
\end{tikzpicture}
\end{tzcode}



%%------------------------------------------------------------
\section{Liquidity trap}
\label{si:trap}

\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(10,8)
\tzshoworigin
\tzaxes(10,8){$Y$}{$r$}
\tzline"LM"(1,2)(5,2)
\tzto[out=0,in=-95](5,2)(8,6){$LM$}[a]
\tzto[dashed,out=0,in=-95](5,2)(9.5,6){$LM'$}[a]
\tzLFn"IS"(4,2){-1}[5:1]{$IS$}[a]
\tzLFn[dashed]<1,0>"ISa"(4,2){-1}[5:1]{$IS'$}[a] %%
\tzXpoint{IS}{LM}(E)
\tzXpoint{ISa}{LM}(E1)
\tzproj(E){$Y^*$}{$r_0$}
\tzprojx(E1){$Y'$}
\end{tikzpicture}
\end{tzcode}

$LM$ curves are drawn with two paths.
To shift the $IS$ curve, |<shift coor>| is used. See Section \ref{s:tzLFn} on page \pageref{s:tzLFn} for more details.


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=.5,font=\scriptsize]
%\tzhelplines(10,8)
\tzshoworigin
\tzaxes(10,8){$m$}{$r$}
\tzto[out=-88,in=180](1,7)(5,2)
    <--(9,2) node [r] {$m^d$}> % code.append
\tzvfnat{5}[0:6]{$m^s_0$}[a]
\tzvfnat{6.5}[0:6]{$m^s_1$}[a]
\tzvfnat{8}[0:6]{$m^s_2$}[a]
\tzprojy(5,2){$r_0$}
\tzticksx{5/{$m_0$},6.5/{$m_1$},8/{$m_2$}}
\end{tikzpicture}
\end{tzcode}

The money demand ($m_d$) curve is drawn with one path.
To do this, |<code.append>| is used.
See Section \ref{s:tzto} on page \pageref{s:tzto} for more details.


%%------------------------------------------------------------
\section{Miscellany}
\label{si:misc}


\begin{tzcode}{.3}
\begin{tikzpicture}[font=\scriptsize]
\def\z{1}
\tzcoors
 (0,0)(A)
 ($(A) + (45:\z)$)(B)
 ($(B) + (45:\z)$)(C)
 ($(A) + (-45:\z)$)(D)
 ($(D) + (45:\z)$)(E)
 ($(E) + (45:\z)$)(F)
 ($(D) + (-45:\z)$)(G)
 ($(G) + (45:\z)$)(H)
 ($(H) + (45:\z)$)(I);

\foreach \a in {A,...,I}
 { \tzdot*(\a){\a}
 }

\tzlines(D)(A)(B)(C)(F)(E)(D)(G)(H)(I)(F);
\tzlines[red](B)(E)(H);
\end{tikzpicture}
\end{tzcode}



\begin{tzcode}{.3}
\begin{tikzpicture}[scale=1,font=\scriptsize]
\tzaxes(4,4){alternatives}{preferences}
\tzticksx{1/$a$,2/$b$,3/$c$}
\tzplot[mark=ball](1,3)(2,2)(3,1){A}[0];
\tzplot[mark=*]   (1,2)(2,1)(3,3){B}[0];
\tzplot[mark=+]   (1,1)(2,3)(3,2){C}[0];
\end{tikzpicture}
\end{tzcode}


\begin{tzcode}{.3}
\begin{tikzpicture}[scale=1,font=\scriptsize]
\tzaxes(4,4){alternatives}{preferences}
\tzticksx{1/$a$,2/$b$,3/$c$}
\foreach \x in {1,2,3}
 {\foreach \y in {1,2,3}
   {\tzdot*(\x,\y)}
 }
\tzlines(1,3)(2,2)(3,1){A}[r];
\tzlines(1,2)(2,1)(3,3){B}[r];
\tzlines(1,1)(2,3)(3,2){C}[r];
\end{tikzpicture}
\end{tzcode}