% ^^A ================================  元注释  ================================
% \iffalse meta-comment
%
% 文件：drawmgr.dtx
%
% 版权 (C) 2024-2026 By Ms_yam
%
% 它可以在 LaTeX 项目公共许可（LPPL）1.3c 及之后的任意版本（随你的意见）下分发或修改。
% 这个许可的最新版本在如下文件中：
%
%   https://www.latex-project.org/lppl.txt
% 
% 本文件的 LPPL 维护状态为 "maintained"。
% 
% 本文件的当前维护者是 Ms_yam。
%
% \fi
%
% ^^A ================================ 安装信息 ================================
%
% \changes{v0.3}{2026-01-27}{添加仅提取文件的支持}
% 
% \iffalse 
%<*install>
\begingroup

\input docstrip.tex
\keepsilent
\usedir{tex/latex/drawmgr}
\askforoverwritefalse

\preamble
\endpreamble

\postamble
\endpostamble

\generate{
    \file{drawmgr.ins} {\from{\jobname.dtx}{install}}
    \file{drawmgr.sty} {\from{\jobname.dtx}{package}}   
    \nopreamble\nopostamble
    \file{README.md}   {\from{\jobname.dtx}{readme}}
  }

\ifx\documentclass\@undefined
  \endbatchfile
\fi

\endgroup
%</install>
% \fi
%
% ^^A ================================ 文档驱动 ================================ 
%
% \changes{v0.1}{2024-12-02}{内部测试发行}
% \changes{v0.3}{2026-01-27}{添加颜色以便于区分}
% \changes{v0.3}{2026-01-27}{更新 texnote 环境的定义}
% 
% \iffalse
%<*driver>
\documentclass[show-notes]{l3doc}
\usepackage[language=cn]{drawmgr}
\usepackage{ctex}
\usepackage{l3draw}
\usepackage{xcolor}

% ^^A 修改颜色
\definecolor{verb}{HTML}{008000}
\definecolor{code}{HTML}{a25e26}
\definecolor{desc}{HTML}{000060}
\let\OriginalMF\MacroFont
\AtBeginEnvironment{verbatim}{\color{verb}}
\makeatletter
\pretocmd{\macrocode}
  {
    \def\macro@font{\color{code}\OriginalMF}
    \def\MacroFont {\color{code}\OriginalMF}
  }{}{}
\makeatother

