add salign to lecture.cls, fix typo in num3
This commit is contained in:
+71
@@ -24,6 +24,7 @@
|
||||
\RequirePackage{totcount}
|
||||
\RequirePackage{calc}
|
||||
\RequirePackage{wasysym}
|
||||
\RequirePackage{environ}
|
||||
|
||||
\usetikzlibrary{quotes, angles}
|
||||
|
||||
@@ -149,3 +150,73 @@
|
||||
|
||||
% contradiction
|
||||
\newcommand{\contr}{\text{\Large\lightning}}
|
||||
|
||||
\ExplSyntaxOn
|
||||
|
||||
% S-tackrelcompatible ALIGN environment
|
||||
% some might also call it the S-uper ALIGN environment
|
||||
% uses regular expressions to calculate the widest stackrel
|
||||
% to put additional padding on both sides of relation symbols
|
||||
\NewEnviron{salign}
|
||||
{
|
||||
\begin{align}
|
||||
\lec_insert_padding:V \BODY
|
||||
\end{align}
|
||||
}
|
||||
% starred version that does no equation numbering
|
||||
\NewEnviron{salign*}
|
||||
{
|
||||
\begin{align*}
|
||||
\lec_insert_padding:V \BODY
|
||||
\end{align*}
|
||||
}
|
||||
|
||||
% some helper variables
|
||||
\tl_new:N \l__lec_text_tl
|
||||
\seq_new:N \l_lec_stackrels_seq
|
||||
\int_new:N \l_stackrel_count_int
|
||||
\int_new:N \l_idx_int
|
||||
\box_new:N \l_tmp_box
|
||||
\dim_new:N \l_tmp_dim_a
|
||||
\dim_new:N \l_tmp_dim_b
|
||||
\dim_new:N \l_tmp_dim_needed
|
||||
|
||||
% function to insert padding according to widest stackrel
|
||||
\cs_new_protected:Nn \lec_insert_padding:n
|
||||
{
|
||||
\tl_set:Nn \l__lec_text_tl { #1 }
|
||||
% get all stackrels in this align environment
|
||||
\regex_extract_all:nnN { \c{stackrel}{(.*?)}{(.*?)} } { #1 } \l_lec_stackrels_seq
|
||||
% get number of stackrels
|
||||
\int_set:Nn \l_stackrel_count_int { \seq_count:N \l_lec_stackrels_seq }
|
||||
\int_set:Nn \l_idx_int { 1 }
|
||||
\dim_set:Nn \l_tmp_dim_needed { 0pt }
|
||||
% iterate over stackrels
|
||||
\int_while_do:nn { \l_idx_int <= \l_stackrel_count_int }
|
||||
{
|
||||
% calculate width of text
|
||||
\hbox_set:Nn \l_tmp_box {$\seq_item:Nn \l_lec_stackrels_seq { \l_idx_int + 1 }$}
|
||||
\dim_set:Nn \l_tmp_dim_a {\box_wd:N \l_tmp_box}
|
||||
% calculate width of relation symbol
|
||||
\hbox_set:Nn \l_tmp_box {$\seq_item:Nn \l_lec_stackrels_seq { \l_idx_int + 2 }$}
|
||||
\dim_set:Nn \l_tmp_dim_b {\box_wd:N \l_tmp_box}
|
||||
% check if 0.5*(a-b) > minimum padding, if yes updated minimum padding
|
||||
\dim_compare:nNnTF
|
||||
{ 1pt * \dim_ratio:nn { \l_tmp_dim_a - \l_tmp_dim_b } { 2pt } } > { \l_tmp_dim_needed }
|
||||
{ \dim_set:Nn \l_tmp_dim_needed { 1pt * \dim_ratio:nn { \l_tmp_dim_a - \l_tmp_dim_b } { 2pt } } }
|
||||
{ }
|
||||
\quad
|
||||
% increment list index by three, as every stackrel produces three list entries
|
||||
\int_incr:N \l_idx_int
|
||||
\int_incr:N \l_idx_int
|
||||
\int_incr:N \l_idx_int
|
||||
}
|
||||
% replace all relations with align characters (&) and add the needed padding
|
||||
\regex_replace_all:nnN
|
||||
{ (\c{approx}&|&\c{approx}|\c{equiv}&|&\c{equiv}|=&|&=|\c{le}&|&\c{le}|\c{ge}&|&\c{ge}|&\c{stackrel}{.*?}{.*?}|\c{stackrel}{.*?}{.*?}&|&\c{neq}|\c{neq}&) }
|
||||
{ \c{kern} \u{l_tmp_dim_needed} \1 \c{kern} \u{l_tmp_dim_needed} }
|
||||
\l__lec_text_tl
|
||||
\l__lec_text_tl
|
||||
}
|
||||
\cs_generate_variant:Nn \lec_insert_padding:n { V }
|
||||
\ExplSyntaxOff
|
||||
|
||||
Reference in New Issue
Block a user