tikzでの一般的な可換図式のマクロの作成



Creating Macros Common Commutative Diagrams Tikz



解決:

キーを使用して、TikZマトリックスのアンパサンドを置き換える必要がありますアンパサンド置換=、ここですることができます&、 例えば。

これがコマンドとしてのコードです。 PGF / TikZ:文字列を配列に格納する方法で説明されているアプローチを使用しましたか?ラベルに個別の引数の代わりにリストを使用するため。あなたの図



その後、を使用して作成できます



 monoid {(A  otimes A) otimes A、A  otimes(A  otimes A)、A  otimes A、A  otimes A、A、$  mu  otimes Id $、$  mu $、$ Id  otimes  mu $、$  mu $、$  alpha $}

完全なコードは次のとおりです。

 documentclass {article}  usepackage {tikz}  usetikzlibrary {matrix、arrows}  usepackage {xparse}  usepackage {etoolbox}  newcounter {listtotal}  newcounter {listcntr}% NewDocumentCommand { arguments} {o} {% setcounter {listtotal} {0}  setcounter {listcntr} {-1}% renewcommand * { do} [1] { stepcounter {listtotal}}% expandafter  docsvlist  expandafter { argumentsarray}% IfNoValueTF {# 1} { namesarray}% names {% names []  renewcommand * { do} [1] { stepcounter {listcntr}  ifnum  value {listcntr} =#1  Relax ## 1  fi}%  expandafter  docsvlist  expandafter { argumentsarray}}%}  newcommand { monoid} [1] { def  argumentsarray {#1}  begin {tikzpicture} [baseline =(current bounding box.center)]  matrix( m)[数学ノードの行列、アンペアと置換= &、行sep = 2.6em、列sep = 2.8em、テキストの高さ= 2ex、テキストの深さ= 0.5ex] {引数[0] &&引数[ 1] \引数[2] &&引数[3] \ &引数[4] &\};  path [->、font =  normalsize、> = angle 90](m-1-1)エッジノード[自動] { arguments [5]}(m-2-1)(m-2-1)エッジノード[自動] {引数[6]}(m-3-2)(m-1-3)エッジノード[自動] {引数[8]}(m-2-3)(m-2-3 )エッジノード[自動] {引数[9]}(m-3-2);  path [、font =  normalsize、> = angle 90](m-1-1)エッジノード[auto] { arguments [10]}(m-1-3);  end {tikzpicture}}  begin {document}  monoid {(A  otimes A) otimes A、A  otimes(A  otimes A)、A  otimes A、A  otimes A、A、$  mu  otimes Id $、$  mu $、$ Id  otimes  mu $、$  mu $、$  alpha $}  end {document} 

別のアプローチ:

  • 使用する可換図式の簡単な構築のためのtikz-cd
  • 使用要素のarrayjobxパッケージ

利点:



  • 短いダイアグラムコード、要素内に直接矢印
  • 呼び出すたびに9つのパラメータを書き込む代わりに monoid、ダイアグラムが類似している場合は、特定の配列引数のみを変更できます。 monoidelements(1)= {A ' otimesA'}と呼び出し monoid再び
 documentclass {article}  usepackage {arrayjobx}  newarray {monoidelements}  usepackage {tikz-cd}  newcommand { monoid} [1] { begin {tikzcd} [->、font =  normalsize、> = angle 90 、アンパサンド置換= &]#1(1) arrow {d} {#1(6)}  arrow [] {rr} { alpha} &&#1(2) arrow {d} { #1(7)} \#1(3) arrow {dr} {#1(8)} &&#1(4) arrow {dl} {#1(9)} \ & #1(5)& end {tikzcd}}  begin {document}  readarray {monoidelements} {(A  otimes A) otimes A  otimes A&A  otimes(A  otimes A)&A  otimes A&A  otimes A&A& mu  otimes Id&Id  otimes  mu& mu& mu  otimes Id}  monoid { monoideselements}  end {document}

モノイド


コメントには長すぎる回答。これは、に基づく短い構文を使用したジェイクの回答の書き直しにすぎないためです。expl3:

 documentclass {article}  usepackage {tikz}  usetikzlibrary {matrix、arrows}  usepackage {xparse}  ExplSyntaxOn  seq_new:N  l_jake_monoid_seq  NewDocumentCommand { monoid} {m} { seq_set_split:Nnn  l_jake_monoid_seq {、 #1}  domonoid}  NewDocumentCommand { arguments} {o} { IfNoValueTF {#1} { seq_use:N  l_jake_monoid_seq} { seq_item:Nn  l_jake_monoid_seq {#1}}}  ExplSyntaxOff  NewDocumentCommand { dom } {} { begin {tikzpicture} [baseline =(current bounding box.center)]  matrix(m)[数学ノードの行列、アンペアと置換= &、行sep = 2.6em、列sep = 2.8em、テキストheight = 2ex、text depth = 0.5ex] { arguments [0] && arguments [1] \  arguments [2] && arguments [3] \ & arguments [4] &\};  path [->、font =  normalsize、> = angle 90](m-1-1)エッジノード[自動] { arguments [5]}(m-2-1)(m-2-1)エッジノード[自動] {引数[6]}(m-3-2)(m-1-3)エッジノード[自動] {引数[8]}(m-2-3)(m-2-3 )エッジノード[自動] {引数[9]}(m-3-2);  path [、font =  normalsize、> = angle 90](m-1-1)エッジノード[auto] { arguments [10]}(m-1-3);  end {tikzpicture}}  begin {document}  monoid {(A  otimes A) otimes A、A  otimes(A  otimes A)、A  otimes A、A  otimes A、A、$  mu  otimes  mathit {Id} $、$  mu $、$  mathit {Id}  otimes  mu $、$  mu $、$  alpha $}  end {document}

NS monoidマクロは2つのことを行います:引数からシーケンスを設定し、呼び出しますジェイクと同じ domonoidモノイド。そのことに注意してくださいドモノイド しなければならない で定義されます ExplSyntaxOff、TikZキーのスペースが重要であるため。

の定義引数は 多くの より簡単etoolbox。

注:より良い形を得るために Id 、使用する方が良いです mathit {Id}。


StefanKottwitzの回答にも同様のアイデアを使用できます

 documentclass {article}  usepackage {xparse}  usepackage {tikz-cd}  NewDocumentCommand { monoid} {m} { makeargument {#1}  begin {tikzcd} [->、font =  normalsize、> = angle 90、ampersand replace = &]  arguments {0}  arrow {d} { arguments {5}}  arrow [] {rr} { alpha} && arguments {1}  arrow {d} {引数{6}} \ 引数{2}  arrow {dr} {引数{7}} &&引数{3}  arrow {dl} {引数{8}} \ & arguments {4} & end {tikzcd}}  ExplSyntaxOn  seq_new:N  l_sk_monoid_seq  cs_new:Npn  makeargument#1 { seq_set_split:Nnn  l_sk_monoid_seq {&} {#1}}  cs_new:N引数#1 { seq_item:Nn  l_sk_monoid_seq {#1}}  ExplSyntaxOff  begin {document}  monoid {(A  otimes A) otimes A  otimes A&A  otimes(A  otimes A)&A  otimes A&A  otimes A&A& mu  otimes  mathit {Id}& mathit {Id}  otimes  mu& mu& mu  otimes  mathit {Id}}  end {document}