-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmd-graphics.sty
254 lines (221 loc) · 6.45 KB
/
nmd-graphics.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
%%% Code for graphics.
%%%
%%% Two options: tikz and xy
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{nmd/nmd-graphics}[2014/08/31 - Semester start edition]
\RequirePackage{nmd/nmd-common}
\newboolean{tikz}
\newboolean{xy}
\DeclareOption{xy}{\xytrue}
\DeclareOption{tikz}{\tikztrue}
\ProcessOptions
%%% Always load the basics
\RequirePackage{graphicx, color}
\RequirePackage{xcolor}
%%% My colors
\definecolor{nmdlight}{cmyk}{0.128, 0.176, 0.0, 0.0}
\definecolor{nmdmedium}{cmyk}{0.41, 0.49, 0.06, 0.0}
\definecolor{nmddark}{rgb}{0.1, 0.0, 0.5}
% Same colors in rgb and HTML formats
%
% nmdlight {0.872, 0.824, 1} #DED2FF
% nmdmedium {0.59, 0.51, 0.94} #9682F0
% nmddark {0.1, 0, 0.5} #1A0080
%%% TikZ addons
\iftikz
\RequirePackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{intersections}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{decorations.pathreplacing}
% USAGE:
%
% \begin{tikzpicture}
% \begin{tikzoverlay*}[<graphics opts>]{file name}
% (TikZ commands in coordinate system where horizontal direction is 100)
% \end{tikzoverlay*}
% \end{tikzpicture}
%
% This is a variant of the tikzoverlay environment defined below. It
% is sometimes advantageous to have the tikzpicture command be
% explicit, e.g. it is compatible with TikZ's externalize library.
\newenvironment{tikzoverlay*}[2][]{%
\node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\newdimen\nmd@tikzoverlaywidth
\pgfextractx{\nmd@tikzoverlaywidth}{\pgfpointanchor{image}{south east}}
\begin{scope}
\tikzset{x=0.01\nmd@tikzoverlaywidth}
\tikzset{y=0.01\nmd@tikzoverlaywidth}
}{
\end{scope}
}
% USAGE: \begin{tikzoverlay}[<graphics opts>]{file name}[tikz opts]
% (tikz commands in coordinate system where horizontal
% direction is 100)
% \end{tikzoverlay}
%
% The variant tikzoverlayabs uses coordinates going from (0,0) to (1,1).
%
% Modeled on
%
% http://bazaar.launchpad.net/~tex-sx/tex-sx/development/view/head:/onimage.dtx
\def\tikzoverlay{%
\pgfutil@ifnextchar[{\tikzoverlay@opt}{\tikzoveraly@opt[]}%
}
\def\tikzoverlay@opt[#1]#2{%
\begin{tikzpicture}
\node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\newdimen\nmd@tikzoverlaywidth
\pgfextractx{\nmd@tikzoverlaywidth}{\pgfpointanchor{image}{south east}}
\begin{scope}
\tikzset{x=0.01\nmd@tikzoverlaywidth}
\tikzset{y=0.01\nmd@tikzoverlaywidth}
}
\def\endtikzoverlay{%
\end{scope}
\end{tikzpicture}
}
\def\tikzoverlayabs{%
\pgfutil@ifnextchar[{\tikzoverlayabs@opt}{\tikzoveralyabs@opt[]}%
}
\def\tikzoverlayabs@opt[#1]#2{%
\begin{tikzpicture}
\node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[#1]{#2}};
\begin{scope}
\tikzset{x=(image.south east)}
\tikzset{y=(image.north west)}
}
\def\endtikzoverlayabs{%
\end{scope}
\end{tikzpicture}
}
%%% Including Matplotlib figures with TikZ overlay
\pgfkeys{
/matplotlibfigure/.is family, /matplotlibfigure,
default/.style = {width = 0.95\textwidth, font = \footnotesize},
width/.store in = \matplotlibfigurewidth,
font/.store in = \matplotlibfigurefont,
}
\newcommand{\matplotlibfigure}[2][]{%
\pgfkeys{/matplotlibfigure, default, #1}%
\input{plots/#2}
}
% Basic default for all my TikZ pictures
\tikzset{%
nmdstd/.style={%
line join=round,
line cap=round,
font=\footnotesize,
% My preferred arrow has length 1pt + 5*(line width) and
% width equal to its height.
>={Computer Modern Rightarrow[length=1pt 5, width'=0pt 1]},
}
}
% Default style for labels on subfigures
\tikzset{%
subfig label/.style={%
font=\small
}
}
% Draw an arrow somewhere along a path
\tikzset{%
mid arrow/.style={postaction={
decorate,
decoration={markings,
mark=at position #1 with {\arrow{>}}}
}}
}
% Add a coordinate somewhere along a path
\tikzset{%
add coordinate/.style 2 args={postaction={
decorate,
decoration={markings,
mark=at position #1 with {\coordinate (#2);}}
}}
}
% Show the control points for the Bezier curves
\tikzset{%
show controls/.style={
postaction={
decoration={
show path construction,
curveto code={
\draw [blue, -]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentsupporta)
(\tikzinputsegmentlast) -- (\tikzinputsegmentsupportb);
\fill [red, opacity=0.5]
(\tikzinputsegmentsupporta) circle [radius=.5ex]
(\tikzinputsegmentsupportb) circle [radius=.5ex];
}
},
decorate
}}}
% Add a tangent vector along a curve
\tikzset{%
tangent vector/.style 2 args={
postaction={
decorate,
decoration={markings,
mark=at position #1 with {\draw (0, 0) -- (#2, 0);}}
}}
}
% Add a normal vector along a curve
\tikzset{%
normal vector/.style 2 args={
postaction={
decorate,
decoration={markings,
mark=at position #1 with {\draw (0, 0) -- (0, #2);}}
}}
}
% Add a vector along a curve
\tikzset{%
vector along/.style 2 args={
postaction={
decorate,
decoration={markings,
mark=at position #1 with {\draw (0, 0) -- #2;}}
}}
}
% Specifying Bezier curves in a relatively comprehensible way.
\newcommand{\easybezier}[6]{%
#1 .. controls ($#1!#4!#3:#2$) and ($#2!#6!#5:#1$) .. #2
}
% Drawing a grid in the upper quadrant to measure stuff against
\newcommand{\measurementgrid}[2]{%
\begin{scope}
\begin{scope}[line width=0.2pt, color=blue!30]
\draw[dashed, step=0.5] (0, 0) grid (#1, #2);
\draw[step=1] (0, 0) grid (#1, #2);
\end{scope}
\begin{scope}[font=\scriptsize, color=black!40]
\foreach \x in {0,1,...,#1}{
\node[below] at (\x, 0) {\x};
}
\foreach \y in {0,1,...,#2}{
\node[left] at (0,\y) {\y};
}
\end{scope}
\end{scope}
}
\fi % End \iftikz
% Nathan's XY-pic based label overlay environment. The usual version
% is the second one below. Args are: coor system, graphics modifiers,
% graphics name. Deprecated.
\ifxy
\RequirePackage[all,import,rotate]{xy}
\newenvironment{xyoverpic}[3]
{%
\begin{xy}
\xyimport#1{\includegraphics[#2]{#3}}
}{\end{xy}}
\newenvironment{cxyoverpic}[3]
{%
\begin{center}
\centering\leavevmode\small
\begin{xyoverpic}{#1}{#2}{#3}
}{\end{xyoverpic}
\end{center}}
\fi