4

closely related to How to implement (low-level) arrays in TeX . What is the recommended package that provides a simple abstraction of the hash feature that is in latex, at least for small-scale needs. Think

\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

It's just one global hash. This is essentially the same functionality that labels and refs provide through the .aux files. I know I have hacked around this problem a few times before, but the last times was years ago, and I can't recall how. I didn't abstract it, either. Grrr... Moreover, there may be newer packages that satisfy this need better. If no one answers this, I will look through my old tex hacks (comp.text.tex) to see what my most recent solution to this issue was. It's common enough a need to warrant a dedicated tex.stackexchange post.

I will want to use this, e.g., to define

\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}}

and in my document

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

\begin{table} \mycaption{tbl:1}{Table 1} \end{table}
  • 2
    Always place the \label after the \caption. – Werner Mar 20 '15 at 1:41
  • 4
    1) That's not what a hash set is – you're describing a dictionary. 2) You may be able to use property lists in conjunction with distinct external files – take a look at expl3 (texdoc expl3; texdoc interface3). 3) I don't know why you would want to do this in the first place. What's the actual problem? – Sean Allred Mar 20 '15 at 2:18
  • Looks as if you want to use the endfloat package with the markers option. – Ulrike Fischer Mar 20 '15 at 9:29
  • @Werner Or in the caption. – user10274 Mar 20 '15 at 10:35
  • sorry about the label caption misorder. I was just trying to sketch the application. I also edited the title. – ivo Welch Mar 20 '15 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.