%\subsection{Pencil-and-Paper Example}
%Figure \ref{pencil} contains two panels, one for each firm's value function. To create it, we use the \textsc{pgfplots} package of \cite{manual2008Feuersanger} to make an axis for each panel and then draw the value functions directly using the equilibrium entry thresholds, exit thresholds, and value functions calculated by |pencil.m| and saved in |pgfTikZ/ac2apencilConstants.tex|. The following |TikZ| code requires those constants to be defined, and a|tikzpicture| environment must enclose it. For example
%\input[25..27]{ac2apencilWrapper.tex}

%The code below resides within |/compute/pgfTikZ|.\footnote{The ``file'' |ac2apencilColor.tex| within |/compute| is only a link to the file used by LaTeX when compiling the program.} 

%\subsubsection{Top Panel}
%We begin with opening the first axis, which contains the value function for a firm with rank 1. We set several |TikZ| keys to control the axes appearance, including the location, style, and labeling of tick marks.

\begin{axis}[width=4.5in,height=2.5in,
  title=First Entrant's Value Function,	% Title placed over the axis.
  name=v1, 	%An axis name used to place the next axis.
  ylabel={},						
  axis x line=bottom,	%Place the x-axis at the bottom of the plotted area.
  every outer x axis line/.append style={-,color=gray,line width=0.75pt},
  axis y line=left,		%Place the y-axis at the left of the ploted area
  every outer y axis line/.append style={-,color=gray,line width=0.75pt},
  %Place x-axis tick marks at $\hat{C}$, $\underline{C}_1$, $\overline{C}_1$, and $\check{C}$.
  xtick={\pencilChat,\pencilCunderbarOne,\pencilCoverbarOne,\pencilCcheck},
  %Only label the middle two tick marks. Manually adjust the second one's vertical offset.
  xticklabels={$ $,\raisebox{-2.3mm}{$\underline{C}_1$},$\overline{C}_1$, $ $},
  %Place y-axis tick marks at 0, $\varphi(i)$, and $v(0,\overline{C}_2,1)$.
  ytick={0,\pencilPhiOne,\pencilVOneOneCoverbarTwo},
  %Only label the first two tick marks.
  yticklabels={$0$,\makebox[0pt][r]{$\varphi(1)$},$ $},
  %Style the tick marks.
  major tick length=2.5mm,
  every tick/.append style={line width=0.75pt},
 %Set the plotted area's horizontal and vertical limits.
   xmin=\pencilChat,
  xmax=\pencilCcheck,
  ymin=0,
  ymax=\pencilVOneOneCoverbarTwo]
%\paragraph{The cost of entry}
%The next task at hand is to draw the horizontal line demarking the cost of the first firm's entry. We do this with the |axis| coordinate system, which selects points based on their locations in the Cartisian plane (See page 21 of \cite{manual2008Feuersanger} ).
  \draw[color=gray,line width=0.75pt,dashed]
   (axis cs:\pencilChat,\pencilPhiOne) -- (axis cs:\pencilCcheck,\pencilPhiOne);
