summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/inlinegraphicx/tex/inlinegraphicx.sty
blob: d4b696c2e4e0d49639350db3ff02be6ef0254e25 (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
% Author        : C. Pierquet
% licence       : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{inlinegraphicx}[2024/11/06 0.1.0 Insert inline graphicx]

%====HISTORY
% v 0.1.0	Initial version

%====BASE
\RequirePackage{graphicx}
\RequirePackage{calc}
\RequirePackage{simplekv}

%====DIMENSIONS
\newlength{\totheightinlinegraphicx}
\newlength{\depthinlinegraphicx}
\newlength{\inlinedepthgraphicsscale}

%====KEYS
\defKV[inlinegraphics]{scale=\def\inlinegraphicsscale{#1},strut=\def\inlinegraphicstrut{#1}}
\setKVdefault[inlinegraphics]{scale=1,strut={qH}}

%====MACRO
\NewDocumentCommand\inlinegraphics{ s O{} m }{%
	%1 = no depth/raisebox
	%2 = keys (scale + strut)
	%3 = file
	\restoreKV[inlinegraphics]%
	\setKV[inlinegraphics]{#2}%
	\IfBooleanTF{#1}%
		{%
			\settoheight{\totheightinlinegraphicx}{\hbox{\inlinegraphicstrut}}%
			\includegraphics[height=\inlinegraphicsscale\totheightinlinegraphicx]{#3}%
		}%
		{%
			\settototalheight{\totheightinlinegraphicx}{\hbox{\inlinegraphicstrut}}%
			\settodepth{\depthinlinegraphicx}{\hbox{\inlinegraphicstrut}}%
			\xdef\inlinegraphicsinvscale{\fpeval{0.5*(1-\inlinegraphicsscale)}}%
			\setlength{\inlinedepthgraphicsscale}%
				{\dimexpr\depthinlinegraphicx-\inlinegraphicsinvscale\totheightinlinegraphicx\relax}%
			\raisebox{-\inlinedepthgraphicsscale}{%
				\includegraphics[height=\inlinegraphicsscale\totheightinlinegraphicx]{#3}%
			}%
		}%
}

\endinput