From 10c2dbef5e9981d697e700ece7d40ba303f35303 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 7 Nov 2020 22:01:51 +0000 Subject: causets (7nov20) git-svn-id: svn://tug.org/texlive/trunk@56872 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/causets/causets.sty | 408 ++++++++++++++++++++++++ 1 file changed, 408 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/causets/causets.sty (limited to 'Master/texmf-dist/tex/latex/causets/causets.sty') diff --git a/Master/texmf-dist/tex/latex/causets/causets.sty b/Master/texmf-dist/tex/latex/causets/causets.sty new file mode 100644 index 00000000000..778c0784e3a --- /dev/null +++ b/Master/texmf-dist/tex/latex/causets/causets.sty @@ -0,0 +1,408 @@ +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{causets}[2020/10/25 Package to draw causal set diagrams] +%% Copyright 2020 by C. Minz +% +% This work may be distributed and/or modified under the +% conditions of the LaTeX Project Public License, either version 1.3 +% of this license or (at your option) any later version. +% The latest version of this license is in +% http://www.latex-project.org/lppl.txt +% +% This work has the LPPL maintenance status "maintained". +% +% The Current Maintainer of this work is C. Minz. +% https://github.com/c-minz +% +% This work consists of the files causets.sty, causets.tex, +% causets.pdf, causet_tikz_example1.tex, causet_tikz_example1.pdf, +% causet_tikz_example2.tex, causet_tikz_example2.pdf + +\RequirePackage{tikz} + +%% size options: +\newcommand*{\causetsSetSizes}[6]{% +\def\causetTileSize{#1}% +\def\causetRegionLine{#2}% +\def\causetGridLine{#3}% +\def\causetEventSize{#4}% +\def\causetLinkWidth{#5}% +\def\causetTextScale{#6}% +} +\newcommand*{\tinycausets}{% +\causetsSetSizes{0.30ex}{0.02ex}{0.01ex}{0.16ex}{0.05ex}{0.16}} +\newcommand*{\smallcausets}{% +\causetsSetSizes{0.60ex}{0.04ex}{0.02ex}{0.32ex}{0.10ex}{0.32}} +\newcommand*{\normalcausets}{% +\causetsSetSizes{0.90ex}{0.06ex}{0.03ex}{0.48ex}{0.15ex}{0.48}} +\newcommand*{\largecausets}{% +\causetsSetSizes{1.35ex}{0.09ex}{0.05ex}{0.75ex}{0.20ex}{0.75}} +\newcommand*{\hugecausets}{% +\causetsSetSizes{1.80ex}{0.12ex}{0.07ex}{1.00ex}{0.25ex}{1.00}} + +%% color options: +\newcommand*{\causetsSetColorsBlack}{% + \colorlet{causetRegionColor}{black}% + \colorlet{causetGridColor}{black}% + \colorlet{causetTileColor}{white}% + \colorlet{causetEventColor}{black}% + \colorlet{causetLabelColor}{black}% + \colorlet{causetLinkColor}{black}% + \colorlet{causetSeparationColor}{black}% + \colorlet{causetULabelColor}{black}% + \colorlet{causetVLabelColor}{black}% +} +\newcommand*{\causetsSetColorsGray}{% + \colorlet{causetRegionColor}{black!75}% + \colorlet{causetGridColor}{black!25}% + \colorlet{causetTileColor}{black!10!white}% + \colorlet{causetEventColor}{black}% + \colorlet{causetLabelColor}{black}% + \colorlet{causetLinkColor}{black!65!white}% + \colorlet{causetSeparationColor}{black!50!white}% + \colorlet{causetULabelColor}{black!65!white}% + \colorlet{causetVLabelColor}{black!65!white}% +} +\newcommand*{\causetsSetColorsBlue}{% + \colorlet{causetRegionColor}{black!75}% + \colorlet{causetGridColor}{black!25}% + \colorlet{causetTileColor}{yellow!75!black!50!white}% + \colorlet{causetEventColor}{blue!50!black}% + \colorlet{causetLabelColor}{blue!50!black}% + \colorlet{causetLinkColor}{cyan!75!black}% + \colorlet{causetSeparationColor}{red!65!black}% + \colorlet{causetULabelColor}{black!50}% + \colorlet{causetVLabelColor}{black!50}% +} +\newcommand*{\causetsSetColorsNeon}{% + \colorlet{causetRegionColor}{black}% + \colorlet{causetGridColor}{green}% + \colorlet{causetTileColor}{yellow}% + \colorlet{causetEventColor}{blue}% + \colorlet{causetLabelColor}{blue}% + \colorlet{causetLinkColor}{cyan}% + \colorlet{causetSeparationColor}{red}% + \colorlet{causetULabelColor}{magenta}% + \colorlet{causetVLabelColor}{magenta}% +} + +%% switches: +\newif\ifcausetsDrawPermutation +\newif\ifcausetsDrawLabels +\newif\ifcausetsDrawLinks +\newif\ifcausetsDrawSeparations + +%% delare and execute options: +\providecommand{\causetsDirectory}{causets.standalone} +\normalcausets +\causetsSetColorsGray +\causetsDrawLinkstrue +\DeclareOption{gray}{\causetsSetColorsGray} +\DeclareOption{black}{\causetsSetColorsBlack} +\DeclareOption{blue}{\causetsSetColorsBlue} +\DeclareOption{neon}{\causetsSetColorsNeon} +\DeclareOption{permutation}{\causetsDrawPermutationtrue} +\DeclareOption{labeled}{\causetsDrawLabelstrue} +\DeclareOption{spacelike}{\causetsDrawSeparationstrue} +\DeclareOption{unlinked}{\causetsDrawLinksfalse} +\DeclareOption{tiny}{\tinycausets} +\DeclareOption{small}{\smallcausets} +\DeclareOption{large}{\largecausets} +\DeclareOption{huge}{\hugecausets} +\DeclareOption*{\PackageWarning{causets}{The package causets does not support the option: \CurrentOption}} +\ProcessOptions\relax + +%% TikZ styles: +\tikzset{causet/.style={baseline=-0.707*\causetTileSize}} +\tikzset{causetRegion/.style={}} +\tikzset{causetGrid/.style={}} +\tikzset{causetTiles/.style={}} +\tikzset{causetEvents/.style={}} +\tikzset{causetLabels/.style={}} +\tikzset{causetLinks/.style={}} +\tikzset{causetSeparations/.style={}} +\tikzset{causetULabels/.style={}} +\tikzset{causetVLabels/.style={}} +\tikzset{causetRegionStyle/.style={causetRegionColor, line width=\causetRegionLine, causetRegion}} +\tikzset{causetGridStyle/.style={causetGridColor, line width=\causetGridLine, step=\causetTileSize, causetGrid}} +\tikzset{causetTilesStyle/.style={causetTileColor, line width=\causetGridLine, fill, causetTiles}} +\tikzset{causetEventsStyle/.style={causetEventColor, circle, fill, inner sep=0pt, minimum size=\causetEventSize, causetEvents}} +\tikzset{causetLabelsStyle/.style={causetLabelColor, below left, text opacity=1.0, inner sep=0pt, scale=\causetTextScale, causetLabels}} +\tikzset{causetLinksStyle/.style={causetLinkColor, line width=\causetLinkWidth, arrows=-, causetLinks}} +\tikzset{causetSeparationsStyle/.style={causetSeparationColor, line width=\causetLinkWidth, dashed, causetSeparations}} +\tikzset{causetULabelsStyle/.style={causetULabelColor, right=-\causetTextScale*0.5ex, scale=\causetTextScale, rotate=-45, align=left, causetULabels}} +\tikzset{causetVLabelsStyle/.style={causetVLabelColor, left=-\causetTextScale*0.5ex, scale=\causetTextScale, rotate=45, align=right, causetVLabels}} + +%% functions: +% variables: +\newcounter{causet@i} +\newcounter{causet@j} +\newif\ifcauset@ItemFoundInList + +% count the number of events: +\newcommand*{\causets@readCausetSize}[1]{% +\setcounter{causet@i}{0}% +\foreach \causet@p in {#1}{% + \stepcounter{causet@i}% +}% +\pgfmathsetmacro\causet@N{\value{causet@i}}% +} + +% define and draw events as (E#): +\newcommand*{\causets@drawEvents}[1]{% +\setcounter{causet@i}{0} +\foreach \causet@p in {#1}{% + \stepcounter{causet@i} + \pgfmathsetmacro\causet@e@U{\causet@p - 1.0} + \pgfmathsetmacro\causet@e@V{\value{causet@i} - 1.0} + \ifcausetsDrawPermutation + \path[causetTilesStyle] ( \causet@e@U * \causetTileSize, \causet@e@V * \causetTileSize ) + rectangle +( \causetTileSize, \causetTileSize ); + \fi + \pgfmathsetmacro\causet@e@U{\causet@p - 0.5} + \pgfmathsetmacro\causet@e@V{\value{causet@i} - 0.5} + \node[causetEventsStyle] (E\causet@p) + at ( \causet@e@U * \causetTileSize, \causet@e@V * \causetTileSize ) + {}; +} +} + +% draw the permutation and the null coordinate labels: +\newcommand*{\causets@drawPermutation}[1]{% +\ifcausetsDrawPermutation + \draw[causetGridStyle] ( 0, 0 ) + grid ( \causet@N * \causetTileSize, \causet@N * \causetTileSize ); + \draw[causetRegionStyle] ( 0, 0 ) + rectangle ( \causet@N * \causetTileSize, \causet@N * \causetTileSize ); + \setcounter{causet@i}{0} + \foreach \causet@p in {#1}{% + \stepcounter{causet@i} + \node[causetULabelsStyle] (EUL\causet@p) + at ( \value{causet@i} * \causetTileSize - 0.5 * \causetTileSize, 0 ) + {\thecauset@i}; + \node[causetVLabelsStyle] (EVL\causet@p) + at ( 0, \value{causet@i} * \causetTileSize - 0.5 * \causetTileSize ) + {\causet@p}; + } +\fi +} + +% draw event labels: +\newcommand*{\causets@drawEventLabels}[1]{% +\ifcausetsDrawLabels + \foreach \causet@p in {#1}{% + \node[causetLabelsStyle] (EL\causet@p) + at (E\causet@p.south west) {\causet@p}; + } +\fi +} + +% draw a causet from a permutation: +\newcommand*{\drawpcauset}[1]{% +\causets@readCausetSize{#1} +\begin{scope}[rotate=45] + \begin{scope}[xshift=-\causet@N * \causetTileSize / 2, + yshift=-\causet@N * \causetTileSize / 2] + \causets@drawEvents{#1} + \causets@drawPermutation{#1} + \ifcausetsDrawLinks + \setcounter{causet@i}{0} + \foreach \causet@p in {#1}{% + \stepcounter{causet@i} + \pgfmathsetmacro\causet@qBound{int(\causet@N + 1)} + \setcounter{causet@j}{0} + \foreach \causet@q in {#1}{% + \stepcounter{causet@j} + \ifnum\value{causet@j}>\value{causet@i} + \ifnum\causet@q<\causet@qBound + \ifnum\causet@p<\causet@q + \draw[causetLinksStyle] (E\causet@p) -- (E\causet@q); + \xdef\causet@qBound{\causet@q} + \fi + \fi + \fi + } + } + \fi + \ifcausetsDrawSeparations + \setcounter{causet@i}{0} + \foreach \causet@p in {#1}{% + \stepcounter{causet@i} + \edef\causet@qBound{0} + \setcounter{causet@j}{0} + \foreach \causet@q in {#1}{% + \stepcounter{causet@j} + \ifnum\value{causet@j}>\value{causet@i} + \ifnum\causet@q>\causet@qBound + \ifnum\causet@p>\causet@q + \draw[causetSeparationsStyle] (E\causet@q) -- (E\causet@p); + \xdef\causet@qBound{\causet@q} + \fi + \fi + \fi + } + } + \fi + \causets@drawEventLabels{#1} + \end{scope} +\end{scope} +} + +% draw a causet from a permutation and a link-pair list: +\newcommand*{\drawcauset}[2]{% +\causets@readCausetSize{#1} +\begin{scope}[rotate=45] + \begin{scope}[xshift=-\causet@N * \causetTileSize / 2, + yshift=-\causet@N * \causetTileSize / 2] + \causets@drawEvents{#1} + \causets@drawPermutation{#1} + \ifcausetsDrawLinks + \foreach \causet@From/\causet@To in {#2}{% + \draw[causetLinksStyle] (E\causet@From) -- (E\causet@To); + } + \fi + \causets@drawEventLabels{#1} + \end{scope} +\end{scope} +} + +% draw a causet from a permutation removes links given in a link-pair list: +\newcommand*{\drawrcauset}[2]{% +\causets@readCausetSize{#1} +\begin{scope}[rotate=45] + \begin{scope}[xshift=-\causet@N * \causetTileSize / 2, + yshift=-\causet@N * \causetTileSize / 2] + \causets@drawEvents{#1} + \causets@drawPermutation{#1} + \ifcausetsDrawLinks + \setcounter{causet@i}{0} + \foreach \causet@p in {#1}{% + \stepcounter{causet@i} + \pgfmathsetmacro\causet@qBound{int(\causet@N + 1)} + \setcounter{causet@j}{0} + \foreach \causet@q in {#1}{ + \stepcounter{causet@j} + \ifnum\value{causet@j}>\value{causet@i} + \ifnum\causet@q<\causet@qBound + \ifnum\causet@p<\causet@q + \global\causet@ItemFoundInListfalse + \foreach \causet@From/\causet@To in {#2}{% + \pgfmathparse{and( equal( int(\causet@From), int(\causet@p) ), equal( int(\causet@To), int(\causet@q) ) )} + \ifnum\pgfmathresult=1 + \global\causet@ItemFoundInListtrue + \fi + } + \ifcauset@ItemFoundInList + % skip link + \else + \draw[causetLinksStyle] (E\causet@p) -- (E\causet@q); + \fi + \xdef\causet@qBound{\causet@q} + \fi + \fi + \fi + } + } + \fi + \causets@drawEventLabels{#1} + \end{scope} +\end{scope} +} + +% insert a TikZ picture with a causet from a permutation: +\newcommand*{\pcauset}[2][causet]{% +\begin{tikzpicture}[#1]\drawpcauset{#2}\end{tikzpicture}} + +% insert a TikZ picture with a causet from a permutation and a link-pair list: +\newcommand*{\causet}[3][causet]{% +\begin{tikzpicture}[#1]\drawcauset{#2}{#3}\end{tikzpicture}} + +% insert a TikZ picture with a causet from a permutation removes links given +% in a link-pair list: +\newcommand*{\rcauset}[3][causet]{% +\begin{tikzpicture}[#1]\drawrcauset{#2}{#3}\end{tikzpicture}} + +%% short-hand functions: +\newcommand*{\causetfile}[2][]{% +\includegraphics[#1]{\causetsDirectory/#2}} + +\newcommand*{\pcausetP}[2][causet]{% +{\causetsDrawPermutationtrue\pcauset[#1]{#2}}} + +\newcommand*{\pcausetL}[2][causet]{% +{\causetsDrawLabelstrue\pcauset[#1]{#2}}} + +\newcommand*{\pcausetX}[2][causet]{% +{\causetsDrawPermutationtrue\pcausetL[#1]{#2}}} + +\newcommand*{\causetP}[3][causet]{% +{\causetsDrawPermutationtrue\causet[#1]{#2}{#3}}} + +\newcommand*{\causetL}[3][causet]{% +{\causetsDrawLabelstrue\causet[#1]{#2}{#3}}} + +\newcommand*{\causetX}[3][causet]{% +{\causetsDrawPermutationtrue\causetL[#1]{#2}{#3}}} + +\newcommand*{\rcausetP}[3][causet]{% +{\causetsDrawPermutationtrue\rcauset[#1]{#2}{#3}}} + +\newcommand*{\rcausetL}[3][causet]{% +{\causetsDrawLabelstrue\rcauset[#1]{#2}{#3}}} + +\newcommand*{\rcausetX}[3][causet]{% +{\causetsDrawPermutationtrue\rcausetL[#1]{#2}{#3}}} + +%% some standard causets: +\newcommand*{\causetFence}[2][causet]{% +\ifcase#2% +\or%=1 +\pcauset[#1]{1,2}% +\or%=2 +\pcauset[#1]{3,1,4,2}% +\or%=3 +\pcauset[#1]{5,3,6,1,4,2}% +\or%=4 +\pcauset[#1]{7,5,8,3,6,1,4,2}% +\or%=5 +\pcauset[#1]{9,7,10,5,8,3,6,1,4,2}% +\or%=6 +\pcauset[#1]{11,9,12,7,10,5,8,3,6,1,4,2}% +\or%=7 +\pcauset[#1]{13,11,14,9,12,7,10,5,8,3,6,1,4,2}% +\or%=8 +\pcauset[#1]{15,13,16,11,14,9,12,7,10,5,8,3,6,1,4,2}% +\or%=9 +\pcauset[#1]{17,15,18,13,16,11,14,9,12,7,10,5,8,3,6,1,4,2}% +\or%=10 +\pcauset[#1]{19,17,20,15,18,13,16,11,14,9,12,7,10,5,8,3,6,1,4,2}% +\fi% +} + +\newcommand*{\causetClosedFence}[2][causet]{% +\ifcase#2% +\or%=1 +\pcauset[#1]{1,2}% +\or%=2 +\pcauset[#1]{2,1,4,3}% +\or%=3 +\rcauset[#1]{4,2,6,1,5,3}{2/5}% +\or%=4 +\rcauset[#1]{6,4,8,2,7,1,5,3}{2/5,4/7}% +\or%=5 +\rcauset[#1]{8,6,10,4,9,2,7,1,5,3}{2/5,4/7,6/9}% +\or%=6 +\rcauset[#1]{10,8,12,6,11,4,9,2,7,1,5,3}{2/5,4/7,6/9,8/11}% +\or%=7 +\rcauset[#1]{12,10,14,8,13,6,11,4,9,2,7,1,5,3}{2/5,4/7,6/9,8/11,10/13}% +\or%=8 +\rcauset[#1]{14,12,16,10,15,8,13,6,11,4,9,2,7,1,5,3}{2/5,4/7,6/9,8/11,10/13,12/15}% +\or%=9 +\rcauset[#1]{16,14,18,12,17,10,15,8,13,6,11,4,9,2,7,1,5,3}{2/5,4/7,6/9,8/11,10/13,12/15,14/17}% +\or%=10 +\rcauset[#1]{18,16,20,14,19,12,17,10,15,8,13,6,11,4,9,2,7,1,5,3}{2/5,4/7,6/9,8/11,10/13,12/15,14/17,16/19}% +\fi% +} + +\newcommand*{\causetCrown}[1][causet]{% +\causetClosedFence[#1]{3}% +} -- cgit v1.2.3