-
Notifications
You must be signed in to change notification settings - Fork 4
Support *smallmatrix and align key in the diagmat module #28
Copy link
Copy link
Open
Description
The mathtools package has all kinds of matrices with a small appearance, and setting the align of every matrix element is supported.
It seems that many *.dtx files for modules have disappeared in this repo. So I open an issue instead of a PR.
I downloaded the phy-diagmat.sty on CTAN and then modified it, and the modified code is attached at the end.
- demo
\documentclass{article}
\usepackage{physics2, mathtools}
\usephysicsmodule{diagmat}
\begin{document}
The normal ones:
\[
\begin{array}{lll}
\diagmat{-1, 2, 123} & \pdiagmat{-1, 2, 123} & \bdiagmat{-1, 2, 123}\\[1em]
\Bdiagmat{-1, 2, 123} & \vdiagmat{-1, 2, 123} & \Vdiagmat{-1, 2, 123}
\end{array}
\]
The small ones:
\[
\begin{array}{lll}
\diagmat*{-1, 2, 123} & \pdiagmat*{-1, 2, 123} & \bdiagmat*{-1, 2, 123}\\[1em]
\Bdiagmat*{-1, 2, 123} & \vdiagmat*{-1, 2, 123} & \Vdiagmat*{-1, 2, 123}
\end{array}
\]
And configure the align:
\[
\begin{array}{lll}
\diagmat[empty = {a}, align = r]{-1, 2, 123} &
\pdiagmat[empty = {}, align = c]{-1, 2, 123} &
\bdiagmat[empty = {}, align = l]{-1, 2, 123} \\[1em]
\Bdiagmat[align = l]{-1, 2, 123} &
\vdiagmat[align = c]{-1, 2, 123} &
\Vdiagmat[align = r]{-1, 2, 123}
\end{array}
\]
\end{document}- modified
.styfile
%%
%% This is file `phy-diagmat.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% physics2-code.dtx (with options: `diagmat')
%%
%% Copyright (C) 2023 by Zhang Tingxuan <alphaztx@163.com>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Zhang Tingxuan.
%%
%% This work consists of the files physics2-code.dtx,
%% and the derived files physics2.ins,
%% physics2.sty,
%% phy-<module>.sty,
%% physics2-code.pdf,
%% and README.md.
%%
\ProvidesExplFile{phy-diagmat.sty}{2025/10/30}{}
{`diagmat' module of physics2}
\RequirePackage { amsmath }
\phy@define@key { diagmat } { empty } [ 0 ] { \tl_gset:Nn \l__phy_mat_empty_tl { #1 } }
\clist_new:N \l__phy_mat_diag_clist
\int_new:N \l__phy_mat_dim_int
\tl_new:N \l__phy_mat_line_tl
\tl_new:N \l__phy_diagmat_tl
\tl_new:N \l__phy_mat_empty_tl
\tl_new:N \l__phy_mat_align_tl
\phy@processkeyopt { diagmat }
\keys_define:nn { phy/diagmat }
{
empty .tl_set:N = \l__phy_mat_empty_tl,
empty .initial:n = 0,
align .tl_set:N = \l__phy_mat_align_tl,
}
\DeclareDocumentCommand \diagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { small } {#2} {#3} }
{ \__phy_diagmat_type:nnn { } {#2} {#3} }
}
\DeclareDocumentCommand \pdiagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { psmall } {#2} {#3} }
{ \__phy_diagmat_type:nnn { p } {#2} {#3} }
}
\DeclareDocumentCommand \bdiagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { bsmall } {#2} {#3} }
{ \__phy_diagmat_type:nnn { b } {#2} {#3} }
}
\DeclareDocumentCommand \Bdiagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { Bsmall } {#2} {#3} }
{ \__phy_diagmat_type:nnn { B } {#2} {#3} }
}
\DeclareDocumentCommand \vdiagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { vsmall } {#2} {#3} }
{ \__phy_diagmat_type:nnn { v } {#2} {#3} }
}
\DeclareDocumentCommand \Vdiagmat { s O{} m }
{
\IfBooleanTF {#1}
{ \__phy_diagmat_type:nnn { Vsmall } {#2} {#3} }
{ \__phy_diagmat_type:nnn { V } {#2} {#3} }
}
\cs_new:Npn \__phy_diagmat_type:nnn #1#2#3
{
\group_begin:
\clist_set:Nn \l__phy_mat_diag_clist { #3 }
\int_set:Nn \l__phy_mat_dim_int { \clist_count:N \l__phy_mat_diag_clist }
\int_compare:nNnT { \l__phy_mat_dim_int } > { \value { MaxMatrixCols } }
{ \setcounter { MaxMatrixCols } { \l__phy_mat_dim_int } }
\keys_set:nn { phy/diagmat } { #2 }
\tl_gclear:N \l__phy_diagmat_tl
\int_step_inline:nnn { 1 } { \l__phy_mat_dim_int }
{
\int_step_inline:nnn { 1 } { \l__phy_mat_dim_int }
{
\int_compare:nNnTF { ##1 } = { ####1 }
{
\clist_gpop:NN \l__phy_mat_diag_clist \l__phy_tmpa_tl
\tl_if_empty:NTF \l__phy_tmpa_tl
{ \tl_gput_right:Nn \l__phy_mat_line_tl { \l__phy_mat_empty_tl } }
{ \tl_gput_right:No \l__phy_mat_line_tl { \l__phy_tmpa_tl } }
}
{ \tl_gput_right:Nn \l__phy_mat_line_tl { \l__phy_mat_empty_tl } }
\int_compare:nNnTF { ####1 } = { \l__phy_mat_dim_int }
{
\tl_gput_right:Nn \l__phy_mat_line_tl { \\ }
}
{
\tl_gput_right:Nn \l__phy_mat_line_tl { & }
}
}
\tl_gput_right:No \l__phy_diagmat_tl { \l__phy_mat_line_tl }
\tl_gclear:N \l__phy_mat_line_tl
}
\tl_if_empty:NTF { \l__phy_mat_align_tl }
{
\begin { #1 matrix }
\tl_use:N \l__phy_diagmat_tl
\end { #1 matrix }
}
{
\begin { #1 matrix* } [ \l__phy_mat_align_tl ]
\tl_use:N \l__phy_diagmat_tl
\end { #1 matrix* }
}
\group_end:
}
\endinput
%%
%% End of file `phy-diagmat.sty'.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels