summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bondgraphs/bondgraphs.sty
blob: 0fcf4c50015005ab69def646a5b2d956b7973abe (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
%%
%% This is file `bondgraphs.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bondgraphs.dtx  (with options: `package')
%% This is a generated file.
%% 
%% Copyright (C) ⟨2014⟩ by ⟨Geert Folkertsma⟩
%% This file 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 2008/05/04 or later.
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bondgraphs}[2015/03/23 v1.0.1 TikZ-based Bond graphs formatting package]
\RequirePackage{tikz}[2013/12/13]
\usetikzlibrary{arrows,arrows.meta,decorations.pathreplacing}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\RequirePackage{amsfonts}
\RequirePackage{bm}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=bondgraphs,prefix=bondgraphs@}
\DeclareStringOption[blue]{labelcolour}
\DeclareStringOption[green!50!black]{bondlabelcolour}
\DeclareBoolOption[false]{grey}
\DeclareComplementaryOption{colour}{grey}
\DeclareBoolOption[false]{curly}
\ProcessLocalKeyvalOptions{bondgraphs}
\ifbondgraphs@grey
  \message{Bondgraphs package: greyscale set}
  \colorlet{diff}{black!60!white}
  \colorlet{error}{black!40!white}
  \def\bondgraphs@labelcolour{black!50!white}
  \def\bondgraphs@bondlabelcolour{black!50!white}
  %TODO: would be nice to have this as a style instead of a colour...
\else
  \message{Bondgraphs package: using colour}
  \colorlet{diff}{orange}
  \colorlet{error}{red}
\fi
\tikzset{bond/.style args={#1}{
  decoration={show path construction,
    lineto code={
    \draw[#1,thick]
      \pgfextra{%       +45 i.s.o. -1 for to left or to under, always
        \pgfmathparse{int((\pgfdecoratedangle-1)/90)}
        \ifcase\pgfmathresult
          \ifbondgraphs@curly
            \tikzset{-{Classical TikZ Rightarrow[length=3 2 0.8,right]}}
          \else
            \tikzset{-{Straight Barb[length=3 2 0.8,right]}}
          \fi
        \or
          \ifbondgraphs@curly
            \tikzset{-{Classical TikZ Rightarrow[length=3 2 0.8,left]}}
          \else
            \tikzset{-{Straight Barb[length=3 2 0.8,left]}}
          \fi
        \or
          \ifbondgraphs@curly
            \tikzset{-{Classical TikZ Rightarrow[length=3 2 0.8,left]}}
          \else
            \tikzset{-{Straight Barb[length=3 2 0.8,left]}}
          \fi
        \else
          \ifbondgraphs@curly
            \tikzset{-{Classical TikZ Rightarrow[length=3 2 0.8,right]}}
          \else
            \tikzset{-{Straight Barb[length=3 2 0.8,right]}}
          \fi
        \fi
      }  (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
    }
  },
  postaction=decorate
},
bond/.default={}
}
\tikzset{mbond/.style={bond={double,#1}}}
\tikzset{bonds/.style={every edge/.append style={bond}}}
\tikzset{
  bondlabel/.style={
    font=\small,
    color=\bondgraphs@bondlabelcolour,
    sloped,
  },
  effort/.style args={#1}{
    edge node={node [bondlabel,above]{#1}}
  },
  effort/.default={},
  flow/.style args={#1}{
    edge node={node [bondlabel,below]{#1}}
  },
  flow/.default={}
}
\tikzset{
  e_out/.style args={#1}{
    -{|[line width=1.2pt,width=7pt,#1]}
  },
  e_out/.default={black},
  f_in/.style args={#1}{
    e_out={#1}
  },
  e_in/.style args={#1}{
    {|[line width=1.2pt,width=7pt,#1]}-
  },
  e_in/.default={black},
  f_out/.style args={#1}{
    e_in={#1}
  }
}
\newcommand\bond[1][]{%
  \tikz \draw(0,0) edge[bond,#1] (1,0);
}
\tikzset{
  bgelement/.style={
    font=\bfseries,
    prefix after command= {\pgfextra{
      \tikzset{every label/.style={
        % Element label style
        \bondgraphs@labelcolour,
        font={\mdseries}
      }
    }}}
  }
}
\tikzset{
  multiport/.style={
    execute at begin node=$\mathbb\bgroup,
    execute at end node=\egroup$
  }
}
\tikzset{
  wordbgelement/.style={
    draw,ellipse,minimum size=12pt,thick,font=\mdseries
  }
}
\newif\ifbondgraphs@bgelement@multiport
\newif\ifbondgraphs@bgelement@wordbg
\pgfkeys{
  /bgelement/.is family, %automatically cd to /bgelement when present
  /bgelement/n/.store in=\bondgraphs@bgelement@n,
  /bgelement/n=1,
  %
  /bgelement/multiport/.is if=bondgraphs@bgelement@multiport,
  /bgelement/multiport=false,
  /bgelement/wordbg/.is if=bondgraphs@bgelement@wordbg,
  /bgelement/wordbg=false,
}
\newcommand\bgelement[2][]{%
  \pgfkeys{/bgelement,multiport=false,wordbg=false,#1}%
  \ifbondgraphs@bgelement@wordbg
    \tikz[baseline=(the_elm.base)] \node[wordbgelement] (the_elm) {#2};%
  \else
    \ifbondgraphs@bgelement@multiport
      \ifnum\bondgraphs@bgelement@n=1
        \ensuremath{\mathbb{#2}}%
      \else
        \ensuremath{\mathbb{#2}_{\bondgraphs@bgelement@n}}%
      \fi
    \else
      \ifnum\bondgraphs@bgelement@n=1
        \textrm{\textbf{#2}}%
      \else
        \textrm{\textbf{#2}$_{\bondgraphs@bgelement@n}$}%
      \fi
    \fi
  \fi
}
\newenvironment{bondgraph}[1][]{%
\begin{tikzpicture}%
  [#1,every node/.style={bgelement},every edge/.append style={bond}]%
}{%
\end{tikzpicture}
}
\endinput
%%
%% End of file `bondgraphs.sty'.