summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tikz-imagelabels/tikz-imagelabels.sty
blob: 8f5e8d46298d3b090eaebd36d2218b4123f1d93a (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
%%
%% This is file `tikz-imagelabels.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tikz-imagelabels.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2019 by Tobias Plüss <tpluess@ieee.org>
%% 
%% 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.
%% 
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{tikz-imagelabels}
  [2019/01/29 v0.1 put labels on images using TikZ]
\RequirePackage{tikz}
\RequirePackage{xifthen}
\usetikzlibrary{
  arrows.meta,
  calc,
  positioning,
  decorations,
  decorations.markings,
  math,
}
\pgfkeys{
  /imagelabels/.is family,
  /imagelabels/.search also={/tikz},
}

\def\imagelabelset{\pgfqkeys{/imagelabels}}
\imagelabelset{
  coarse grid color/.store in = \maingridcolor,
  fine grid color/.store in = \finegridcolor,
}

\imagelabelset{
  image label font/.store in = \imagelabelfont,
  image label distance/.store in = \imagelabelsep,
  image label back/.store in = \imagelabelback,
  image label text/.store in = \imagelabeltext,
}

\imagelabelset{
  annotation font/.store in = \annotationfont,
  arrow distance/.store in = \arrowdistance,
  arrow thickness/.store in = \arrowthickness,
  tip size/.store in = \tipsize,
  border thickness/.store in = \borderthickness,
  outer dist/.store in = \labeloutersep,
}
\imagelabelset{
  coarse grid color = red,
  fine grid color = gray,
  image label font = \sffamily\bfseries\small,
  image label distance = 2mm,
  image label back = black,
  image label text = white,
  annotation font = \normalfont\small,
  arrow distance = 1.5mm,
  border thickness = 0.6pt,
  arrow thickness = 0.4pt,
  tip size = 1.2mm,
  outer dist = 0.5cm,
}
\newenvironment{annotationimage}[3][]{
\let\tikzset\imagelabelset
  \begin{tikzpicture}
  \node[anchor=south west, inner sep=0]
    (image) at (0,0) {\includegraphics[#2]{#3}};
  \begin{scope}[x={(image.south east)},y={(image.north west)}]
  \ifthenelse{\equal{#1}{grid}}{%
    \draw[very thin, draw=\finegridcolor, step=0.02]
      (0,0) grid (1,1);
    \draw[thin, draw=\maingridcolor, xstep=0.1, ystep=0.1]
      (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} {
      \node [anchor=north] at (\x/10,0) {\tiny 0.\x};
    }
    \node [anchor=north] at (1,0) {\tiny 1};

    \foreach \y in {0,1,...,9} {
      \node [anchor=east] at (0,\y/10) {\tiny 0.\y};
    }
    \node [anchor=east] at (0,1) {\tiny 1};
  }{}
}
{
 \end{scope}
 \end{tikzpicture}}
\imagelabelset{
  annotation arrow/.style =
  {
    preaction =
    {
      draw,
      -{Circle[fill=white, length=\tipsize+2*\borderthickness,
        width=\tipsize+2*\borderthickness]},
      line width = 2*\borderthickness + \arrowthickness,
      white,
      shorten >= \arrowdistance,
    },
    draw,
    -{Circle[fill=black, length=\tipsize, width=\tipsize]},
    black,
    line width = \arrowthickness,
    shorten >= \borderthickness + \arrowdistance,
  },
  annotation node/.style =
  {
    font=\annotationfont,
    inner sep = 0.5ex,
  },
  annotation below/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (#2,0) ++ (0,-\labeloutersep)
        node[anchor = north, annotation node] {#1\strut}
    }
  },
  annotation above/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (#2,1.0) ++ (0,\labeloutersep)
        node[anchor = south, annotation node] {#1\strut}
    }
  },
  annotation left/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (0,#2) ++ (-\labeloutersep,0)
        node[anchor = east, annotation node] {#1}
    }
  },
  annotation right/.style args = {#1 at #2}{
    annotation arrow,
    insert path = {
      (1.0,#2) ++ (\labeloutersep,0)
        node[anchor = west, annotation node] {#1}
    }
  },
}
\imagelabelset{
  image label style/.style = {
    rectangle,
    minimum width = 5mm,
    minimum height = 5mm,
    fill = \imagelabelback,
    text = \imagelabeltext,
    font = \imagelabelfont,
  },
  image label/.style args = {#1 at #2}{
    insert path = {
      (image.#2) node[outer sep = \imagelabelsep,
        anchor=#2, image label style] {#1}
    }
  },
}
\endinput
%%
%% End of file `tikz-imagelabels.sty'.