summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/memorygraphs
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-12-28 23:26:11 +0000
committerKarl Berry <karl@freefriends.org>2018-12-28 23:26:11 +0000
commitb725313018cecaf42e1e195dccf34e44ae02b30e (patch)
treedfd21f2a9db07901d6485f7847a1bcca167544b0 /Master/texmf-dist/tex/latex/memorygraphs
parent5f5e3b734fe79b18115c591ba0d2b1a789e7678a (diff)
memorygraphs (27dec18)
git-svn-id: svn://tug.org/texlive/trunk@49518 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/memorygraphs')
-rw-r--r--Master/texmf-dist/tex/latex/memorygraphs/memorygraphs.sty159
1 files changed, 159 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/memorygraphs/memorygraphs.sty b/Master/texmf-dist/tex/latex/memorygraphs/memorygraphs.sty
new file mode 100644
index 00000000000..bcd5286b718
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/memorygraphs/memorygraphs.sty
@@ -0,0 +1,159 @@
+%% memorygraphs.tex
+%% Copyright 2018 C. Staps
+%
+% 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
+% and version 1.3 or later is part of all distributions of LaTeX
+% version 2005/12/01 or later.
+%
+% This work has the LPPL maintenance status “maintained”.
+%
+% The Current Maintainer of this work is C. Staps.
+%
+% This work consists of the files memorygraphs.sty and the documentation in
+% memorygraphs.tex and example-fibonacci.tex.
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{memorygraphs}[2018/12/26 v0.1 Draw memory graphs using TikZ]
+
+\RequirePackage{tikz}
+\usetikzlibrary{arrows.meta,calc,positioning,shapes}
+
+\def\pgfaddtoshape#1#2{%
+ \begingroup
+ \def\pgf@sm@shape@name{#1}%
+ #2%
+ \endgroup
+}
+
+\pgfaddtoshape{rectangle split}{%
+ \pgfmathsetcount\c@pgf@counta{\pgfkeysvalueof{/pgf/rectangle split parts}}%
+ \edef\parts{\the\c@pgf@counta}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@head north east\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@one split north\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@head south east\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@one split south\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@head north west\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@north west\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@head south west\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@south west\endcsname}%
+ \pgfmathloop%
+ \ifnum\pgfmathcounter>\parts%
+ \else%
+ \pgf@lib@sh@getalpha\pgf@lib@sh@rs@number{\pgfmathcounter}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@\pgf@lib@sh@rs@number\space center\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@\pgf@lib@sh@rs@number\space north\endcsname%
+ \pgf@ya=\pgf@y%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@\pgf@lib@sh@rs@number\space south\endcsname%
+ \advance\pgf@ya by-\pgf@y%
+ \advance\pgf@y by.5\pgf@ya}%
+ \c@pgf@counta=\pgfmathcounter%
+ \advance\c@pgf@counta by-1\relax%
+ \edef\name{\ifnum\c@pgf@counta=0 head\else arg \the\c@pgf@counta\fi}%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@\name\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@\pgf@lib@sh@rs@number\endcsname}%
+ \pgfutil@for\pgf@lib@sh@rs@temp:={center,north,east,south,west}\do{%
+ \expandafter\xdef\csname pgf@anchor@rectangle split@\name\space\pgf@lib@sh@rs@temp\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle split@\pgf@lib@sh@rs@number\space\pgf@lib@sh@rs@temp\endcsname}}%
+ \repeatpgfmathloop%
+}
+\pgfaddtoshape{rectangle}{%
+ \expandafter\xdef\csname pgf@anchor@rectangle@head north east\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle@north east\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle@head south east\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle@south east\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle@head north west\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle@north west\endcsname}%
+ \expandafter\xdef\csname pgf@anchor@rectangle@head south west\endcsname{%
+ \expandafter\noexpand\csname pgf@anchor@rectangle@south west\endcsname}%
+}
+
+\newcommand{\memorygraphs@arg}[1]{%
+ \pgfmathsetcount\c@pgf@counta{#1}%
+ \advance\c@pgf@counta by1\relax%
+ \expandafter\nodepart\expandafter{\expandafter\pgf@lib@sh@toalpha\expandafter{\the\c@pgf@counta}}}
+
+\newdimen\memorygraphs@marklength
+\memorygraphs@marklength=4pt
+
+\tikzset{
+ memory graph/.style={
+ node distance=1.5em,
+ },
+ every block/.style={},
+ block/.style={
+ draw,
+ text height=height("I"),
+ text depth=depth("I"),
+ anchor=mid,
+ every block,
+ },
+ block/.append code={\let\arg\memorygraphs@arg},
+ block mark north east/.style={
+ append after command={
+ \pgfextra
+ \pgfinterruptpath
+ \draw[#1]
+ ($(\tikzlastnode.head north east)-(0,.5\pgflinewidth)$)
+ -- +(0,-\memorygraphs@marklength)
+ -- ($(\tikzlastnode.head north east)-(0+\memorygraphs@marklength,.5\pgflinewidth)$)
+ -- cycle;
+ \endpgfinterruptpath
+ \endpgfextra
+ },
+ },
+ block mark south east/.style={
+ append after command={
+ \pgfextra
+ \pgfinterruptpath
+ \draw[#1]
+ ($(\tikzlastnode.head south east)+(0,.5\pgflinewidth)$)
+ -- +(0,\memorygraphs@marklength)
+ -- ($(\tikzlastnode.head south east)+(0-\memorygraphs@marklength,.5\pgflinewidth)$)
+ -- cycle;
+ \endpgfinterruptpath
+ \endpgfextra
+ },
+ },
+ block mark north west/.style={
+ append after command={
+ \pgfextra
+ \pgfinterruptpath
+ \draw[#1]
+ ($(\tikzlastnode.head north west)+(.5\pgflinewidth,-.5\pgflinewidth)$)
+ -- +(0,-\memorygraphs@marklength)
+ -- ($(\tikzlastnode.head north west)-(-.5\pgflinewidth-\memorygraphs@marklength,.5\pgflinewidth)$)
+ -- cycle;
+ \endpgfinterruptpath
+ \endpgfextra
+ },
+ },
+ block mark south west/.style={
+ append after command={
+ \pgfextra
+ \pgfinterruptpath
+ \draw[#1]
+ ($(\tikzlastnode.head south west)+(.5\pgflinewidth,.5\pgflinewidth)$)
+ -- +(0,\memorygraphs@marklength)
+ -- ($(\tikzlastnode.head south west)+(.5\pgflinewidth+\memorygraphs@marklength,.5\pgflinewidth)$)
+ -- cycle;
+ \endpgfinterruptpath
+ \endpgfextra
+ },
+ },
+ arity/.style={
+ block,
+ rectangle split,
+ rectangle split parts=#1+1,
+ rectangle split horizontal,
+ rectangle split every empty part={},
+ rectangle split empty part width=.2em,
+ },
+ ref/.style={
+ {Circle[length=3pt]}-Latex,
+ shorten <=-1.5pt,
+ rounded corners=.2em,
+ },
+}