+docstring Counters::theCounter(docstring const & counter)
+{
+ std::set<docstring> callers;
+ return theCounter(counter, callers);
+}
+
+docstring Counters::theCounter(docstring const & counter,
+ std::set<docstring> & callers)
+{
+ if (!hasCounter(counter))
+ return from_ascii("??");
+
+ docstring label;
+
+ if (callers.find(counter) == callers.end()) {
+
+ pair<std::set<docstring>::iterator, bool> result = callers.insert(counter);
+
+ Counter const & c = counterList[counter];
+ docstring ls = appendix() ? c.labelStringAppendix() : c.labelString();
+
+ if (ls.empty()) {
+ if (!c.master().empty())
+ ls = from_ascii("\\the") + c.master() + from_ascii(".");
+ ls += from_ascii("\\arabic{") + counter + "}";
+ }
+
+ label = counterLabel(ls, &callers);
+
+ callers.erase(result.first);
+ } else {
+ // recursion detected
+ lyxerr << "Warning: Recursion in label for counter `"
+ << counter << "' detected"
+ << endl;
+ }
+
+ return label;
+}
+
+
+docstring Counters::counterLabel(docstring const & format,
+ std::set<docstring> * callers)