Debian Codegraph @

texmf-dist/tex/latex/tikz-dimline/tikz-dimline.sty

raw
1 %% Dimension line for LaTeX/TikZ
2 %% Copyright © 2013 Sébastien Gross <seb•ɑƬ•chezwam•ɖɵʈ•org>
3 %%
4 %% This file may be distributed and/or modified
5 %%
6 %% 1. under the LaTeX Project Public License and/or
7 %% 2. under the WTF Public License.
8 %%
9 %%
10 %% This simplify the creation drawing of dimension arrows.
11 %%
12 %%
13 %% To install it copy the tango directory to either:
14 %% - $TEXHOME/tex/latex/
15 %% - ~/texmf/tex/latex/
16 %% - ~/Library/texmf/tex/latex
17 %%
18
19 \NeedsTeXFormat{LaTeX2e}
20 \ProvidesPackage{tikz-dimline}[2013/03/13 v1.0 initial version]
21
22 \RequirePackage{tikz}
23 \RequirePackage{pgfplots}
24 \RequirePackage{ifthen}
25
26 \usetikzlibrary{calc,decorations.markings,arrows}
27
28 \makeatletter
29
30
31
32 \pgfkeys {
33 /dimline/.cd,
34 execute style/.style = {#1},
35 execute macro/.style = {/dimline/execute style/.expand once=#1},
36 }
37
38
39 \newdimen\dimline@arrow@linewidth
40
41 \pgfarrowsdeclare{dimline}{dimline}
42 {
43 \arrowsize=1\pgflinewidth
44 \pgfarrowsleftextend{0\arrowsize}
45 \pgfarrowsrightextend{5\arrowsize}
46 } {
47 \arrowsize=1\pgflinewidth
48 \pgfsetdash{}{0pt} % do not dash
49 % |
50 \pgfsetlinewidth{.5\arrowsize}
51 \pgfpathmoveto{\pgfpoint{4.75\arrowsize}{3\arrowsize}}
52 \pgfpathlineto{\pgfpoint{4.75\arrowsize}{-3\arrowsize}}
53 \pgfusepathqstroke
54 % >
55 \pgfsetlinewidth{0.01pt}
56 \pgfpathmoveto{\pgfpoint{4.5\arrowsize}{0pt}}
57 \pgfpathlineto{\pgfpoint{-3\arrowsize}{2\arrowsize}}
58 \pgfpathlineto{\pgfpoint{-3\arrowsize}{-2\arrowsize}}
59 \pgfpathclose
60 \pgfusepathqfillstroke
61 }
62
63
64 \pgfarrowsdeclare{dimline reverse}{dimline reverse}
65 {
66 \arrowsize=1\pgflinewidth
67 \pgfarrowsleftextend{-5\arrowsize}
68 \pgfarrowsrightextend{0\arrowsize}
69 } {
70 \arrowsize=1\pgflinewidth
71 \pgfsetdash{}{0pt} % do not dash
72 % |
73 \pgfsetlinewidth{0.5\arrowsize}
74 \pgfpathmoveto{\pgfpoint{-0.25\arrowsize}{3\arrowsize}}
75 \pgfpathlineto{\pgfpoint{-0.25\arrowsize}{-3\arrowsize}}
76 \pgfusepathqstroke
77 % >
78 \pgfsetlinewidth{0.01pt}
79 \pgfpathmoveto{\pgfpoint{0pt}{0pt}}
80 \pgfpathlineto{\pgfpoint{7.5\arrowsize}{2\arrowsize}}
81 \pgfpathlineto{\pgfpoint{7.5\arrowsize}{-2\arrowsize}}
82 \pgfpathclose
83 \pgfusepathqfillstroke
84 }
85
86
87 % measure lenght
88 % http://tex.stackexchange.com/questions/123913
89
90
91 \newcommand{\dimline@do@nothing}[1]{#1}%
92 % http://tex.stackexchange.com/questions/58283/tikz-how-to-determine-the-vector-between-two-co-ordinates
93
94
95 % #1: optional keys parameters
96 % #2: start point
97 % #3: end point
98 % #4: text
99 \newcommand{\dimline}[4][]{%
100
101 \pgfplotsifinaxis{%
102 \let\dimline@internal\pgfplotsextra%
103 }{%
104 \let\dimline@internal\dimline@do@nothing%
105 }%
106
107 \dimline@internal{
108 \pgfkeys{
109 dimline/.is family,
110 dimline,
111 color/.initial = black,
112 extension start length/.initial=1cm,
113 extension end length/.initial=1cm,
114 extension start angle/.initial=-90,
115 extension end angle/.initial=90,
116 line style/.initial = {},
117 label style/.initial = {},
118 extension style/.initial = {},
119 extension start style/.initial = {},
120 extension start path/.initial = {},
121 extension end style/.initial = {},
122 extension end path/.initial = {},
123 #1,
124 line style/.get = \dimline@line@style,
125 label style/.get = \dimline@label@style,
126 extension style/.get = \dimline@extension@style,
127 extension start style/.get = \dimline@extension@start@style,
128 extension start path/.get = \dimline@extension@start@path,
129 extension end style/.get = \dimline@extension@end@style,
130 extension end path/.get = \dimline@extension@end@path,
131 }
132
133 \begin{scope} [
134 line/.style = {
135 color=\pgfkeysvalueof{/dimline/color},
136 arrows=dimline-dimline,
137 /dimline/execute macro = \dimline@line@style,
138 },
139 extension/.style = {
140 color=\pgfkeysvalueof{/dimline/color}!40, line width=0.01,
141 /dimline/execute macro = \dimline@extension@style,
142 },
143 extension start/.style = {
144 extension,
145 /dimline/execute macro = \dimline@extension@start@style
146 },
147 extension end/.style = {
148 extension,
149 /dimline/execute macro = \dimline@extension@end@style,
150 },
151 label/.style = {
152 fill=white, align=center, sloped=true, pos=0.5,
153 /dimline/execute macro = \dimline@label@style
154 },
155 ]
156
157 \coordinate (a) at #2 {};
158 \coordinate (b) at #3 {};
159
160 \ifthenelse{\equal{\dimline@extension@start@path}{}}{
161 \coordinate (a to b) at ($(a)!\pgfkeysvalueof{/dimline/extension start length}!\pgfkeysvalueof{/dimline/extension start angle}:(b)$);
162 \draw [extension start] (a.center) -- (a to b);
163 } {
164 \draw [extension start] plot coordinates {\dimline@extension@start@path};
165 }
166
167 \ifthenelse{\equal{\dimline@extension@end@path}{}}{
168 \coordinate (b to a) at ($(b)!\pgfkeysvalueof{/dimline/extension end length}!\pgfkeysvalueof{/dimline/extension end angle}:(a)$);
169 \draw [extension end] (b.center) -- (b to a);
170 } {
171 \draw [extension end] plot coordinates {\dimline@extension@end@path};
172 }
173
174 \draw[line] (a.center) -- (b.center) node[label] {#4};
175 \end{scope}
176 }
177 }
178
179
180
181 \@ifclassloaded{beamer}{%
182 \renewcommand<>{\dimline}[4][]{\only#5{\beameroriginal{\dimline}[#1]{#2}{#3}{#4}}}
183 }
184 \makeatother
185
186
187 \endinput
188 %% tikz-dimline.sty ends here.
189