%\paragraph{Plot of $v(N,C,1)$}
%We now proceed to plot $v(0,C,1)$ and $v(1,C,1)$. Each of these is piecewise linear with exactly one discontinuity. Since they overlap outside of $[\underline{C}_2,\overline{C}_2]$, it is useful to conceive of them as consisting of two branches. The ``monopoly'' branch plots $v(0,C,1)$ over $[\hat{C},\overline{C}_2]$. This is flat from $\hat{C}$ to $\underline{C}_1$ and thereafter slopes up at the rate $\pi(1)/(1-\beta(1-\lambda)$. To draw this, we simply connect two points on each line segments using the |\\path| command. The line is colored black to distinguish it from the gray helper lines. We give two of these points names for later use using the |coordinate| directive. 
  \path[draw,color=black,line width=0.75pt]
   (axis cs: \pencilChat,0) -- (axis cs: \pencilCunderbarOne,0) coordinate (monopolyMin) 
   -- (axis cs: \pencilCoverbarTwo,\pencilVOneOneCoverbarTwo) coordinate (monopolyMax);
%The ``duopoly'' branch, which gives $v(1,C,1)$ over $[\underline{C}_2,\check{C}]$ completes the two value functions. Its red color distinguishes it from the monopoly branch.
  \path[draw,color=red!75,line width=0.75pt] 
   (axis cs: \pencilCunderbarTwo,\pencilVOneTwoCunderbarTwo) coordinate (duopolyMin) 
   -- (axis cs: \pencilCcheck,\pencilVOneTwoCcheck) coordinate (duopolyMax);
%\paragraph{Transition Arrows}
% As $C$ passes through $\overline{C}_2$,  the change in the potential entrant's actual entry decision causes $v(0,C,1)$ to drop discontinously. We denote this discontinuity with a gray vertical array from the monopoly branch to the duopoly branch. Its origin is at the point we denoted above with |monopolyMax|. Theoretically, its destination is where the duopoly branch crosses a vertical line from |monopolyMax| to the x axis. We calculate this point using the intersection coordinate system of TikZ. Practically, the arrow looks better if we end it just above this point.

  %Find the intersection of interest.
  \path(axis cs:\pencilCoverbarTwo,0) coordinate (Xaxis1);
  \path(intersection cs:
   first line={(duopolyMin)--(duopolyMax)},
   second line={(monopolyMax) -- (Xaxis1)}) coordinate
   (duopolyEntry);
   %Set the arrow's target slightly above this intersection.
  \path(duopolyEntry) ++ (0,5pt) coordinate(duopolyTarget); 
  %Draw the arrow.
  \draw[-stealth,dashed,line width=0.5pt,color=gray] (monopolyMax) -- (duopolyTarget);

%The analogous discontinuity in $v(1,C,1)$ associated with a younger rival's exit occurs at $\underline{C}_2$.  Again, the arrow's source coordinate is in hand, |duopolyMin|. Its destination is at the intersection of the monopoly branch with a vertical line through |duopolyMin|. We place the arrow tip just below this point.

  %Find the intersection of interest.
  \path(axis cs:\pencilCunderbarTwo,0) coordinate (Xaxis2);
  \path(intersection cs:
   first line={(monopolyMin)--(monopolyMax)},
   second line={(duopolyMin)--(Xaxis2)}) coordinate (monopolyExit);
   %Set the arrow's target slightly below this intersection.
  \path(monopolyExit) ++ (0,-5pt) coordinate (monopolyTarget);
  %Draw the arrow. 
  \draw[-stealth,dashed,line width=0.5pt,color=gray] (duopolyMin) -- (monopolyTarget);

%\paragraph{The Legend}
% To aid the reader, we create a legend to label the two value-function branches. Rather than rely on the legend-creation capabilities of \textsc{pgfplots}, we create our own by placing a similar line next to a textual explanation. The first task is to calculate the beginning and end points for the line in the monopoly branch's legend entry. We place its start point 4/5 of the way up the vertical axis and half way from the origin to $\underline{C}_1$. To calculate these points, we use |\\pgfmathsetmacro| and the |axis| coordinate system.

  \pgfmathsetmacro{\legendxOne}{0.5*(\pencilCunderbarOne-\pencilChat)}
  \pgfmathsetmacro{\legendyOne}{0.8*\pencilVOneOneCoverbarTwo}
  \path(axis cs: \legendxOne,\legendyOne) coordinate (legendStartMonopoly);

%The line rises at the slope $\pi(1)$, which is saved in |\\pencilPiOne|, and ends just above $\underline{C}_1$.

   \pgfmathsetmacro{\legendyTwo}{\legendyOne+\pencilPiOne*\pencilCunderbarOne*0.5}
   \pgfmathsetmacro{\legendxTwo}{\pencilCunderbarOne}
   \path(axis cs: \legendxTwo,\legendyTwo) coordinate(legendStopMonopoly);

%We place the text for the monopoly branch's legend entry to the right of $\underline{C}_1$.
   \pgfmathsetmacro{\legendxThree}{2*\pencilCunderbarOne}
   \pgfmathsetmacro{\legendyThree}{\legendyOne+\pencilPiOne*\pencilCunderbarOne*0.25}
   \path(axis cs: \legendxThree,\legendyThree) coordinate (legendTextMonopoly);

%With the coordinates in hand, we draw the legend entry and place its label text.
   \path[draw,color=black,line width=0.75pt] 
    (legendStartMonopoly) -- (legendStopMonopoly) 
    (legendTextMonopoly) node{Monopoly Branch};

%The duopoly branch's legend entry locations are just those from the monopoly branch shifted down by half a centemeter.

   \path(legendStartMonopoly) ++(0,-0.5cm) coordinate (legendStartDuopoly);
   \path(legendStopMonopoly) ++(0,-0.5cm) coordinate (legendStopDuopoly);
   \path(legendTextMonopoly) ++(0,-0.5cm) coordinate (legendTextDuopoly);

   \draw[color=red!75,line width=0.75pt] (legendStartDuopoly) -- (legendStopDuopoly) 
    (legendTextDuopoly) node[color=black]{Duopoly Branch};

%The words ``Monopoly Branch'' and ``Duopoly Branch'' are centered in their nodes. It would be great to left-justify them so that their left-ends were properly aligned. In any case, this panel and its corresponding |axis| environment are complete.

\end{axis}

%\subsubsection{Bottom Panel}
% The bottom panel gives the value function of a firm with rank 2. This is considerably simpler to plot. We begin by calculating a point below the top panel for its location. 
\path(v1.origin) ++(0,-2.50in) coordinate (v2 plot position);
%As before, we use the |axis| environment to create the bottom panel.
\begin{axis}[width=4.5in,height=2.5in,
    title=Second Entrant's Value Function,
    name=v2,
    at = {(v2 plot position)},
    anchor={origin},
    ylabel={},
    axis x line=bottom,
    every outer x axis line/.append style={-,color=gray,line width=0.75pt},
    axis y line=left,
    every outer y axis line/.append style={-,color=gray,line width=0.75pt},
    %We place x-axis tick marks at $\hat{C}$, $\underline{C}_2$, $\overline{C}_2$, and $\check{C}.$
    xtick={\pencilChat,\pencilCunderbarTwo,\pencilCoverbarTwo,\pencilCcheck},
    %All four x-axis tick marks get labels.
    xticklabels={$\hat{C} $,\raisebox{-2.3mm}{$\underline{C}_2$},
	$\overline{C}_2$, $\check{C}$},
    ytick={0,\pencilPhiTwo,\pencilVOneOneCoverbarTwo},
    yticklabels={$0$,\makebox[0pt][r]{$\varphi(2)$},$ $},
    major tick length=2.5mm,
    every tick/.append style={line width=0.75pt},
    ymin=0,
    ymax=\pencilVOneOneCoverbarTwo,
    xmin=\pencilChat,
    xmax=\pencilCcheck]

%The actual plotting of the cost of entry and the value function is very straightforward.
    \draw[color=gray,line width=0.75pt,dashed] 
     (axis cs:\pencilChat,\pencilPhiOne) -- (axis cs:\pencilCcheck,\pencilPhiOne);

    \draw[color=black,line width=0.75pt] (axis cs: \pencilChat,0) 
     -- (axis cs: \pencilCunderbarTwo,0) 
     -- (axis cs: \pencilCcheck,\pencilVTwoCcheck);

%The bottom panel is done, so close the axis environment
\end{axis}
