Ein Remake von @Ijon Tichys Antwort mit `l3keys`. Um mehr über das Zeug zu lernen empfehle ich die beiden Artikel von Joseph Wright aus TUGboat:
- [https://tug.org/TUGboat/tb31-1/tb97wright-l3keys.pdf](Programming key–value in expl3)
- [https://www.tug.org/TUGboat/tb30-1/tb94wright-latex3.pdf](LaTeX3 programming: External perspectives)
---
Vielleicht kann mir noch jemand erklären warum ich keinen LaTeX3 kernel error bekomme wenn ich `file=...` weglasse obwohl `file .value_required` ist.
\documentclass{article}
\usepackage{mwe,blindtext,graphicx,caption,xparse}
\ExplSyntaxOn
\keys_define:nn { cis }
{
options .tl_set:N = \l_cis_options_tl ,
file .tl_set:N = \l_cis_file_tl ,
title .tl_set:N = \l_cis_title_tl ,
shorttitle .tl_set:N = \l_cis_shorttitle_tl ,
shorttitle .initial:n = \l_cis_title_tl ,
floatto .tl_set:N = \l_cis_floatto_tl ,
lofthumbsize .tl_set:N = \l_cis_lofthumbsize_tl,
lofthumbsize .initial:n = 2em ,
file .value_required: ,
}
%\keys_set:nn { cis } { lofthumbsize = 4em }
\cs_new_protected:Npn \cis_img:n #1
{
\group_begin:
\keys_set:nn { cis } { #1 }
\tl_if_empty:NTF \l_cis_floatto_tl
{
\cis_img_nofloat:
}
{
\cis_img_float:
}
\group_end:
}
\cs_new_protected:Npn \cis_img_nofloat:
{
\vskip\intextsep\noindent
\begin{minipage}{\linewidth}
\centering
\exp_after:wN
\includegraphics
\exp_after:wN
[\l_cis_options_tl]{\l_cis_file_tl}
\exp_args:NNo \includegraphics[\l_cis_options_tl]{\l_cis_file_tl}
\tl_if_empty:NF \l_cis_title_tl
{
\captionof{figure}[
\lofimage{\l_cis_lofthumbsize_tl}{\l_cis_file_tl}
\l_cis_shorttitle_tl
]{\l_cis_title_tl}
}
\par
\end{minipage}
\vskip\intextsep
}
\cs_new_protected:Npn \cis_img_float:
{
\tl_set:Nx \l_tmpa_tl { \exp_not:N \begin{figure}[\l_cis_floatto_tl] }
\l_tmpa_tl
\exp_args:Nnno \begin{figure}[\l_cis_floatto_tl]
\centering
\exp_after:wN
\includegraphics
\exp_after:wN
[\l_cis_options_tl]{\l_cis_file_tl}%
\exp_args:NNo\includegraphics[\l_cis_options_tl]{\l_cis_file_tl}
\tl_if_empty:NF \l_cis_title_tl
{
\caption[
\lofimage{\l_cis_lofthumbsize_tl}{\l_cis_file_tl}
\l_cis_shorttitle_tl
]{\l_cis_title_tl}
}
\end{figure}
}
\box_new:N \l_cis_lofimage_box
\NewDocumentCommand \lofimage { m m }
{
$
\tex_vcenter:D \hbox_set_to_wd:Nnn \l_cis_lofimage_box { #1 }
{
\hss
\includegraphics[
width=#1,height=#1,keepaspectratio=true
]{#2}
\hss
}
$\tex_vcenter:D to #1 {\vss
\hbox_to_wd:nn { #1 } {\hss
\includegraphics[
width=#1,height=#1,keepaspectratio=true
]{#2}
\hss}
\vss}
$
\vss \box_use:N \l_cis_lofimage_box \vss }$
\quad
}
\NewDocumentCommand \IMG { r[] }
{
\cis_img:n { #1 }
}
\ExplSyntaxOff
\begin{document}
\listoffigures
\section{Test}
\blindtext
\IMG[title={Testtitle},file=example-image]
\Blindtext
Und jetzt folgt eine Abbildung genau hier:
\IMG[floatto={},title={Testtitel},shorttitle={Kurztesttitel},file=example-image-16x9]
\blindtext
\IMG[floatto=p,options={scale=.5},title={Auch ein Titel},file=example-image]
\Blindtext
\end{document}