2

I use ConTeXt ver: 2025.08.21 23:32 LMTX fmt: 2025.9.18 and have a tex file

\setupinteraction[state=start,focus=standard] \setuphead[section][textstyle=\bf,numbercommand=\groupedcommand{}{.}] \definereferenceformat[zcref][label=*,style=normal,color=blue] \setuplabeltext[en][section=Section~] \starttext \section[sec:math]{Math} We want to refer to \zcref[sec:math]. \stoptext 

enter image description here

Could you explain how to hide the word "Section" from the printed title? On the other hand, I would like to keep this word when using \zcref[sec:math]. I tried the option prefix=no in the command \setuphead[section], but to no avail.

6
  • I discussed this with Hans. There will be functionality added for it. (Nobody asked about it before, it seems.) Commented Sep 21 at 11:37
  • @mickep Even in LaTeX community, most people is fine with a kind of Section \zcref[sec:math]. Commented Sep 21 at 11:46
  • I do not understand what that means. Commented Sep 21 at 11:53
  • @mickep If I remove \setuplabeltext[en][section=Section~], then I have my desired section title. But in this case, I have to manually type Section \zcref[sec:math] to get "Section 1". Commented Sep 21 at 11:56
  • 1
    The ConTeXt way to add option prefixes and suffixes to a reference is to use the two optional arguments, e.g. \in{Section}[sec:example] or \in{Figure}{a}[fig:example]. You can also pass these optional argument tp custom reference commands but no space is added between the text and reference unless you configure your command (\setupreferenceformat[...][left=\nobreakspace]). Commented Sep 21 at 12:18

3 Answers 3

3

ConTeXt doesn't seem to provide a builtin way to do this, but we can implemented it ourselves using Lua:

