summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/conteq/conteq.sty
blob: 1b7f88a6de50700df2b19e36249f37d870058212 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
%%
%% This is file `conteq.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% conteq.dtx  (with options: `package')
%% conteq.dtx  (with options: `layouts')
%% ----------------------------------------------------------------
%% conteq --- continued equalities
%% E-mail: mail@joachim-breitner.de
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}[2012/07/02]
\ProvidesExplPackage
  {conteq}              % Package name
  {2015/07/17}          % Release date
  {0.1.1}                 % Release version
  {Various layouts for continued equalities} % Description

\RequirePackage{amsmath}
\RequirePackage{environ}
\msg_new:nnn
    { conteq }
    { empty }
    { Empty~conteq~environment~\msg_line_context: }

\msg_new:nnn
    { conteq }
    { ignoreddata }
    { Ignored~text~\msg_line_context: }

\msg_new:nnn
    { conteq }
    { undefined layout }
    { Undefined~layout~``#1''~\msg_line_context: }

\tl_new:N \l__conteq_default_layout_tl
\tl_new:N \l__conteq_layout_tl
\tl_new:N \l__conteq_body_tl
\tl_new:N \l__conteq_lines_seq
\tl_new:N \l__conteq_cells_seq
\tl_new:N \l__conteq_head_tl
\tl_new:N \l__conteq_lastline_tl
\tl_new:N \l__conteq_rhs_tl
\tl_new:N \l__conteq_expl_tl
\tl_new:N \l__conteq_result_tl

\cs_new_protected:Nn \__conteq_set_default_layout:n
  {
    \tl_set:Nn \l__conteq_default_layout_tl {#1}
  }
\cs_new_eq:NN \ConteqSetDefaultLayout \__conteq_set_default_layout:n
\tl_const:Nn \c__conteq_prefix_tl { __conteq_layouts }

\cs_new_protected:Nn \__conteq_define_layout:nnnnnnn
  {
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1 _begin: } { #2 }
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1_lhs:n } { #3 }
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1_rhs_only:n } { #4 }
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1_rhs_expl:nn } { #5 }
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1_nl: } { #6 }
    \cs_new_protected:cn { \c__conteq_prefix_tl _ #1_end: } { #7 }
  }
\cs_new_eq:NN \ConteqDefineLayout \__conteq_define_layout:nnnnnnn
\cs_new:Npn \__conteq_args_once:Nn #1#2
  {
   \exp_not:o { #1 {#2} }
  }
\cs_generate_variant:Nn \__conteq_args_once:Nn { NV }

\cs_new:Npn \__conteq_args_once:Nnn #1#2#3
  {
   \exp_not:o { #1 { #2 }{ #3 } }
  }
\cs_generate_variant:Nn \__conteq_args_once:Nnn { NVV }
\cs_new_protected:Npn \__conteq_print_line:Nnn #1#2#3
  {
    \seq_set_split:Nnn \l__conteq_cells_seq { & } { #2 }
    \seq_pop_left:NN \l__conteq_cells_seq \l__conteq_rhs_tl
    \tl_clear:N \l__conteq_expl_tl
    \seq_if_empty:NF \l__conteq_cells_seq
      {
\seq_pop_left:NN \l__conteq_cells_seq \l__conteq_expl_tl
      }
    \tl_if_blank:VTF \l__conteq_expl_tl
      {
\tl_put_right:Nx #1
  {
    \__conteq_args_once:NV \__conteq_rhs_only:n \l__conteq_rhs_tl
  }
      }
      {
\tl_set:Nx \l_tmpa_tl { \exp_not:N \text { \exp_not:N \ConteqExplStyle { \exp_not:V \l__conteq_expl_tl } } }
\tl_put_right:Nx #1
  {
    \__conteq_args_once:NVV \__conteq_rhs_expl:nn \l__conteq_rhs_tl \l_tmpa_tl
          }
      }
      \seq_if_empty:NF \l__conteq_cells_seq
{
  \msg_warning:nn{conteq}{ignoreddata}
}
    \tl_put_right:Nn #1 {#3}
  }
\cs_generate_variant:Nn \__conteq_print_line:Nnn { Nno, NVn }

\NewEnviron{ conteq }[1][ \l__conteq_default_layout_tl ]{
  \tl_set:NV \l__conteq_body_tl \BODY

  \tl_if_blank:oT \l__conteq_body_tl
    {
      \msg_warning:nn{conteq}{empty}
    }

  \tl_set:Nn \l__conteq_layout_tl { #1 }
  \cs_if_exist:cTF { \c__conteq_prefix_tl _ \l__conteq_layout_tl _ begin: }
    {
      \clist_map_inline:nn{ begin:, lhs:n,rhs_only:n, rhs_expl:nn, nl:, end: }
        {
          \cs_set_eq:cc { __conteq_ ##1 }{ \c__conteq_prefix_tl _ \l__conteq_layout_tl _ ##1 }
        }
    }{
      \msg_critical:nnx{conteq}{undefined layout}{\l__conteq_layout_tl}
    }

  \seq_set_split:NnV \l__conteq_lines_seq { \\ } \l__conteq_body_tl

  \tl_clear:N \l__conteq_result_tl


  \int_case:nnF { \seq_count:N \l__conteq_lines_seq }
    {
      {1}
        {
          \tl_put_right:Nx \l__conteq_result_tl { \exp_not:o \__conteq_begin: }
          \tl_put_right:NV \l__conteq_result_tl \l__conteq_body_tl
          \tl_put_right:Nx \l__conteq_result_tl { \exp_not:o \__conteq_end: }
        }
    }
    {

      \seq_pop_left:NN \l__conteq_lines_seq \l__conteq_head_tl
      \seq_pop_right:NN \l__conteq_lines_seq \l__conteq_lastline_tl

      \tl_put_right:Nx \l__conteq_result_tl { \exp_not:o \__conteq_begin: }
      \tl_put_right:Nx \l__conteq_result_tl
        {
          \__conteq_args_once:NV \__conteq_lhs:n \l__conteq_head_tl
        }
      \seq_map_inline:Nn \l__conteq_lines_seq
        {
          \__conteq_print_line:Nno \l__conteq_result_tl { ##1 } { \__conteq_nl: }
        }
      \__conteq_print_line:NVn \l__conteq_result_tl \l__conteq_lastline_tl {}
      \tl_put_right:Nx \l__conteq_result_tl { \exp_not:o \__conteq_end: }
    }
    % Use this for debugging
    %\tl_show:N \l__conteq_result_tl
    \tl_use:N \l__conteq_result_tl
  }


\ConteqDefineLayout
    {plain}
    {\begin{align*}}
    { #1 }
    { & #1 }
    { & #1 && #2 }
    { \\ }
    {\end{align*}}
\ConteqSetDefaultLayout{plain}

\ConteqDefineLayout
    {explline}
    {\begin{align*}}
    { #1 }
    { & #1 }
    { & #1 \\ & \mathrel{\phantom{=}} #2 }
    { \\ }
    {\end{align*}}

\ConteqDefineLayout
    {headline}
    {\begin{align*}}
    { &\mathrel{\phantom{=}} #1 \\ }
    { & #1 }
    { & #1 && #2 }
    { \\ }
    {\end{align*}}

\ConteqDefineLayout
    {onecolumn}
    {\begin{align*}}
    { &\mathrel{\phantom{=}} #1 \\ }
    { & #1 }
    { & #1 \\ & \mathrel{\phantom{=}} #2 }
    { \\ }
    {\end{align*}}

\ConteqDefineLayout
    {oneline}
    {\[}
    { #1 }
    { #1 }
    { #1 }
    {}
    {\]}

\newcommand{\ConteqExplStyle}[1]{\{~#1~\}}
%% 
%% Copyright (C) 2013,2015 by Joachim Breitner <mail@joachim-breitner.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in the file:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Joachim Breitner.
%% 
%% This work consists of the file  conteq.dtx
%% and the derived files           conteq.ins,
%%                                 conteq.pdf and
%%                                 conteq.sty.
%% 
%%
%% End of file `conteq.sty'.