我有一个列表 L,其示例如下:
L=[ 5, [ (1)*a2*a3, (1)*a3*a4 ], [ (1)*a1*a2, (1)*a3*a4 ], [ (1)*a1*a2*a3, (1)*a3*a4 ], [ (1)*a3*a4 ], [ (1)*a1*a2, (1)*a2*a3 ], [ (1)*a2*a3 ], [ (1)*a1*a2, (1)*a2*a3*a4 ],
[ (1)*a1*a2*a3, (1)*a2*a3*a4 ], [ (1)*a2*a3*a4 ], [ (1)*a1*a2 ], [ (1)*a1*a2*a3 ], [ (1)*a1*a2*a3*a4 ] ]
第一个条目是一个数字,这里是 5。其他条目是形式为的列表,例如
[ (1)*a2*a3, (1)*a3*a4 ]
。
从这个包含 n 个条目的列表中,我们可以生成 n-1 张图片,其中每张图片如下所示,对应于以下形式的列表[ (1)*a2*a3, (1)*a3*a4 ]
:
绘制一个有 z 个顶点(z 是列表 L 中的第一个数字)的箭筒(=有向图),它是一条线性定向线,带有以 命名的箭头a_1 to a_{z-1}
。
现在输入关系,例如[ (1)*a2*a3, (1)*a3*a4 ]
输入到这个箭筒中。
该示例[ (1)*a2*a3, (1)*a3*a4 ]
应提供以下 tikz 图片(我使用 tikz 的 quiver 应用程序生成,您可以复制粘贴链接以在 quiverapp 编辑器中获取图片):
%https://q.uiver.app/#q=WzAsNSxbMCwwLCIxIl0sWzEsMCwiMiJdLFsyLDAsIjMiXSxbMywwLCI0Il0sWzQsMCwiNSJdLFswLDEsImFfMSJdLFsxLDIsImFfMiJdLFsyLDMsImFfMyJdLFszLDQsImFfNCJdLFsxLDMsIiIsMSx7ImN1cnZlIjozLCJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XSxbMiw0LCIiLDEseyJjdXJ2ZSI6Mywic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV1d
\[\begin{tikzcd}
1 & 2 & 3 & 4 & 5
\arrow["{a_1}", from=1-1, to=1-2]
\arrow["{a_2}", from=1-2, to=1-3]
\arrow["{a_3}", from=1-3, to=1-4]
\arrow["{a_4}", from=1-4, to=1-5]
\arrow[curve={height=18pt}, dashed, from=1-2, to=1-4]
\arrow[curve={height=18pt}, dashed, from=1-3, to=1-5]
\end{tikzcd}\]
因此输入应该是列表 L,输出应该是 n-1 个这样的颤动,其关系按给定的顺序与列表 L 的条目相对应。
问题 1:有没有一种简单的方法可以使用 Tikz 自动完成此操作?
这里是具有编译关系的线性箭筒图片的最小示例:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\begin{document}
{\tikzset{curve/.style={settings={#1},to path={(\tikztostart)
.. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
settings/.code={\tikzset{quiver/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/quiver/##1}}},
quiver/.cd,pos/.initial=0.35,height/.initial=0}
% https://q.uiver.app/#q=WzAsNSxbMCwwLCIxIl0sWzEsMCwiMiJdLFsyLDAsIjMiXSxbMywwLCI0Il0sWzQsMCwiNSJdLFswLDEsImFfMSJdLFsxLDIsImFfMiJdLFsyLDMsImFfMyJdLFszLDQsImFfNCJdLFsxLDMsIiIsMSx7ImN1cnZlIjozLCJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XSxbMiw0LCIiLDEseyJjdXJ2ZSI6Mywic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV1d
\[\begin{tikzcd}
1 & 2 & 3 & 4 & 5
\arrow["{a_1}", from=1-1, to=1-2]
\arrow["{a_2}", from=1-2, to=1-3]
\arrow["{a_3}", from=1-3, to=1-4]
\arrow["{a_4}", from=1-4, to=1-5]
\arrow[curve={height=18pt}, dashed, from=1-2, to=1-4]
\arrow[curve={height=18pt}, dashed, from=1-3, to=1-5]
\end{tikzcd}\]
\end{document}
感谢您的任何帮助!
编辑:
这是一个完整的例子:
该列表[ 4, [ (1)*a1*a2, (1)*a2*a3 ], [ (1)*a2*a3 ], [ (1)*a1*a2 ], [ (1)*a1*a2*a3 ] ]
应给出以下 4 个线性定向箭筒及其对应关系的 tikz 图片:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\begin{document}
{\tikzset{curve/.style={settings={#1},to path={(\tikztostart)
.. controls ($(\tikztostart)!\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
and ($(\tikztostart)!1-\pv{pos}!(\tikztotarget)!\pv{height}!270:(\tikztotarget)$)
.. (\tikztotarget)\tikztonodes}},
settings/.code={\tikzset{quiver/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/quiver/##1}}},
quiver/.cd,pos/.initial=0.35,height/.initial=0}
% https://q.uiver.app/#q=WzAsMTYsWzAsMCwiMSJdLFsxLDAsIjIiXSxbMiwwLCIzIl0sWzMsMCwiNCJdLFswLDEsIjEiXSxbMSwxLCIyIl0sWzIsMSwiMyJdLFszLDEsIjQiXSxbMCwyLCIxIl0sWzEsMiwiMiJdLFsyLDIsIjMiXSxbMywyLCI0Il0sWzAsMywiMSJdLFsxLDMsIjIiXSxbMiwzLCIzIl0sWzMsMywiNCJdLFswLDEsImFfMSJdLFsxLDIsImFfMiJdLFsyLDMsImFfMyJdLFs0LDUsImFfMSJdLFs1LDYsImFfMiJdLFs2LDcsImFfMyJdLFs4LDksImFfMSJdLFs5LDEwLCJhXzIiXSxbMTAsMTEsImFfMyJdLFsxMiwxMywiYV8xIl0sWzEzLDE0LCJhXzIiXSxbMTQsMTUsImFfMyJdLFswLDIsIiIsMCx7ImN1cnZlIjozLCJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XSxbMSwzLCIiLDAseyJjdXJ2ZSI6Mywic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV0sWzUsNywiIiwwLHsiY3VydmUiOjMsInN0eWxlIjp7ImJvZHkiOnsibmFtZSI6ImRhc2hlZCJ9fX1dLFs4LDEwLCIiLDAseyJjdXJ2ZSI6Mywic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV0sWzEyLDE1LCIiLDIseyJjdXJ2ZSI6Mywic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV1d
\[\begin{tikzcd}
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4
\arrow["{a_1}", from=1-1, to=1-2]
\arrow["{a_2}", from=1-2, to=1-3]
\arrow["{a_3}", from=1-3, to=1-4]
\arrow["{a_1}", from=2-1, to=2-2]
\arrow["{a_2}", from=2-2, to=2-3]
\arrow["{a_3}", from=2-3, to=2-4]
\arrow["{a_1}", from=3-1, to=3-2]
\arrow["{a_2}", from=3-2, to=3-3]
\arrow["{a_3}", from=3-3, to=3-4]
\arrow["{a_1}", from=4-1, to=4-2]
\arrow["{a_2}", from=4-2, to=4-3]
\arrow["{a_3}", from=4-3, to=4-4]
\arrow[curve={height=18pt}, dashed, from=1-1, to=1-3]
\arrow[curve={height=18pt}, dashed, from=1-2, to=1-4]
\arrow[curve={height=18pt}, dashed, from=2-2, to=2-4]
\arrow[curve={height=18pt}, dashed, from=3-1, to=3-3]
\arrow[curve={height=18pt}, dashed, from=4-1, to=4-4]
\end{tikzcd}\]
\end{document}
答案1
首先\regex_extract_all:nnN
用于获取带括号的列表。这些列表存储在中\l__Mare_arrows_seq
。然后用形成一个循环\seq_map_indexed_inline:Nn
。\arrow
命令由\tl_build_put_right:Nn
和构成\tl_build_put_right:Ne
。这些命令用插入到tikzcd
环境中\l__Mare_arrows_tl
。
\documentclass[border=6pt]{standalone}
\usepackage{tikz-cd}
\ExplSyntaxOn
\cs_generate_variant:Nn \clist_map_inline:nn { en }
\cs_generate_variant:Nn \tl_set:Nn { Ne }
\cs_generate_variant:Nn \tl_build_put_right:Nn { Ne }
\seq_new:N \l__Mare_arrows_seq
\seq_new:N \l__Mare_indices_seq
\tl_new:N \l__Mare_arrow_tl
\tl_new:N \l__Mare_arrows_tl
\NewDocumentCommand { \quiver } { r[] }
{
\regex_extract_all:nnN { \[[^\[\]]+\] } {#1} \l__Mare_arrows_seq
\tl_build_begin:N \l__Mare_arrows_tl
\seq_map_indexed_inline:Nn \l__Mare_arrows_seq
{
\tl_set:Ne \l__Mare_arrow_tl {##2}
\tl_remove_all:Nn \l__Mare_arrow_tl { [ }
\tl_remove_all:Nn \l__Mare_arrow_tl { ] }
\tl_remove_all:Nn \l__Mare_arrow_tl { a }
\clist_map_inline:en { \l__Mare_arrow_tl }
{
\seq_set_split:Nnn \l__Mare_indices_seq { * } {####1}
\tl_build_put_right:Nn \l__Mare_arrows_tl { \arrow }
\tl_build_put_right:Ne \l__Mare_arrows_tl
{
[
bend~right ,
dashed ,
from = ##1 - \seq_item:Nn \l__Mare_indices_seq { 2 } ,
to = ##1 - \int_eval:n { \seq_item:Nn \l__Mare_indices_seq { -1 } + 1 }
]
}
}
}
\tl_build_end:N \l__Mare_arrows_tl
\begin { tikzcd } [ ampersand~replacement = \& ]
\int_step_inline:nn { \seq_count:N \l__Mare_arrows_seq }
{
\int_step_inline:nn { \clist_item:nn {#1} { 1 } - 1 }
{ ####1 \arrow [ r , " { a \c_math_subscript_token {####1} } " ] \& }
\clist_item:nn {#1} { 1 }
\int_compare:nNnF {##1} = { \seq_count:N \l__Mare_arrows_seq }
{ \\ }%no \\ for the last row
}
\l__Mare_arrows_tl
\end { tikzcd }
}
\ExplSyntaxOff
\begin{document}
$\quiver[ 5, [ (1)*a2*a3, (1)*a3*a4 ], [ (1)*a1*a2, (1)*a3*a4 ], [ (1)*a1*a2*a3, (1)*a3*a4 ], [ (1)*a3*a4 ], [ (1)*a1*a2, (1)*a2*a3 ], [ (1)*a2*a3 ], [ (1)*a1*a2, (1)*a2*a3*a4 ],
[ (1)*a1*a2*a3, (1)*a2*a3*a4 ], [ (1)*a2*a3*a4 ], [ (1)*a1*a2 ], [ (1)*a1*a2*a3 ], [ (1)*a1*a2*a3*a4 ] ]$
\end{document}