%%%%%%%%%%%%%%%%%%%%%% %%% Implementation %%% %%%%%%%%%%%%%%%%%%%%%% \startluacode local labels = languages.data.labels.texts local variables = interfaces.complete.variables local label_namespace = tokens.getters.macro("??label") local function get_label_text(language, label) local macro_name = ("%slabel:%s:%s"):format(label_namespace, language, label) return tokens.getters.macro(macro_name) end interfaces.implement { name = "GetReferenceLabel", public = true, actions = { function() local types = table.flattened { { structures.references.getcurrentlabel() }, { structures.references.getcurrentmetadata("name") }, { structures.references.getcurrentmetadata("kind") }, } local language = languages.current() local text for _, type in ipairs(types) do text = get_label_text(language, type) if text and text ~= "" then return text end end for _, type in ipairs(types) do local by_reference = labels[type] if by_reference then text = by_reference.labels[language] if text then return text end end end for _, type in ipairs(types) do local by_reference = variables[type] if by_reference then text = by_reference[language] if text then return converters.Words(text) .. " " end end end return "??? " end, context } } \stopluacode \definereferenceformat[zcref][left=\GetReferenceLabel, style=normal, color=blue] %%%%%%%%%%%%%%%%%%%%% %%% Demonstration %%% %%%%%%%%%%%%%%%%%%%%% \setupbodyfont[dejavu, sans] \setuppapersize[A3, landscape] \defineenumeration[theorem][ text=Theorem, label=theorem, way=bysection, prefix=yes, prefixsegments=section, ] \defineenumeration[lemma][theorem][ text=Lemma, label=lemma, ] \setuplabeltext[en][theorem=Theorem~, lemma=Lemma~] \setuplabeltext[nl][theorem=Dutch Theorem~, lemma=Dutch Lemma~] \starttext \startTEXpage[width=4in, offset=1ex] \startbodymatter \part[sec:part]{Part} \chapter[sec:chapter]{Chapter} \section[sec:section]{Section} \subsection[sec:subsection]{Subsection} \subsubsection[sec:subsubsection]{Subsubsection} \subsubsubsection[sec:subsubsubsection]{Subsubsubsection} \startplacefigure[reference=fig:figure, title={Figure Title}] \externalfigure[sys:///cow.pdf][height=1in] \stopplacefigure \startplacetable[reference=tab:table, title={Table Title}] \startTABLE \NC Header 1 \NC Header 2 \NC \NR \NC Cell 1 \NC Cell 2 \NC \NR \stopTABLE \stopplacetable \startplaceintermezzo[reference=imz:intermezzo, title={Intermezzo Title}] This is an intermezzo. \stopplaceintermezzo \startformula x_{1, 2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \numberhere[eq:quadratic] \stopformula \pagereference[page:page] \textreference[text:text]{Some text} \starttheorem[reference=thm:theorem, title={Theorem Title}] This is a theorem. \stoptheorem \startlemma[reference=lem:testlemma, title={Lemma Title}] This is a lemma. \stoplemma \stopbodymatter \startappendices \chapter[page=no, reference=sec:appendix, title={Appendix}] \stopappendices \stopTEXpage \startTEXpage[offset=1ex] \startTABLE[frame=off, roffset=1em] \setupTABLE[column][1][style=tt, align=flushright] \setupTABLE[row][1][style=bold] \NC[style=bold] Reference \NC English \NC Dutch \NC Czech \NC Greek \NC Ukrainian \NC Armenian \NC Arabic \NC \NR \dowith{ sec:part, sec:chapter, sec:section, sec:subsection, sec:subsubsection, sec:subsubsubsection, fig:figure, tab:table, imz:intermezzo, eq:quadratic, page:page, text:text, thm:theorem, lem:testlemma, sec:appendix, }{ \NC #1 \NC \language[english] \zcref[#1] \NC \language[dutch] \zcref[#1] \NC \language[czech] \zcref[#1] \NC \language[greek] \zcref[#1] \NC \language[ukrainian] \zcref[#1] \NC \language[armenian] \zcref[#1] \NC \language[arabic] \zcref[#1] \NC \NR } \stopTABLE \stopTEXpage \stoptext 

output

2
  • There is a problem when I additionally use \starttheorem ... \stoptheorem. Could you have a look at my follow-up question here? Commented Sep 21 at 12:11
  • 1
    @Akira Ok, I posted an answer there (and also edited in a solution here) Commented Sep 21 at 12:42
5

An alternative to the label added by ConTeXt is the manual method with the two optional argument for the \in (and \at) reference command.

This method is also possible with custom reference command but one has to configure it to add an space between the text and reference content.

\setupinteraction [state=start] \setuphead [section] [numbercommand=\groupedcommand{}{.}]% altertnative: sectionstopper=. \definereferenceformat [myreference] [style=typeface,% auto upright: style=\tf + style=\bf color=blue, left=\nobreakspace] \starttext \section[sec:example]{Combination} \startplacefigure[reference=fig:example,title=Figures] \startcombination[nx=2,ny=1] {\externalfigure[figure-a][combination]}{a} {\externalfigure[figure-b][combination]}{b} \stopcombination \stopplacefigure See \in{Figure}{a}[fig:example] in \in{Section}[sec:example]. See \myreference{Figure}{a}[fig:example] in \myreference{Section}[sec:example]. \stoptext 
4

Nobody requested this before, so this will be added (next upload). Maybe we need to discuss the syntax a bit more, but likely it will be something like:

\setupinteraction[state=start,focus=standard] \definereferenceformat[zcref][label=reference:*] \setuplabeltext [en] [reference:section=Section~, reference:formula=Formula~] \setuphead [section] [textstyle=\bf, bodypartlabel=, ] \starttext \startsection [title=Math, reference=sec:math] We want to refer to \zcref[sec:math]. \startformula 1 + 1 = 2 \numberhere[eq:one] \stopformula See \zcref[eq:one]. \stopsection \stoptext 

This gives (on my machine only, currently):

references with names but labels without

The user shall not need to hack to do something like this. If you miss support for features, it might be better to ask on the ConTeXt mailing list, since Hans is there, and you will not need the extra layer (me, in this case).

3
  • You mean that I can send feature requests to [email protected] (or [email protected])? I wonder why don't we use Github for better communication and information sharing. Commented Sep 21 at 14:33
  • 2
    Yes, to the ordinary list. I think Hans prefers email over github. Commented Sep 21 at 14:38
  • Any reason why you need to use \setuplabeltext[reference:…] to manually define all the labels instead of just using the values from lang-txt.lua by default? Commented Sep 21 at 23:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.