% ^^A 提取双语命令
\NewDocumentCommand { \desc } { s +m m }
  { #2 \IfBooleanF {#1} {\\} \textcolor{desc} { \texttt{#3} } }

% ^^A 汉化 l3doc 的部分定义
\DeclareDocumentEnvironment { texnote } { }
  {
    \endgraf
    \vspace{0.5em}% 3mm => 0.5em
    \small\textbf{\TeX{} 黑客笔记~\textcolor{desc}{\TeX~hackers~note}}%
    \par 
  }
  { \vspace{0.5em} }% 3mm => 0.5em

% ^^A 排除索引
\DoNotIndex{ \begin, \end, \label, \par, \textwidth, \rule, \caption, \captionsetup, \centering }
\DoNotIndex
  { 
    \NeedsTeXFormat, \RequirePackage, \ProvidesExplPackage, \ProcessKeyOptions, 
    \NewDocumentCommand, \NewDocumentEnvironment, \ExplSyntaxOn, \ExplSyntaxOff, 
    \IfNoValueTF, \IfNoValueT, \IfBooleanTF, \IfBooleanT, \IfBooleanF
  }
\DoNotIndex{ \group_begin:, \group_end: }
\DoNotIndex{ \cs_new:Nn, \cs_new:Npn, \cs_undefine:N, \cs_generate_variant:Nn }
\DoNotIndex
  { 
    \prg_new_conditional:Nnn, \prg_generate_conditional_variant:Nnn, 
    \prg_replicate:nn, \prg_return_true:, \prg_return_false: 
  }
\DoNotIndex{ \msg_new:nnn, \msg_error:nnn, \msg_error:nnV }
\DoNotIndex
  { 
    \bool_new:N, \bool_new:c, 
    \bool_gset_eq:NN, \bool_gset_eq:Nc, \bool_gset_eq:cN, \bool_set_eq:NN, 
    \bool_gset_true:N, \bool_set_true:N, \bool_set_false:N, 
    \bool_if:NT, \bool_if:NF, \bool_if:NTF, \bool_if:nTF, 
    \bool_show:N, \bool_log:N, \bool_until_do:nn, \c_true_bool
  }
\DoNotIndex
  { 
    \tl_new:N, \tl_const:Nn, \tl_clear:N, \tl_set_eq:NN, \tl_set:Nn, \tl_set:Ne, 
    \tl_if_empty:NTF, \tl_if_empty:NT, \tl_if_empty:NF, \tl_if_empty:nTF,
    \tl_if_eq:NnTF, \tl_if_eq:VnT, \tl_if_in:NnT, 
    \tl_put_right:Nn, \tl_put_right:NV, \tl_replace_all:Nnn, \tl_to_str:N, \tl_to_str:n
  }
\DoNotIndex
  { 
    \str_new:N, \str_const:Nn, \str_const:Ne, \str_set:Nn, \str_set:Ne, 
    \str_clear:N, \str_put_right:Nn, 
    \str_if_eq:nnT, \str_if_eq:VnT, \str_if_eq:nnTF, \str_if_eq:VnTF, 
    \str_if_empty:nTF, \str_if_in:NnF, \str_if_in:nnTF, 
    \str_case:Vn, \str_case:nnF, \str_case:VnF, \str_case_e:nnF, \str_map_inline:nn,
    \str_casefold:n, \str_casefold:V,
    \l_tmpa_str 
  }
\DoNotIndex{ \char_generate:nn }
\DoNotIndex
  { 
    \regex_const:Nn, \regex_match:nnTF, 
    \regex_extract_all:NnN, \regex_extract_all:NnNF, \regex_extract_all:nnNF 
  }
\DoNotIndex
  { 
    \int_new:N, \int_new:c, \int_gset_eq:NN, \int_gset_eq:Nc, \int_gset_eq:cN, \int_set_eq:NN, 
    \int_zero:N, \int_gzero:N, \int_incr:N, \int_gincr:N, \int_gset:Nn, \int_set:Nn, 
    \int_if_zero:nTF, \int_if_zero:nT, \int_if_zero:nF, 
    \int_case:nn, \int_compare:nNnT, \int_compare:nNnF, \int_compare:nNnTF, 
    \int_step_inline:nn, \int_step_inline:nnn, \int_step_inline:nnnn, 
    \int_max:nn, \int_use:N, \int_to_Alph:n,\int_show:N, \int_log:N
  }
\DoNotIndex
  { 
    \dim_new:N, \dim_const:Nn, \dim_zero:N, \dim_set_eq:NN, 
    \dim_gset:Nn, \dim_set:Nn, \dim_add:Nn, \dim_sub:Nn, \dim_max:nn, \dim_eval:n, 
    \dim_compare:nNnT, \dim_compare:nNnTF, \dim_use:N
  }
\DoNotIndex{ \seq_new:N, \seq_new:c, \seq_gset_eq:Nc, \seq_gset_eq:cN, \seq_set_eq:NN, 
  \seq_gclear:N, \seq_clear:N, \seq_set_split:Nnn, \seq_set_split:NVn, \seq_set_split:NnV, \seq_set_split:NVV,
  \seq_if_empty_p:N, \seq_if_empty:NT, \seq_if_empty:NTF, \seq_count:N, 
  \seq_gput_left:Nn, \seq_gput_left:NV, \seq_gput_right:Nn, \seq_gput_right:Ne, \seq_gput_right:NV, 
  \seq_gpop_left:NN, \seq_pop_left:NN, \seq_put_right:Nn, \seq_put_right:NV, 
  \seq_gset_item:Nnn, \seq_gset_item:Nne, \seq_gset_item:NnV, \seq_set_item:Nnn, 
  \seq_get_left:NN, \seq_get_right:NN, \seq_item:Nn,
  \seq_map_function:NN, \seq_map_inline:Nn, \seq_show:N, \seq_log:N
}
\DoNotIndex{ \prop_new:N, \prop_new:c, \prop_gset_eq:Nc, \prop_gset_eq:cN,
  \prop_gclear:N, \prop_clear:N, \prop_gset_eq:NN, \prop_if_empty:NTF, 
  \prop_if_in:NnTF, \prop_if_in:NnT, \prop_if_in:NnF, \prop_if_in:NVTF, 
  \prop_gput:Nnn, \prop_gput:Nne, \prop_gput:Nen, \prop_gput:NVn, \prop_gput:NVe, \prop_put:Nnn, 
  \prop_gpop:NnN, \prop_gpop:NeN, 
  \prop_get:NnN, \prop_get:NVN, \prop_get:NnNF, \prop_get:NnNTF, \prop_item:Nn,
  \prop_map_inline:Nn, \prop_show:N, \prop_log:N
}
\DoNotIndex{ \scan_new:N }
\DoNotIndex{ \clist_new:N, \clist_set_eq:NN, \clist_set:Nn, \clist_gset:Nn, 
  \clist_if_in:nVTF, \clist_count:N, \clist_item:Nn, \clist_item:nn, \clist_map_inline:nn }
\DoNotIndex{ \keys_define:nn, \keys_set:nn, \l_keys_choice_tl }
\DoNotIndex{ \box_new:N, \box_ht:N, \box_dp:N, \box_set_dp:Nn, \box_wd:N, \box_use:N, 
  \hbox:n, \hbox_set:Nn, \vbox_set:Nn, \vbox_set_top:Nn, \vbox_set_to_ht:Nnn 
}
\DoNotIndex{ \color_stroke:n, \color_stroke:e }

\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%
% ^^A ================================ README ================================
%
% \changes{v0.2}{2025-12-25}{为 drawmgr 添加 README}
% 
% \iffalse
%<*readme> ^^A README

# 基本说明 Description

本宏包提供一个集体管理绘图脚本的工具；
它允许用户将绘图脚本组织成模块，并在文档中按需调用。

This package provides a tool for collectively managing drawing 
scripts, which allows users to organize drawing scripts into 
modules and call them on demand in documents.


# 许可 License

版权 Copyright (C) 2023-2026 By Ms_yam


本宏包可以在 LaTeX 项目公共许可（LPPL）1.3c 及之后的任意版本（随你的意见）下分发或修改。
这个许可的最新版本在如下文件中：

   https://www.latex-project.org/lppl.txt

It 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

   https://www.latex-project.org/lppl.txt


本文件的 LPPL 维护状态为 "maintained"。

This file has LPPL maintenance status "maintained".

本文件的当前维护者是 Ms_yam。

The current maintainer of this file is Ms_yam.

本宏包由以下文件组成：
  drawmgr.dtx（源代码）、
  drawmgr.ins、
  drawmgr.sty、
  drawmgr.pdf 和 
  README.md （本文件）。

This package consists of 
  the source file  drawmgr.dtx,
  the install file drawmgr.ins,
  the drived files drawmgr.sty,
                   drawmgr.pdf and
                   README.md(this file).

# 编译 Compilation

本宏包设计为单文件包，你可以直接使用以下命令编译：

This package is designed as a single-file package and can be
compiled directly with the following commands:

```sh
# 提取宏包文件
xetex drawmgr.dtx

# 使用 XeLaTeX 编译文档
xelatex drawmgr.dtx
makeindex -s gglo.ist -o drawmgr.gls drawmgr.glo
makeindex -s gind.ist -o drawmgr.ind drawmgr.idx
xelatex drawmgr.dtx
xelatex drawmgr.dtx
```

# 备注 Remark

英文版本描述由 AI 翻译，如有差异，请以中文版本为准。

The English version description is translated by AI. In case of 
any discrepancies, please refer to the Chinese version as the standard.

%</readme>
% \fi
% 
%
% ^^A ================================ 文档内容 ================================ 
%
% \title{集中管理图形脚本的宏\\[0.5em]\large
%   \textcolor{desc}{Macros for Centralized Management of Graphics Scripts} }
% \author{Ms_yam（\href{mailto:Ms_yam@163.com}{Ms_yam@163.com}）}
% \date{\zhdigits*{2026}年\zhnumber{01}月\zhnumber{28}日}
%
% \maketitle
%
% ^^A -------------------------------- 文档部分 --------------------------------
%
% \begin{documentation}
%
% \section{文档 \textcolor{desc}{Documentation}}
%
% 本宏包设计用于集中管理 \LaTeX 图形脚本，以便维护。\par
% \textcolor{desc}{This package is designed to centrally manage 
% \LaTeX{} graphics scripts for easier maintenance.}
%
% \subsection{用户接口 \textcolor{desc}{User Interface}}
%
%
% \begin{function}[updated=2026-01-27]{\newdraw, \usedraw}
%   \begin{syntax}
%     \cs{newdraw} \Arg{图形索引} \Arg{图形脚本}
%     \textcolor{desc}{ \cs{newdraw} \Arg{graphics-index} \Arg{graphics-script} }
%     \cs{usedraw} \Arg{图形索引}
%     \textcolor{desc}{ \cs{usedraw} \Arg{graphics-index} }
%   \end{syntax}
%   \desc*{创建和使用图形。}{Create and use graphics.}   
%   \begin{texnote}
%     当前版本会确认图形索引是否可用，若检查不通过则报错。
%     使用星号版本可跳过此项检查。\par
%     \textcolor{desc}{
%     The current version verifies whether the graphic index is available. 
%     If the check fails, an error will be reported. 
%     Using the star version allows skipping this check.}
%   \end{texnote}
% \end{function}
%
% 
% \noindent\desc*{例如，以下示例：}{For example, the following example:}
% \begin{verbatim}
%   \ExplSyntaxOn
%   \newdraw{sampleA}
%     {
%       \draw_begin:
%         \color_select:n { green!30!black } 
%         \draw_path_rectangle:nn { 0cm, 0cm } { 4cm, 3cm }
%         \draw_path_circle:nn { 1cm, 1.1cm } { 0.8cm }
%         \draw_path_circle:nn { 2.5cm, 1.5cm } { 1.2cm }
%         \draw_path_use_clear:n { stroke }
%         \hbox_set:Nn \l_tmpa_box { $PicA$ }
%         \draw_box_use:Nn \l_tmpa_box { 0.5cm, 2.5cm }
%       \draw_end:
%     }
%   \newdraw{sampleB}
%     {
%       \draw_begin:
%         \color_select:n { red!30!black } 
%         \draw_path_rectangle:nn { 0cm, 0cm } { 4cm, 3cm }
%         \draw_path_circle:nn { 1cm, 1.1cm } { 0.8cm }
%         \draw_path_circle:nn { 2.5cm, 1.5cm } { 1.2cm }
%         \draw_path_use_clear:n { stroke }
%         \hbox_set:Nn \l_tmpa_box { $PicB$ }
%         \draw_box_use:Nn \l_tmpa_box { 0.5cm, 2.5cm }
%       \draw_end:
%     }
%   \usedraw{sampleB}
%   \ \ \ \ 
%   \usedraw{sampleA}
%   \ExplSyntaxOff
% \end{verbatim}
% \desc*{将输出：}{Will result:}
% 
%   \ExplSyntaxOn
%   \newdraw{sampleA}
%     {
%       \draw_begin:
%         \color_select:n { green!30!black } 
%         \draw_path_rectangle:nn { 0cm, 0cm } { 4cm, 3cm }
%         \draw_path_circle:nn { 1cm, 1.1cm } { 0.8cm }
%         \draw_path_circle:nn { 2.5cm, 1.5cm } { 1.2cm }
%         \draw_path_use_clear:n { stroke }
%         \hbox_set:Nn \l_tmpa_box { $PicA$ }
%         \draw_box_use:Nn \l_tmpa_box { 0.5cm, 2.5cm }
%       \draw_end:
%     }
%   \newdraw{sampleB}
%     {
%       \draw_begin:
%         \color_select:n { red!30!black } 
%         \draw_path_rectangle:nn { 0cm, 0cm } { 4cm, 3cm }
%         \draw_path_circle:nn { 1cm, 1.1cm } { 0.8cm }
%         \draw_path_circle:nn { 2.5cm, 1.5cm } { 1.2cm }
%         \draw_path_use_clear:n { stroke }
%         \hbox_set:Nn \l_tmpa_box { $PicB$ }
%         \draw_box_use:Nn \l_tmpa_box { 0.5cm, 2.5cm }
%       \draw_end:
%     }
%   \usedraw{sampleB}
%   \ \ \ \ 
%   \usedraw{sampleA}
%   \ExplSyntaxOff
%
%
% \begin{function}{\showdraw, \cleardraw}
%   \begin{syntax}
%     \cs{showdraw} [*]
%     \cs{cleardraw}
%   \end{syntax}
%   \desc{显示或清空已添加的图形。星号版本会显示索引及图形本身。}
%   {Display or clear added graphics. 
%   The starred version shows both indices and graphics.}
% \end{function}
%
% \noindent 
% \desc*{不带星号的版本（\cs{showdraw}）效果如下：}
% {The without star version results:}\par
% \showdraw
%
% \noindent 
% \desc*{带星号的版本（\cs{showdraw}*）效果如下：}
% {The without star version results:}\par
% \showdraw*
%
% \changes{v0.2}{2025-12-25}{添加插入图形浮动体的功能}
% 
% \begin{function}[added=2025-12-25]{\setfigurewidth}
%   \begin{syntax}
%     \cs{setfigurewidth} \Arg{宽度列表} 
%     \textcolor{desc}{\cs{setfigurewidth} \Arg{wd-clist} }
%   \end{syntax}
%   设置并排排版两张或三张图形时的各图形的宽度比例。
%   \Arg{宽度列表} 是一个长度为 $2$ 或 $3$ 的逗号分隔的列表，
%   每个元素代表一张图形其相对于当前文本宽度的比例。
%   注意，图形之间包含一个 $0.05$ 倍的文本宽度，即逗号列表之和不应当大于 
%   $1 - 0.05(n-1)$。\\
%   \textcolor{desc}{Set the width ratios of each figure when 
%   typesetting two or three figures side by side.
%   \Arg{wd-clist} is a comma-separated list of length 2 or 3, 
%   where each element represents the ratio of the corresponding 
%   figure relative to the current text width.
%   Note that there is a gap of 0.05 times the text width 
%   between adjacent figures, meaning the sum of the values 
%   in the comma-separated list should not exceed $1-0.05(n-1)$.}
%   \begin{texnote}
%     这个命令用于修改 \cs{addfiguredbl}、\cs{addfigurethr} 命令插入的图形的默认宽度。
%     \par \textcolor{desc}{
%     This command is used to modify the default widths of the figures 
%     inserted by the \cs{addfiguredbl} and \cs{addfigurethr} commands.}
%   \end{texnote}
% \end{function}
%
% \begin{function}[updated=2025-12-25]{\addfigure, \addfiguredbl, \addfigurethr}
%   \begin{syntax}
%     \cs{addfigure} \Arg{图形索引} \oarg{图形标签} \Arg{图形标题}
%     \textcolor{desc}{\cs{addfigure} \Arg{graph-index} \oarg{graph-label} \Arg{graph-title} }
%   \end{syntax}
%   使用浮动体添加插图。插图内容为 \Arg{图形索引} 关联的图形，插图标题由 \Arg{图形标题} 指定。
%   本命令会自动为插图添加标签（|fig:|\Arg{图形标签}），\Arg{图形标签} 
%   默认与 \Arg{图形索引}  一致。对于多个图形，每个图形的参数完全一致。\par
%   \textcolor{desc}{Using a floating environment to add illustrations. 
%   The content of the illustration corresponds to the graphic associated 
%   with \Arg{graph-index}, and the caption is specified by \Arg{graph-title}. 
%   This command automatically adds a label to the illustration (|fig:|
%   \Arg{graph-label}), where \Arg{graph-label} defaults to \Arg{graph-index}. 
%   For multiple graphics, the parameters for each graphic are completely consistent.}
%   \begin{texnote}
%     单个图形始终独立整个文本宽度，多个图形则按 \cs{setfigurewidth} 指定的比例排版。
%     对于两个图形的场景，还可以使用可选参数（参数一）来临时指定图形的宽度。\par
%     \textcolor{desc}{A single figure always occupies the full text width 
%     independently, while multiple figures are typeset according to the ratios
%     specified by \cs{setfigurewidth}. For the scenario with two figures, 
%     an optional parameter (Parameter 1) can also be used to temporarily 
%     specify the widths of the figures.}
%   \end{texnote}
% \end{function}
%
%
% \noindent\desc*{例如，以下示例：}{For example, the following example:}
% 
% \begin{verbatim}
%   \setfigurewidth { 0.3,  0.3 }
%   \setfigurewidth { 0.27, 0.27, 0.27 }
%   \addfigure    {sampleA} [addfigure]      {\cs{addfigure} 的效果} 
%   \addfiguredbl {sampleA} [addfiguredbl.1] {两张图的效果1} 
%                 {sampleB} [addfiguredbl.2] {两张图的效果2}
%   \addfigurethr {sampleA} [addfigurethr.1] {三张图的效果1} 
%                 {sampleB} [addfigurethr.2] {三张图的效果2} 
%                 {sampleA} [addfigurethr.3] {三张图的效果3}
% \end{verbatim}
%
%
% \noindent \desc*{将输出图 \ref{fig:addfigure} \~{} \ref{fig:addfigurethr.3}。}
% {will output pic \ref{fig:addfigure} \~{} \ref{fig:addfigurethr.3}. }
% 
% \setfigurewidth {0.3, 0.3}
% \setfigurewidth {0.27, 0.27, 0.27}
% \addfigure{sampleA} [addfigure] {\cs{addfigure} 的效果}
% \addfiguredbl{sampleA} [addfiguredbl.1] {两张图的效果1} 
%              {sampleB} [addfiguredbl.2] {两张图的效果2}
% \addfigurethr{sampleA} [addfigurethr.1] {三张图的效果1} 
%              {sampleB} [addfigurethr.2] {三张图的效果2} 
%              {sampleA} [addfigurethr.3] {三张图的效果3}
%
% 
% \changes{v0.3}{2026-01-28}{新增图表混排功能}
% 
% \begin{function}[added=2026-01-28]{\addfiguretable, \addtablefigure}
%   \begin{syntax}
%     \cs{addtablefigure} \Arg{表格数据} \oarg{表格标签} \Arg{表格标题} \Arg{图形的三个参数...}
%     \textcolor{desc}{\cs{addtablefigure} \Arg{table-data} \oarg{table-label} \Arg{table-title} \Arg{draw-args...} }
%   \end{syntax}
%   使用浮动体并排添加表格与插图。表格内容为 \Arg{表格数据}，表格标题由\Arg{表格标题} 指定。
%   本命令会自动为表格添加标签（|tab:|\Arg{表格标签}）。
%   对于图形，其参数与 \cs{addfigure} 的参数完全一致。\par
%   \textcolor{desc}{Use a floating environment to place a table and an 
%   illustration side by side. The table content is specified by 
%   \Arg{table data}, and the table caption is given by \Arg{table caption}.
%   This command will automatically add a label to the table (|tab:|\Arg{table label}).
%   For graphic, the parameters are exactly the same as those of \cs{addfigure}.}
%   \begin{texnote}
%     表格与图形的宽度分配使用类似 \cs{addfiguredbl} 的原理。
%     本命令需要开启 \texttt{table} 选项，并会加载 \pkg{catption} 宏包。\par
%     \textcolor{desc}{The width distribution between the table and 
%     the graphic follows a principle similar to \cs{addfiguredbl}. 
%     This command requires the \texttt{table} option to be enabled and then 
%     will load the \pkg{catption} package.}\par
%     \textbf{警告：并排图表为单一浮动体内部排版，不等价于独立 table 浮动体，仅保证编号正确。}\par
%     \textcolor{desc}{\textbf{ Warning: When figures and tables are placed side by side, 
%     they are arranged inside a single floating environment.
%     This does not create independent table floats; 
%     only the table counter and numbering are preserved.} }
%   \end{texnote}
% \end{function}
% 
% 
% \end{documentation}
% \clearpage
%
% ^^A ---------------------------------- 实现部分 ----------------------------------
%
% \begin{implementation}
%
% \section{代码实现 Implementation}
%
% \subsection{初始化 Init}
%
%    \begin{macrocode}
%<*package>
%<@@=drawmgr>
\ExplSyntaxOn
\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{drawmgr}{2026-01-28}{0.3} 
  {集中管理图形脚本的宏}
%    \end{macrocode}
%
%
% \subsection{变量 Variable}
%
%
% \begin{variable}{\g_@@_scripts_prop, \g_@@_wd_dbl_clist, \g_@@_wd_thr_clist, \l_@@_wd_clist}
% 变量定义：
%    \begin{macrocode}
\prop_new:N   \g_@@_scripts_prop
\clist_new:N  \g_@@_wd_dbl_clist
\clist_new:N  \g_@@_wd_thr_clist
\clist_new:N  \l_@@_wd_clist
%    \end{macrocode}
%    \begin{macrocode}
\clist_set:Nn \g_@@_wd_dbl_clist { 0.49, 0.49 }
\clist_set:Nn \g_@@_wd_thr_clist { 0.33, 0.33, 0.33 }
%    \end{macrocode}
% \end{variable}
% 
% \subsection{选项 Options}
% 
% \changes{v0.3}{2026-01-27}{添加宏包选项}
% 
% \begin{variable}{\g_@@_language_int, \g_@@_language_str, \g_@@_table_bool}
% 定义选项相关的变量：
%    \begin{macrocode}
\int_new:N  \g_@@_language_int
\str_new:N  \g_@@_language_str
\bool_new:N \g_@@_table_bool
%    \end{macrocode}
% \end{variable}
% 
% \begin{variable}{drawmgr/preamble}
% 定义宏包选项：
%    \begin{macrocode}
\keys_define:nn { drawmgr / preamble }
  {
    language  .str_gset:N = \g_@@_language_str,
    language  .initial:n  = {zh-CN},
    language  .usage:n    = {load},
    table     .bool_set:N = \g_@@_table_bool,
    table     .initial:n  = {false},
    table     .default:n  = {true},
    table     .usage:n    = {load}
  }
%    \end{macrocode}
% 处理选项：
%    \begin{macrocode}
\ProcessKeyOptions [ drawmgr / preamble ]
\str_case_e:nnF { \str_casefold:V \g_@@_language_str }
  {
    {en}    { \int_gset:Nn \g_@@_language_int {1} }
    {zh-cn} { \int_gset:Nn \g_@@_language_int {2} }
    {zh}    { \int_gset:Nn \g_@@_language_int {2} }
    {cn}    { \int_gset:Nn \g_@@_language_int {2} }
  }
  { \int_gset:Nn \g_@@_language_int {2} }
\bool_if:NT \g_@@_table_bool
  { \RequirePackage { caption  } }
%    \end{macrocode}
% \end{variable}
% 
% \subsection{消息 Message}
%
% \changes{v0.3}{2026-01-27}{添加错误消息}
%
% 常见的错误消息。
%    \begin{macrocode}
\int_compare:nNnTF {\g_@@_language_int} = {1}
  {
    \msg_new:nnn {drawmgr} {unknown_draw_index}     {Unknown draw index: <#1>}
    \msg_new:nnn {drawmgr} {already_existing_index} {Already existing index: <#1>}
  }
  {
    \msg_new:nnn {drawmgr} {unknown_draw_index}     {未知的图形索引：<#1>}
    \msg_new:nnn {drawmgr} {already_existing_index} {已使用的图形索引：<#1>}
  }
%    \end{macrocode}
%
% \subsection{命令 Command}
% 
% \subsubsection{核心 Core} 
% 
% \changes{v0.3}{2026-01-28}{添加英文支持}
% 
% \begin{macro}{\newdraw, \usedraw, \showdraw, \cleardraw}
% 定义保存、使用、显示、清空图形脚本：
%    \begin{macrocode}
\NewDocumentCommand \newdraw { s m +m }
  {
    \IfBooleanF {#1}
      {
        \prop_if_in:NnT \g_@@_scripts_prop {#2}
          { \msg_error:nnn {drawmgr} {already_existing_index} {#2} }
      }
    \prop_gput:Nnn \g_@@_scripts_prop { #2 } { #3 }
  }
\NewDocumentCommand \usedraw { s m }
  {
    \prop_if_in:NnTF \g_@@_scripts_prop { #2 }
      { \prop_item:Nn \g_@@_scripts_prop { #2 } }
      { 
        \IfBooleanF {#1} 
          { \msg_error:nnn {drawmgr} {unknown_draw_index} {#2} }
      }
  }
\NewDocumentCommand \showdraw { s }
  {
    \IfBooleanTF { #1 }
      {
        \int_compare:nNnTF {\g_@@_language_int} = {1}
          { The~saved~graphics~are~as~follows:~\par }
          { 已保存的图形如下：\par }
        \prop_map_inline:Nn \g_@@_scripts_prop
          { ##1: \par ##2 \par }
      }
      {
        \int_compare:nNnTF {\g_@@_language_int} = {1}
          { Saved~graphics:~ }
          { 已保存的图形有： }
        \prop_map_inline:Nn \g_@@_scripts_prop
          { ##1 ；}
      }
  }
\NewDocumentCommand \cleardraw { }
  {
    \prop_gclear:N \g_@@_scripts_prop
  }
%    \end{macrocode}
% \end{macro}
%
% 
% \subsubsection{浮动体 Float} 
% 
% 
% \begin{macro}{\setfigurewidth}
% 设置图形宽度：
%    \begin{macrocode}
\NewDocumentCommand \setfigurewidth { m }
  {
    \clist_set:Nn \l_@@_wd_clist { #1 }
    \int_compare:nNnTF { \clist_count:N \l_@@_wd_clist } = { 2 }
      { \clist_gset:Nn \g_@@_wd_dbl_clist { #1 } }
      { \clist_gset:Nn \g_@@_wd_thr_clist { #1 } }
  }
%    \end{macrocode}
% \end{macro}
% 
% 
% 
% \begin{macro}{\@@_insert_draw:nnnn}
% 向文档中插入图片（|#1| 图形宽度；|#2| 图形索引；|#3| 图形标签；|#4| 图形标题名）：
%    \begin{macrocode}
\cs_new:Npn \@@_insert_draw:nnnn #1#2#3#4
  {
    \begin{minipage}[t]{ #1\textwidth } 
      \centering
      \usedraw{#2}
      \caption{#4}
      \label{fig:#3}
    \end{minipage}
  }
\cs_generate_variant:Nn \@@_insert_draw:nnnn { Vnnn }
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\@@_insert_table:nnnn}
% 向文档中插入表格（|#1| 表格宽度；|#2| 表格内容；|#3| 表格标签；|#4| 表格标题名）：
%    \begin{macrocode}
\cs_new:Npn \@@_insert_table:nnnn #1#2#3#4
  {
    \begin{minipage}[b]{ #1\textwidth } 
      \centering
      \captionof{table}{#4}
      \label{tab:#3}
      #2
    \end{minipage}
  }
\cs_generate_variant:Nn \@@_insert_table:nnnn { Vnnn }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\addfigure, \addfiguredbl, \addfigurethr}
% 用于（并排）插入单张、两张或三张图片：
%    \begin{macrocode}
\NewDocumentCommand \addfigure {  m o m }
  {
    \begin{figure}[!htbp]
      \centering
      \IfNoValueTF { #2 }
        { \@@_insert_draw:nnnn { 1 } { #1 } { #1 } { #3 } }
        { \@@_insert_draw:nnnn { 1 } { #1 } { #2 } { #3 } }        
    \end{figure}
  }
\NewDocumentCommand \addfiguredbl { o m o m m o m }
  {
    \IfNoValueTF {#1}
      { \clist_set_eq:NN \l_@@_wd_clist \g_@@_wd_dbl_clist }
      { \clist_set:Nn \l_@@_wd_clist {#1} }
    \begin{figure}[!htbp]
      \centering
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 1 } }
      \IfNoValueTF { #3 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #2 } { #2 } { #4 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #2 } { #3 } { #4 } }        
      \rule{ 0.05\textwidth } { 0pt }
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 2 } }
      \IfNoValueTF { #6 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #5 } { #5 } { #7 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #5 } { #6 } { #7 } }    
    \end{figure}
  }
\NewDocumentCommand \addfigurethr { m o m m o m m o m }
  {
    \clist_set_eq:NN \l_@@_wd_clist \g_@@_wd_thr_clist
    \begin{figure}[!htbp]
      \centering
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 1 } }
      \IfNoValueTF { #2 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #1 } { #1 } { #3 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #1 } { #2 } { #3 } }  
      \rule{ 0.05\textwidth } { 0pt }
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 2 } }
      \IfNoValueTF { #5 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #4 } { #4 } { #6 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #4 } { #5 } { #6 } }    
      \rule{ 0.05\textwidth } { 0pt }
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 3 } }
      \IfNoValueTF { #8 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #7 } { #7 } { #9 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #7 } { #8 } { #9 } }       
    \end{figure}
  }
%    \end{macrocode}
% \end{macro}
% 
% 
% \begin{macro}{\addfiguretable, \addtablefigure}
% 用于并排图片与表格：
%    \begin{macrocode}
\NewDocumentCommand \addfiguretable { o m o m +m o m }
  {
    \IfNoValueTF {#1}
      { \clist_set_eq:NN \l_@@_wd_clist \g_@@_wd_dbl_clist }
      { \clist_set:Nn \l_@@_wd_clist {#1} }
    \begin{figure}[!htbp]
      \centering
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 1 } }
      \IfNoValueTF { #3 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #2 } { #2 } { #4 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #2 } { #3 } { #4 } }        
      \rule{ 0.05\textwidth } { 0pt }
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 2 } }
      \IfNoValueTF { #6 }
        { \@@_insert_table:Vnnn \l_tmpa_str { #5 } { #7 } { #7 } }
        { \@@_insert_table:Vnnn \l_tmpa_str { #5 } { #6 } { #7 } }    
    \end{figure}
  }
\NewDocumentCommand \addtablefigure { o +m o m m o m }
  {
    \IfNoValueTF {#1}
      { \clist_set_eq:NN \l_@@_wd_clist \g_@@_wd_dbl_clist }
      { \clist_set:Nn \l_@@_wd_clist {#1} }
    \begin{figure}[!htbp]
      \centering
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 1 } }
      \IfNoValueTF { #3 }
        { \@@_insert_table:Vnnn \l_tmpa_str { #2 } { #4 } { #4 } }
        { \@@_insert_table:Vnnn \l_tmpa_str { #2 } { #3 } { #4 } }        
      \rule{ 0.05\textwidth } { 0pt }
      \str_set:Ne \l_tmpa_str { \clist_item:Nn \l_@@_wd_clist { 2 } }
      \IfNoValueTF { #6 }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #5 } { #5 } { #7 } }
        { \@@_insert_draw:Vnnn \l_tmpa_str { #5 } { #6 } { #7 } }    
    \end{figure}
  }
\bool_if:NF \g_@@_table_bool
  { 
    \cs_undefine:N \addfiguretable 
    \cs_undefine:N \addtablefigure
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ExplSyntaxOff
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintChanges
% \PrintIndex
% 
\endinput
