summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/easyfig/easyfig.sty
blob: a64ea6a7c936e72bb30917d38d9bf7b8e0e72e18 (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
%% Copyright (C) 2011-2018 by Martin Scharrer <martin@scharrer-online.de>
%% ----------------------------------------------------------------------
%% 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 Martin Scharrer.
%%
%% This work consists of the files easyfig.dtx and easyfig.ins
%% and the derived filebase easyfig.sty.
%%
\ProvidesPackage{easyfig}[%
    2018/03/30
    v1.2a
    Easy way to include figures]
\RequirePackage{adjustbox}
\RequirePackage{xkeyval}
\RequirePackage{ifetex}
\let\easyfig@caption\@gobble
\let\easyfig@captionabove\@gobble
\let\easyfig@placement\@empty
\let\easyfig@default\@empty
\let\easyfig@default@end\@empty
\let\easyfig@shortcaption\@empty
\def\easyfig@env{{figure}}
\newcommand*{\easyfigdefault}{%
    \@ifstar
        {\def\easyfig@default@end}%
        {\def\easyfig@default}%
}
\easyfigdefault*{center}
\def\easyfig@label#1{%
    \@ifundefined {easyfig@r@fig:#1}{%
        \label{fig:#1}%
        \global\@namedef{easyfig@r@fig:#1}{}%
    }{}%
}
\define@key{easyfig}{caption}{%
    \def\easyfig@caption##1{\expandafter\caption\easyfig@shortcaption{#1}\easyfig@label{##1}}%
    \let\easyfig@captionabove\@gobble
}
\define@key{easyfig}{shortcaption}{%
    \def\easyfig@shortcaption{[{#1}]}%
}
\define@key{easyfig}{captionabove}{%
    \let\easyfig@caption\@gobble
    \def\easyfig@captionabove##1{{%
        \@tempdima=\abovecaptionskip
        \abovecaptionskip=\belowcaptionskip
        \belowcaptionskip=\@tempdima
        \expandafter\caption\easyfig@shortcaption{#1}%
        \easyfig@label{##1}%
    }}%
}
\define@key{easyfig}{label}{%
    \def\easyfig@label##1{\label{#1}}%
}
\define@key{easyfig}{placement}{%
    \def\easyfig@placement{[#1]}%
}
\define@key{easyfig}{here}[]{%
    \def\easyfig@env{{easyfighere}}%
}
\newenvironment{easyfighere}{%
    \trivlist
    \def\@captype{figure}%
    \item\relax
}{%
    \endtrivlist
}
\define@key{easyfig}{twocolumn}[true]{%
    \begingroup
    \def\@tempa{#1}%
    \def\@tempb{true}%
    \ifx\@tempa\@tempb
        \endgroup
        \def\easyfig@env{{figure*}}%
    \else
        \endgroup
        \def\easyfig@env{{figure}}%
    \fi
}
\newcommand{\Figure}{%
    \begingroup
    \@ifstar
        {\def\easyfig@env{{figure*}}\@Figure}%
        {\@Figure}%
}
\ifetex
\def\easyfig@expandonce#1{%
    \expandafter\unexpanded\expandafter{#1}%
}
\newcommand{\@Figure}[2][]{%
    \edef\@tempa{%
        \noexpand\setkeys*{easyfig}{%
            \easyfig@expandonce\easyfig@default,%
            \unexpanded{#1},%
            \easyfig@expandonce\easyfig@default@end
        }%
    }%
    \@tempa
    \edef\@tempa{%
        \noexpand\begin\easyfig@env%
        \easyfig@placement
    }%
    \@tempa
    \easyfig@captionabove{#2}%
    \edef\@tempa{\noexpand\begin{adjustbox}{\easyfig@expandonce\XKV@rm}}%
    \@tempa
        \includegraphics{#2}%
    \end{adjustbox}%
    \easyfig@caption{#2}%
    \expandafter\end\easyfig@env%
    \endgroup
}
\else
\newcommand{\@Figure}[2][]{%
    \def\@tempa{\setkeys*{easyfig}}%
    \expandafter\toks@\expandafter{\easyfig@default,#1}%
    \expandafter\expandafter\expandafter\toks@
    \expandafter\expandafter\expandafter{\expandafter\the\expandafter\toks@\expandafter,\easyfig@default@end}%
    \expandafter\@tempa\expandafter{\the\toks@}
    \edef\@tempa{\noexpand\begin\easyfig@env}%
    \expandafter\@tempa\easyfig@placement
    \easyfig@captionabove{#2}%
    \def\@tempa{\begin{adjustbox}}%
    \expandafter\def\expandafter\@tempb\expandafter{\expandafter{\XKV@rm}}%
    \expandafter\@tempa\@tempb
        \includegraphics{#2}%
    \end{adjustbox}%
    \easyfig@caption{#2}%
    \expandafter\end\easyfig@env%
    \endgroup
}
\fi
\endinput
%%
%% End of file `easyfig.sty'.