I found a solution, but it's tricky (and there's no check on reference
existence in structures.references.collected).


\directlua{
  function userdata.printrange(singular, plural, label)
    local coll_ref = structures.references.collected[""]
    local pagestart = coll_ref[label .. ":start"].references.realpage
    local pagestop = coll_ref[label .. ":stop"].references.realpage
    if pagestart == pagestop then
      context(singular)
    else
      context(plural)
    end
    context("~")
    context.ref({"page"}, {label .. ":start"})
    if pagestart ~= pagestop then
      context("-")
      context.ref({"page"}, {label .. ":stop"})
    end
  end

  function userdata.printpagerange(label)
    userdata.printrange("page", "pages", label)
  end
}

\def\printpagerange#1{\ctxlua{userdata.printpagerange("#1")}}

\starttext

Tufte quote at \printpagerange{tufte}.

% start of quote reference
\pagereference[tufte:start]
\input{tufte}

%\page  % comment/uncomment this to toggle from page range to single
page

\input{tufte}
% end of quote reference
\pagereference[tufte:stop]

\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to