summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/ptolemaicastronomy/ptolemaicastronomy.dtx
blob: e00111ae4bead007b0ae4814f6a79c42fdf48b71 (plain)
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
% \iffalse meta-comment
% vim: textwidth=75
%<*internal>
\iffalse
%</internal>
%<*readme>
ptolemaicastronomy
==================

Diagrams of sphere models for variably strict conditionals (Lewis
counterfactuals)

Author: Richard Zach  
E-mail: rzach@ucalgary.ca  
License: Released under the LaTeX Project Public License v1.3c or later  
See: http://www.latex-project.org/lppl.txt

David K. Lewis (Counterfactuals, Blackwell 1973) introduced a sphere
semantics for counterfactual conditionals. He jokingly referred to the
diagrams depicting such sphere models as Ptolemaic astronomy, hence
the name of this package. It has nothing to do with Ptolemy or with
astronomy, sorry.

The macros provided in this package aid in the construction of
sphere model diagrams in the style of Lewis. The macros all make use
of TikZ.

See https://github.com/rzach/ptolemaic-astronomy

%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble

ptolemaicastronomy
==================

Diagrams of sphere models for variably strict conditionals (Lewis
counterfactuals)

Author: Richard Zach
E-mail: rzach@ucalgary.ca
License: Released under the LaTeX Project Public License v1.3c or later
See: http://www.latex-project.org/lppl.txt

David K. Lewis (Counterfactuals, Blackwell 1973) introduced a sphere
semantics for counterfactual conditionals. He jokingly referred to the
diagrams depicting such sphere models as Ptolemaic astronomy, hence
the name of this package. It has nothing to do with Ptolemy or with
astronomy, sorry.

The macros provided in this package aid in the construction of
sphere model diagrams in the style of Lewis. The macros all make use
of TikZ.

for documentation and source code see
https://github.com/rzach/ptolemaic-astronomy

