From c3dd41d8e602553e24e252a9f37f3d9f5237f759 Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Sat, 13 Apr 2024 11:55:19 +0200 Subject: [PATCH] Added convenience macros to add types --- doc/crossrefenum.md | 8 ++++---- tex/crossrefenum.tex | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/crossrefenum.md b/doc/crossrefenum.md index 2873cf4..d20300c 100644 --- a/doc/crossrefenum.md +++ b/doc/crossrefenum.md @@ -215,6 +215,8 @@ use an empty group (e.g. `\def\crfnmPageEnumDelim{}`). Adding support for new types consists in defining the related macros in your preamble. Here is a commented example that would add support for references to lines in ConTeXt if this feature were not already included in _crossrefenum_. +We suppose that the labels are inserted in the document using the standard ConTeXt macros, +i.e. `\someline` for line references and `\pagereference` for page references. ```{.tex} % Register the types. Take care about capitalization! @@ -226,10 +228,8 @@ if this feature were not already included in _crossrefenum_. \def\crfnm@pageline{Pageline} %% Add them to the lists of known types. -\crfnm@newListFrom[\crfnm@simpleRefTypes][\crfnm@line] -> \crfnm@simpleRefTypes -\crfnm@newListFrom[\crfnm@doubleRefTypes][\crfnm@pageline] -> \crfnm@doubleRefTypes -\crfnm@newListFrom[\crfnm@supportedTypes][\crfnm@line] -> \crfnm@supportedTypes -\crfnm@newListFrom[\crfnm@supportedTypes][\crfnm@pageline] -> \crfnm@supportedTypes +\crfnm@declareType[simple][\crfnm@line] +\crfnm@declareType[double][\crfnm@pageline] ``` ```{.tex} diff --git a/tex/crossrefenum.tex b/tex/crossrefenum.tex index 46196ed..695f6bf 100644 --- a/tex/crossrefenum.tex +++ b/tex/crossrefenum.tex @@ -472,8 +472,7 @@ \def\crfnm@newListFrom[#1][#2] -> #3{% % #1 is either a list or a reference. - % #2 is a reference. - % #2 is appended to #1. + % #2 is the reference appended to #1. % #3 is the control sequence which the resulting list will be bound to. \crfnm@ifIsList[#1]{% \edef#3{#1{#2}}% @@ -481,6 +480,12 @@ \edef#3{{#1}{#2}}% }% } +\def\crfnm@addToList[#1][#2]{\crfnm@newListFrom[#1][#2] -> #1} +\def\crfnm@declareType[#1][#2]{% + % #1 is "simple" or "double", #2 is the type + \expandafter\crfnm@addToList\expandafter[\csname crfnm@#1RefTypes\endcsname][#2]% + \crfnm@addToList[\crfnm@supportedTypes][#2]% +} \def\crfnm@replaceFirstInList[#1]#2{% % #1 is a token, #2 is a list of tokens