summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/eqexpl/eqexpl.sty
blob: dfdd46779c0b3e28afc6aedd3b06a194e3432534 (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
%% The package is licenced under Creative Commons Attribution-ShareAlike
%% 4.0 International (CC BY-SA 4.0)

\ProvidesPackage{eqexpl}[2019/05/15 v. 1.1]
\RequirePackage{etoolbox}
\RequirePackage{xparse}
\RequirePackage{calc}

%% Spaces between elements
\newlength{\eqexplSpaceWidth}
\newcommand{\eqexplSetSpace}[1]{%
  \setlength{\eqexplSpaceWidth}{\ifstrempty{#1}{2mm}{#1}}%
}
\eqexplSetSpace{}

%% Width of 'intro' (typ. 'where')
\newcommand{\eqexplSetIntro}[1]{%
  \def\eqexplIntro{#1}%
}
\eqexplSetIntro{}

%% Width of delimiter
\newcommand{\eqexplSetDelim}[1]{%
  \def\eqexplDelim{#1}%
}
\eqexplSetDelim{---}

%% Width of item
\newcommand{\eqexplSetItemWidth}[1]{%
  \def\eqexplItemWidth{#1}%
}
\eqexplSetItemWidth{5mm}

%% Align of item
\newcommand{\eqexplSetItemAlign}[1]{%
  \def\eqexplItemAlign{#1}%
}
\eqexplSetItemAlign{r}

\newlength{\itemWidth}
\newlength{\leftSideWidth}

\newenvironment{eqexpl}[1][\eqexplItemWidth]{%
  \let\olditem\item%
  \setlength{\itemWidth}{#1}%
  \setlength{\leftSideWidth}{\ifdefempty{\eqexplIntro}{}{\widthof{\eqexplIntro}+%
                             \eqexplSpaceWidth+}%
                             \itemWidth+%
                             \eqexplSpaceWidth+%
                             \widthof{\eqexplDelim}+%
                             \eqexplSpaceWidth}%
  \newtoggle{eqexplFirstItem}%
  \toggletrue{eqexplFirstItem}%
  \RenewDocumentCommand{\item}{ m O{\eqexplDelim}}{%
    \olditem \makebox[\leftSideWidth]{%
      \ifdefempty{\eqexplIntro}{}{
        \makebox[\widthof{\eqexplIntro}][l]{\iftoggle{eqexplFirstItem}{\eqexplIntro}{}}%
        \hspace{\eqexplSpaceWidth}%
      }
      \makebox[\itemWidth][\eqexplItemAlign]{##1}%
      \hspace{\eqexplSpaceWidth}%
      \makebox[\widthof{##2}][c]{##2}%
      \hspace{\eqexplSpaceWidth}%
    }%
    \togglefalse{eqexplFirstItem}%
    \ignorespaces% https://tex.stackexchange.com/a/44062
  }%
  \begin{list}{}{\setlength{\parsep}{0pt}%
  \setlength{\topsep}{0pt}%
  \setlength{\itemsep}{0pt}%
  \setlength{\labelsep}{0pt}%
  \setlength{\leftmargin}{\leftSideWidth}%
  \setlength{\itemindent}{-\leftSideWidth}}}{%
  \end{list}
}
\endinput