\endpreamble
\usedir{tex/latex/ptolemaicastronomy}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/ptolemaicastronomy}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/ptolemaicastronomy}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{ptolemaicastronomy.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{ptolemaicastronomy}
%<*package>
    [2018/04/08 v1.00 Diagrams of sphere models for variably strict conditionals (Lewis counterfactuals)]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[numbered]{hypdoc}
\usepackage{\jobname}
\usepackage{lstdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.dtx}
% \DoNotIndex{\newcommand,\newenvironment}
%
%\title{\textsf{ptolemaicastronomy} --- Diagrams of sphere models for variably strict conditionals (Lewis counterfactuals)\thanks{This file
%   describes version \fileversion, last revised \filedate.}
%}
%\author{Richard Zach\thanks{\href{http://richardzach.org/}{richardzach.org}, E-mail: rzach@ucalgary.ca}}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v1.00}{2018/04/08}{First public release}
%
% \section{Introduction}

% Lewis\footnote{David K. Lewis, \emph{Counterfactuals} (Blackwell
% 1973)} introduced a sphere semantics for counterfactual
% conditionals. He jokingly referred to the diagrams depicting such
% sphere models as ``Ptolemaic astronomy,'' hence the name of this
% package. It has nothing to do with Ptolemy or with astronomy, sorry.

% The macros provided in this package aid in the construction of
% sphere model diagrams in the style of Lewis. The macros all make use
% of \href{https://ctan.org/tex-archive/graphics/pgf/}{Ti\emph{k}Z}.

% Source code can be found at \url{https://github.com/rzach/ptolemaic-astronomy}
%
% \section{Usage}
%
% \DescribeMacro{\spheresystem}
% To draw a sphere system with \meta{n} layers, say
% \cmd{\spheresystem}\marg{n}:
% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \spheresystem{5}
%    \end{tikzpicture}
% \end{lstsample}
% The width of each layer is determined by the TikZ parameter
% \verb|layerwidth| and defaults to $.5$ TikZ units (so $0.5$ cm by
% default). The radius of the center sphere is \emph{not}
% \verb|layerwidth|, but $\verb|layerwidth| \times (1 -
% \verb|innerfactor|)$. \verb|innerfactor| defaults to $0.4$.
% Spheres are drawn in \verb|dotted| style by default. You can change
% this by passing an option to \cmd{\spheresystem}, e.g.,
% to get red, dashed, thick lines and wider layers:
% \begin{lstsample}{}{}
%     \begin{tikzpicture}
%       \spheresystem[dashed, red,
%          thick, layerwidth=.75]{3}
%     \end{tikzpicture}
% \end{lstsample}
% \DescribeMacro{\spherelayer} \DescribeMacro{\spherefill} These
% macros shade the \meta{n}-th layer of the sphere model, or the
% entire \meta{n}-th sphere. The fill defaults to \verb|lightgray| and
% can be changed with \oarg{options}. Note that the fill extends to the
% center of the layer boundary line, so you should fill first and then
% draw the spheres. For instance:
% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \spherelayer{3}
%      \spherefill[yellow]{1}
%      \spheresystem[densely dashed]{3}
%    \end{tikzpicture}
% \end{lstsample}
% \DescribeMacro{\proposition}
% \DescribeMacro{\propositionintersect}

% A proposition is a set of worlds which (usually) intersects with a
% sphere system. A common way of drawing them is as a parabola, and
% often we want to highlight the intersection of the proposition with
% the closest sphere with which it intersects.
% \cmd{\proposition}\marg{direction}\marg{n}\marg{width}\marg{length}
% will draw such a parabola. \meta{direction} is the angle (0 is due
% east and 90 is due north) from which you want the proposition to
% reach into the sphere system. \meta{n} is the innermost layer you
% want it to intersect. \meta{width} and \meta{length} describe the
% triangle with apex \meta{width} degrees and sides of length
% \meta{length}. Use \cmd{\propositionintersect} to also highlight the
% intersection with the \meta{n}-th sphere. E.g., here are
% propositions that intersects the 3rd layer at 45 degrees, with a
% width of 20, 40, and 60 degrees, and the intersection of the first
% one with the innermost sphere it intersects.

% With the \verb|shift| option you can also position propositions outside the center, e.g., a proposition extending from the north through the west side of the sphere system would use, say, \verb|shift={(-1,-1)}|.

% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \propositionintersect{45}{3}{20}{3}
%      \proposition{45}{3}{40}{3}
%      \proposition{45}{3}{60}{3}
%      \proposition[shift={(-1,-1)}]{90}{1}{20}{4}
%      \spheresystem{5}
%    \end{tikzpicture}
% \end{lstsample}

% The degree of ``pointedness'' of propositions is determined by the
% \verb|tension| parameter, which defaults to $1.7$. Larger values
% make the proposition more bulgy, smaller values more pointy.

% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \proposition[green,
%         proposition/.style={tension=3}]{0}{3}{80}{3}
%      \proposition{0}{3}{80}{3}
%      \proposition[red,
%         proposition/.style={tension=1}]{0}{3}{80}{3}
%      \proposition[blue,
%         proposition/.style={tension=.5}]{0}{3}{80}{3}
%      \spheresystem{5}
%    \end{tikzpicture}
% \end{lstsample}

% \DescribeMacro{\spherepos}
% \cmd{\spherepos}\marg{direction}\marg{n}\marg{code} moves to a
% position in the center of layer \meta{n} in \meta{direction} and
% then executes TikZ \verb|path| code \meta{code}. It's useful to put
% labels or other things into the sphere system.

% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \propositionintersect{45}{3}{20}{3}
%      \spheresystem{5}
%      \spherepos[fill,red]{45}{3}{circle[radius=.1]}
%      \spherepos{90}{4}{node {$w$}}
%      \spherepos{45}{6.5}{node {$\varphi$}}
%    \end{tikzpicture}
% \end{lstsample}

% \DescribeMacro{\sphereintersect} \cmd{\propositionintersect} uses
% \cmd{\sphereintersect}\oarg{options}\marg{n}\marg{code} to fill the
% area between the parabola and the outside edge of the \meta{n}-th
% sphere. (More precisely: what happens is that the area between the
% parabola and the line between its two endpoints is set as the
% clipping path, and then TikZ only shows the part of the shaded
% sphere within that clipping path.) That macro can also be used to
% intersect the respective layer with other paths, and in cases where
% the convex closure of the proposition does not include enough area.
% In that case, the clipping region has to be extended, and the path
% drawn separately. The example below shows what happens when a very
% wide parabola does not completely intersect with a sphere (on the
% right), how to use the trick to get the fill right (on the left), as
% well as how to intersect a more complex path with a sphere.

% \begin{lstsample}{}{}
%    \begin{tikzpicture}
%      \propositionintersect{0}{3}{140}{3}
%      \sphereintersect{3}{\propositionplot{180}{3}{140}{3} -- (-2,-2)}
%      \proposition{180}{3}{140}{3}
%      \sphereintersect{4}{plot[smooth] coordinates
%          {(1.5,2) (2.5,1) (1.5,0) (2.5,-1) (1.5,-2) (2.5,-3)}}
%      \draw[red] plot[smooth] coordinates
%          {(1.5,2) (2.5,1) (1.5,0) (2.5,-1) (1.5,-2) (2.5,-3)} ;
%      \spheresystem{5}
%    \end{tikzpicture}
% \end{lstsample}

% Finally, a complex example: the Sobel sequence diagram, Figure~2 from Lewis, p.~11:
% \begin{lstsample}{}{}
%    \begin{tikzpicture}[scale=.8]\small
%      % wider layers, pointier propositions
%      \tikzset{layerwidth=1,innerfactor=0,
%               proposition/.style={smooth,tension=1}}
%      % fill the areas between three props and their innermost spheres
%      \sphereintersect{3}{\propositionplot{30}{3.3}{30}{4}}
%      \sphereintersect{2}{\propositionplot{30}{2.3}{45}{4}}
%      \sphereintersect{1}{\propositionplot{30}{1.3}{60}{4}}
%      % draw the sphere system
%      \spheresystem{3}
%      % draw the propositions
%      \draw \propositionplot{30}{3.3}{30}{4};
%      \draw \propositionplot{30}{2.3}{45}{4};
%      \draw \propositionplot{30}{1.3}{60}{4};
%      % draw \psi (coordinates figured out by trial and error)
%      \draw plot[smooth,tension=1.2]
%        coordinates {(-1.5,3) (1.2,-1) (.8,2.3) (2.8,.7) (3,4)};
%      % draw and label the center world, spheres, and propositions
%      \filldraw circle[radius=.05];
%      \node at (-.2,-.2) {$i$};
%      \spherepos{-70}{1.8}{node {$S^1_i$}}
%      \spherepos{-70}{2.8}{node {$S^2_i$}}
%      \spherepos{-70}{3.8}{node {$S^3_i$}}
%      \spherepos{4}{4.3}{node {$\phi_1$}
%                         node at +(0,.5) {$\phi_2$}
%                         node at +(0,1) {$\phi_3$}}
%      \spherepos{80}{4}{node {$\psi$}}
%    \end{tikzpicture}
% \end{lstsample}

%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\RequirePackage{tikz}

\tikzset{
  sphere/.style = {dotted},
  sphere intersection/.style = {fill=lightgray},
  sphere layer/.style = {fill=lightgray},
  proposition/.style={smooth,tension=1.7},
}
%    \end{macrocode}
% \begin{macro}{layerwidth}
% \begin{macro}{innerfactor}
% TikZ parameters used to compute the sphere radii and can be set
% using TikZ's options mechanism or using \cmd{\tikzset}.
%    \begin{macrocode}
\pgfkeyssetvalue{/tikz/layerwidth}{.5}
\pgfkeyssetvalue{/tikz/innerfactor}{.4}
%    \end{macrocode}
% \end{macro}\end{macro}
% \begin{macro}{\sphereplot}
% \cmd{\sphereplot}\marg{n} gives the plot codes for the \meta{n}-th sphere
%    \begin{macrocode}
\newcommand{\sphereplot}[1]{
  circle
    [radius=(#1)*\pgfkeysvalueof{/tikz/layerwidth}-
      \pgfkeysvalueof{/tikz/layerwidth}*\pgfkeysvalueof{/tikz/innerfactor}]
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\spheresystem}
% \cmd{\spheresystem}\oarg{options}\marg{n} draws a sphere system centered at
% the origin with \meta{n} number of layers
%
%    \begin{macrocode}
\newcommand{\spheresystem}[2][]{
  \foreach \i in {1,...,#2}{
    \draw[sphere,#1] \sphereplot{\i} ;
  }
}
%    \end{macrocode}
% \end{macro}
%

%
%
% \begin{macro}{\spherelayer}
% \cmd{\spherelayer}\oarg{options}\marg{n} shades the \meta{n}-th layer
%    \begin{macrocode}
\newcommand{\spherelayer}[2][]{
  \begin{scope}[even odd rule]
    \fill[#1,sphere layer]
    \sphereplot{#2-1} \sphereplot{#2} ;
  \end{scope}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\spherefill}
%
% \cmd{\spherefill}\oarg{options}\marg{n} fills the \meta{n}-th sphere
%
%    \begin{macrocode}
\newcommand{\spherefill}[2][]{
    \fill[sphere intersection,#1]
    \sphereplot{#2} ;
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\sphereintersect}
% \cmd{\sphereintersect}\oarg{options}\marg{n}\marg{path} shades the
% area between \meta{path} and the the \meta{n}-th sphere
% layer. Options only apply to the sphere layer.
% \begin{macrocode}
\newcommand{\sphereintersect}[3][]{
  \begin{scope}[even odd rule]
    \path[clip] #3;
    \spherefill[#1]{#2}
  \end{scope}
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\propositionplot}
% \cmd{\propositionplot}\oarg{options}\marg{direction}\marg{n}\marg{width}\marg{length}
% produces the \verb|plot| code for a proposition intersecting the \meta{n}-th layer in angle \meta{direction}
% away from the center of the sphere system, with endpoints \meta{length}
% away from the center at an angle of $\meta{direction} \pm \meta{width}/2$.
%    \begin{macrocode}
\newcommand{\propositionplot}[4]{
  plot [proposition]
  coordinates {+(#1+#3/2:#4)
    +(#1:#2*\pgfkeysvalueof{/tikz/layerwidth}-
    \pgfkeysvalueof{/tikz/layerwidth}*.9
    -\pgfkeysvalueof{/tikz/layerwidth}*\pgfkeysvalueof{/tikz/innerfactor})
    +(#1-#3/2:#4)}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\proposition}
% \cmd{\proposition}\oarg{options}\marg{direction}\marg{n}\marg{width}\marg{length}
% actually draws the proposition. Note that \meta{options} applies to
% \cmd{\draw}, not to \cs{plot}. 
%    \begin{macrocode}
\newcommand{\proposition}[5][]{
  \draw[proposition,#1] \propositionplot {#2}{#3}{#4}{#5} ;
  }
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\propositionintersect}
% \cmd{\spherepropositionintersect} does the same as \cmd{\sphereproposition} but
% also shades the area of intersection with the \meta{n}-th sphere.
%
%    \begin{macrocode}
\newcommand{\propositionintersect}[5][]{
  \begin{scope}
  \path[clip] \propositionplot{#2}{#3}{#4}{#5};
  \spherefill[#1]{#3}
  \end{scope}
  \draw[proposition,#1] \propositionplot{#2}{#3}{#4}{#5};
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\spherepos}
% \cmd{\spherepos}\oarg{options}\marg{direction}\marg{n}\marg{code}
% shifts the scope to a position in the center of the \meta{n}-th layer in
% direction angle from the center---and then puts a \meta{code} \verb|path|
% there.
%\begin{macrocode}
\newcommand{\spherepos}[4][]{
  \begin{scope}[shift=(#2:#3*\pgfkeysvalueof{/tikz/layerwidth}-
      \pgfkeysvalueof{/tikz/layerwidth}/2-
        \pgfkeysvalueof{/tikz/layerwidth}*\pgfkeysvalueof{/tikz/innerfactor})]
    \path[#1] #4 ;
  \end{scope}
}
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput