% PGF examples for Physical Mathematics I
% Ewan Stewart
% KAIST
% 2011/9/11

\documentclass[12pt,a4paper]{article}

\usepackage{pm1} % Physical Mathematics I style file
%\usepackage{tikz} % PGF figures (already loaded by the Physical Mathematics I style file)

\newcommand{\xyz}[4][0.1\textwidth]{
\pgfmathsetlengthmacro{\unit}{#1}
\pgfmathsetmacro{\xpx}{cos(#3)*cos(#2)}
\pgfmathsetmacro{\xpy}{cos(#4)*sin(#3)*cos(#2)+sin(#4)*sin(#2)}
\pgfmathsetmacro{\ypx}{-sin(#3)}
\pgfmathsetmacro{\ypy}{cos(#4)*cos(#3)}
\pgfmathsetmacro{\zpx}{cos(#3)*sin(#2)}
\pgfmathsetmacro{\zpy}{cos(#4)*sin(#3)*sin(#2)-sin(#4)*cos(#2)}
} % The command "\xyz[<unit length>]{<z-x plane rotation angle>}{<x-y plane rotation angle>}{<y-z plane rotation angle>}" sets the unit length "\unit" equal to its optional argument, which has a default value of 1/10 of the text width, and calculates the projection parameters "\xpx",...,"\zpy" from its three compulsary arguments.
\xyz{0}{0}{0} % Sets default values for "\xpx",...,"\zpy".
\tikzset{xyz/.style={x={(\xpx*\unit,\xpy*\unit)},y={(\ypx*\unit,\ypy*\unit)},z={(\zpx*\unit,\zpy*\unit)}}} % The TikZ style "xyz" sets the x,y,z vectors, projected onto the 2D document, in terms of the unit length "\unit" and the projection parameters "\xpx",...,"\zpy".

\newcommand{\axes}[2]{
\draw[->] (\xmin,\ymin) -- (\xmax,\ymin) -- ++ (10pt,0pt) node[right]{$#1$};
\draw[->] (\xmin,\ymin) -- (\xmin,\ymax) -- ++ (0pt,10pt) node[above]{$#2$};
}
\newcommand{\helplines}[2]{
\foreach \x in {#1} \draw[help lines] (\x,\ymin) -- (\x,\ymax);
\foreach \y in {#2} \draw[help lines] (\xmin,\y) -- (\xmax,\y);
}
\newcommand{\axislabels}[2]{
\foreach \x/\xlabel in {#1} \draw (\x,\ymin) -- ++(0pt,-2pt) node[below]{$\xlabel$};
\foreach \y/\ylabel in {#2} \draw (\xmin,\y) -- ++(-2pt,0pt) node[left]{$\ylabel$};
}
% Defines graph drawing commands.

\newcommand{\logaxes}[2]{
\draw[->] (\logxmin,\logymin) -- (\logxmax,\logymin) -- ++ (10pt,0pt) node[right]{$#1$};
\draw[->] (\logxmin,\logymin) -- (\logxmin,\logymax) -- ++ (0pt,10pt) node[above]{$#2$};
}
\newcommand{\loghelplines}[2]{
\foreach \log in {-0.6990,-0.5229,-0.3979,-0.3010,-0.2218,-0.1549,-0.0969,-0.0458,0}{
\foreach \logx in {#1} \draw[help lines] (\logx+\log,\logymin) -- (\logx+\log,\logymax);
\foreach \logy in {#2} \draw[help lines] (\logxmin,\logy+\log) -- (\logxmax,\logy+\log);
}}
\newcommand{\logaxislabels}[2]{
\foreach \logx/\logxlabel in {#1} \draw (\logx,\logymin) -- ++(0pt,-2pt) node[below]{$10^{\logxlabel}$};
\foreach \logy/\logylabel in {#2} \draw (\logxmin,\logy) -- ++(-2pt,0pt) node[left]{$10^{\logylabel}$};
}
\newcommand{\logplot}[3][red]{
\draw[#1] plot[domain=10^\logxmin:10^\logxmax] ({0.4343*ln(#2)},{0.4343*ln(#3)})
}
% Defines log-log graph drawing commands.


\title{\textbf{P}retty \textbf{G}ood \textbf{F}igures}
\author{Ewan Stewart}
\date{Physical Mathematics I \\ Fall \number\year}
% Information is entered logically and used appropriately by LaTeX.


\begin{document}

\maketitle % Generated from the information entered in the preamble.

\section{PGF examples}

\begin{figure}[h] % Begins a figure environment. The option "h" encourages LaTeX to put the figure here.
\centering % Centers the figure.
%
\tikzset{content/.style={thick,blue}} % Defines the TikZ style "content" to be "thick,blue".
\tikzset{style/.style={thick,red}}
\tikzset{latex/.style={thick,green}}
\tikzset{pgf/.style={brown}}
%
\begin{tikzpicture}[x=0.05\textwidth,y=0.05\textwidth] % Begins a TikZ picture environment. The option "x=0.05\textwidth" sets the x coordinate units to be 1/20 of the text width.
\fill[yellow!20] (0,0) -- (4,0) -- (4,4) -- cycle; % Fills the triangle {(0,0),(4,0),(4,4)} with 20% yellow and 80% white.
\draw[content] (0,0) -- node[below]{content} (4,0); % Draws a line from (0,0) to (4,0) and places a node, with text "content", below the line, all with style "content".
\draw[style] (4,0) -- node[right]{style} (4,4);
\draw[latex] (0,0) -- node(latex)[above left]{\LaTeX} (4,4); % "(latex)" labels the node "latex".
\path (latex.center) -- node[pgf]{PGF} (4,0); % Places a node, with style "pgf" and text "PGF", half way along the path joining the center of the node labelled "latex" with the coordinate (4,0).
\end{tikzpicture}
%
\caption{
$\textrm{PGF} \gg \textrm{JPEG, PNG}$.
}
\end{figure}


\begin{figure}[h]
\centering
%
\xyz{0}{20}{-70} % The command "\xyz[<unit length>]{<z-x plane rotation angle>}{<x-y plane rotation angle>}{<y-z plane rotation angle>}" is defined in the preamble.
%
\begin{tikzpicture}[xyz] % The TikZ style "xyz" is defined in the preamble.
% back side
\draw[fill=black!50,fill opacity=0.5] (-1,1,-1) -- (1,1,-1) -- (1,1,1) -- (-1,1,1) -- cycle;
% bottom side
\draw[fill=black!50,fill opacity=0.5] (-1,-1,-1) -- (-1,1,-1) -- (1,1,-1) -- (1,-1,-1) -- cycle;
% right side
\draw[fill=black!50,fill opacity=0.5] (1,-1,-1) -- (1,-1,1) -- (1,1,1) -- (1,1,-1) -- cycle;
% left side
\draw[fill=black!50,fill opacity=0.5] (-1,-1,-1) -- (-1,-1,1) -- (-1,1,1) -- (-1,1,-1) -- cycle;
% top side
\draw[fill=black!50,fill opacity=0.5] (-1,-1,1) -- (-1,1,1) -- (1,1,1) -- (1,-1,1) -- cycle;
% front side
\draw[fill=black!50,fill opacity=0.5] (-1,-1,-1) -- (1,-1,-1) -- (1,-1,1) -- (-1,-1,1) -- cycle;
% orientation
\draw[->] (-210:0.2) arc(-210:60:0.2); % drawn on the x-y plane in polar coordinates (\theta:r)
\draw[->] (0,0,-0.3) -- (0,0,0.3);
\end{tikzpicture}
\caption{
An oriented 3-volume.
}
\end{figure}


\begin{figure}[p] % The option "p" encourages LaTeX to put the figure on a separate page of figures.
\centering
%
\newcommand{\xmin}{0} % The parameter "\xmin" is defined and set to "0".
\newcommand{\xmax}{1000}
\newcommand{\ymin}{-0.15}
\newcommand{\ymax}{0.15}
%
\begin{tikzpicture}[x=0.0008\textwidth,y=2\textwidth]
% x = [0.8/(\xmax - \xmin)]\textwidth , y = [0.6/(\ymax - \ymin)]\textwidth
\axes{mt}{n_L/n_\mathrm{AD}}
\helplines{200,400,600,800,1000}{-0.1,-0.05,0,0.05,0.1,0.15}
\axislabels{0,200,400,600,800,1000}{-0.15,-0.1,-0.05,0,0.05,0.1,0.15}
% The graph drawing commands "\axes", "helplines" and "\axislabels" are defined in the preamble. 
\draw[red] plot file {figures/L+.dat}; % The data in the file "figures/L+.dat" is plotted as a red line.
\draw[green] plot file {figures/L0.dat};
\draw[blue] plot file {figures/L-.dat};
\end{tikzpicture}
%
\caption{
Lepton number generated at the end of thermal inflation.
}
\end{figure}


\begin{figure}[p]
\centering
%
\newcommand{\logxmin}{0}
\newcommand{\logxmax}{2}
\newcommand{\logymin}{0}
\newcommand{\logymax}{2}
%
\begin{tikzpicture}[x=0.2\textwidth,y=0.2\textwidth]
\logaxes{x}{\sqrt{x}}
\loghelplines{1,2}{1,2}
\logaxislabels{0,1,2}{0,1,2}
%
\logplot{\x}{sqrt(\x)};
\end{tikzpicture}
%
\caption{
A simple log-log plot.
}
\end{figure}


\begin{figure}[h]
\centering
%
\pgfdeclareimage[width=0.5\textwidth]{me}{figures/estewart.jpg}
\newcommand{\LeftLensX}{4.4}
\newcommand{\RightLensX}{6.3}
\newcommand{\LensY}{6.6}
\newcommand{\LensHalfWidth}{0.6}
\newcommand{\LensHalfHeight}{0.3}
\tikzset{glasses/.style={draw,line width=0.005\textwidth,brown!50!black}}
\tikzset{lens/.style={fill=red,fill opacity=0.5}}
%
\begin{tikzpicture}[x=0.05\textwidth,y=0.067\textwidth]
\pgftext[bottom,left]{\pgfuseimage{me}}
\path[glasses,lens] (\LeftLensX,\LensY) ellipse({\LensHalfWidth} and {\LensHalfHeight});
\path[glasses,lens] (\RightLensX,\LensY) ellipse({\LensHalfWidth} and {\LensHalfHeight});
\path[glasses] (\LeftLensX+\LensHalfWidth,\LensY) to[out=45,in=135] (\RightLensX-\LensHalfWidth,\LensY);
\path[glasses] (\LeftLensX-\LensHalfWidth,\LensY) -- (3.2,6.5);
\path[glasses] (\RightLensX+\LensHalfWidth,\LensY) -- (7.3,6.55);
\end{tikzpicture}
%
\caption{
Who is this guy?
}
\end{figure}


\end{document}