哈希(字典)数据结构

哈希(字典)数据结构

密切相关如何在 TeX 中实现(低级)数组。推荐使用哪个包来提供 latex 中哈希功能的简单抽象,至少可以满足小规模需求。想想

\makeatletter
\AtBeginDocument{\hashrestore}
\newcommand{\hashinsert}[2]{\expandafter\def\csname #1\endcsname{#2}}
\newcommand{\hashget}[1]{\csname #1\endcsname}
\AtEndDocument{\hashsave}
\newcommand{\hashsave}{ ... write to file ... }
\newcommand{\hashretrieve}{ ... load from file ... }
\makeatother

它只是一个全局哈希。这本质上与标签和引用通过 .aux 文件提供的功能相同。我知道我以前曾多次解决这个问题,但最后一次是几年前的事了,我记不清是怎么回事了。我也没有抽象它。哎呀……此外,可能有更新的包可以更好地满足这一需求。如果没有人回答这个问题,我会查看我以前的 tex hacks (comp.text.tex),看看我最近对这个问题的解决方案是什么。这是一个很常见的需求,值得专门发一篇 tex.stackexchange 帖子。

我想要使​​用它来定义

\usepackage{hash}
\newcommand{\mycaption}[2]{\caption{#2}\label{#1}\hashinsert{#1}{#2}}
\newcommand{\myinshere}[1]{\begin{center} Insert Table \ref{#1}: \hashget{#1} \end{center}}

在我的文档中

...
\myinshere{tbl:1}
...

\begin{table} \mycaption{tbl:1}{Table 1} \end{table}

相关内容