Debian Codegraph @

texmf-dist/source/latex/aligned-overset/aligned-overset.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% Copyright (C) 2018 by Marcel Krueger
4 %%
5 %% This file may be distributed and/or modified under the
6 %% conditions of the LaTeX Project Public License, either
7 %% version 1.3c of this license or (at your option) any later
8 %% version. The latest version of this license is in:
9 %%
10 %% http://www.latex-project.org/lppl.txt
11 %%
12 %% and version 1.3 or later is part of all distributions of
13 %% LaTeX version 2005/12/01 or later.
14 %
15 %<*batch>
16 %<*gobble>
17 \ifx\jobname\relax\let\documentclass\undefined\fi
18 \ifx\documentclass\undefined
19 \csname fi\endcsname
20 %</gobble>
21 \input l3docstrip.tex
22 \keepsilent
23 \preamble
24 \endpreamble
25 \generate{\file{aligned-overset.sty}{\from{aligned-overset.dtx}{package}}}
26 \endbatchfile
27 %</batch>
28 %<*gobble>
29 \fi
30 \expandafter\ifx\csname @currname\endcsname\empty
31 \csname fi\endcsname
32 %</gobble>
33 %<*driver>
34 \documentclass[full]{l3doc}
35 \usepackage{aligned-overset}
36 \begin{document}
37 \DocInput{aligned-overset.dtx}
38 \PrintIndex
39 \PrintChanges
40 \end{document}
41 %</driver>
42 %<*gobble>
43 \fi
44 %</gobble>
45 % \fi
46 %
47 % \GetFileInfo{aligned-overset.dtx}
48 % \title{The \pkg{aligned-overset} package\thanks{This document
49 % corresponds to \pkg{aligned-overset}~0.1.0, dated~2018/04/04.}}
50 % \author{Marcel Kr\"uger \\ \href{mailto:[email protected]}{[email protected]}}
51 %
52 % \maketitle
53 %
54 % \begin{documentation}
55 % This package allows the base character of \cmd\underset{} or \cmd\overset{} to be used as the alignment position for the amsmath aligned math environments.
56 %
57 % \section{Example}
58 % The naive way to align at an operator annotated by \cmd\overset{} would be
59 % \begin{verbatim}
60 % \begin{align*}
61 % f(x)&\overset{\text{Def}}=x+x\\
62 % & =2x
63 % \end{align*}
64 % \end{verbatim}
65 % This results in
66 % \begin{align*}
67 % f(x)&\overset{\text{Def}}=x+x\\
68 % & =2x
69 % \end{align*}
70 % But here, the two equal signes are not aligned.
71 %
72 % Using this package, this can be fixed by writing
73 % \begin{verbatim}
74 % \begin{align*}
75 % f(x)\overset{\text{Def}}&=x+x\\
76 % &=2x
77 % \end{align*}
78 % \end{verbatim}
79 % which result in correct alignment:
80 % \begin{align*}
81 % f(x)\overset{\text{Def}}&=x+x\\
82 % &=2x
83 % \end{align*}
84 % \section{Usage}
85 % \begin{function}{\overset,\underset}
86 % To add an alignment point at an \cmd\overset{} or \cmd\underset, add a |&| before the base symbol.
87 % The |&| should not be enclosed in braces, even if the symbols are enclosed in braces.
88 % For example you have to write |\overset{\approx}&{\ge}| instead of |\overset{\approx}{&\ge}|.
89 % \end{function}
90 % \end{documentation}
91 % \begin{implementation}
92 % \section{The implementation}
93 % \begin{macrocode}
94 %<@@=alignedsets>
95 % \end{macrocode}
96 % \iffalse
97 %<*package>
98 \NeedsTeXFormat{LaTeX2e}
99 \RequirePackage{expl3}
100 \ProvidesExplPackage
101 {aligned-overset}
102 {2018/04/04}
103 {0.1.0}
104 {aligned overset and underset}
105
106 \RequirePackage{xparse,amsmath,mathtools}
107 %</package>
108 % \fi
109 % \begin{macrocode}
110 \box_new:N\l__alignedsets_clap_box
111 \box_new:N\l__alignedsets_full_box
112
113 % \end{macrocode}
114 % \begin{macro}{\overset}
115 % \begin{macrocode}
116 \let\__alignedsets_original_overset:nn\overset
117 \cs_set:Npn\overset{
118 \group_align_safe_begin:
119 \__alignedsets_modified_overset:nwn
120 }
121 \NewExpandableDocumentCommand\__alignedsets_modified_overset:nwn{mt{&}m}{
122 \group_align_safe_end:
123 \IfBooleanTF{#2}{
124 \group_begin:
125 \hbox_set:Nn\l__alignedsets_clap_box{
126 $
127 \displaystyle
128 {}\__alignedsets_original_overset:nn{\mathclap{#1}}{#3}{}
129 $
130 }
131 \hbox_set:Nn\l__alignedsets_full_box{
132 $
133 \displaystyle
134 {}\__alignedsets_original_overset:nn{#1}{#3}{}
135 $
136 }
137 \hspace{
138 \dim_eval:n{(\box_wd:N\l__alignedsets_full_box-\box_wd:N\l__alignedsets_clap_box)/2}
139 }
140 \exp_args:NNNx
141 \group_end:
142 {&}
143 \hspace{
144 -\dim_eval:n{
145 (\box_wd:N\l__alignedsets_full_box-\box_wd:N\l__alignedsets_clap_box)/2
146 }
147 }
148 \__alignedsets_original_overset:nn{#1}{#3}
149 }{
150 \__alignedsets_original_overset:nn{#1}{#3}
151 }
152 }
153 % \end{macrocode}
154 % \end{macro}
155 % \begin{macro}{\underset}
156 % \begin{macrocode}
157 \let\__alignedsets_original_underset:nn\underset
158 \cs_set:Npn\underset{
159 \group_align_safe_begin:
160 \__alignedsets_modified_underset:nwn
161 }
162 \NewExpandableDocumentCommand\__alignedsets_modified_underset:nwn{mt{&}m}{
163 \group_align_safe_end:
164 \IfBooleanTF{#2}{
165 \group_begin:
166 \hbox_set:Nn\l__alignedsets_clap_box{
167 $
168 \displaystyle
169 {}\__alignedsets_original_underset:nn{\mathclap{#1}}{#3}{}
170 \m@th
171 $
172 }
173 \hbox_set:Nn\l__alignedsets_full_box{
174 $
175 \displaystyle
176 {}\__alignedsets_original_underset:nn{#1}{#3}{}
177 \m@th
178 $
179 }
180 \hspace{
181 \dim_eval:n{(\box_wd:N\l__alignedsets_full_box-\box_wd:N\l__alignedsets_clap_box)/2}
182 }
183 \exp_args:NNNx
184 \group_end:
185 {&}
186 \hspace{
187 -\dim_eval:n{
188 (\box_wd:N\l__alignedsets_full_box-\box_wd:N\l__alignedsets_clap_box)/2
189 }
190 }
191 \__alignedsets_original_underset:nn{#1}{#3}
192 }{
193 \__alignedsets_original_underset:nn{#1}{#3}
194 }
195 }
196 % \end{macrocode}
197 % \end{macro}
198 % \end{implementation}