# Incremented to format 21, 12 January 2010 by rgh
# Added HTMLTocLayout and HTMLTitle tags.
+
+# Incremented to format 22, 20 January 2010 by rgh
+# Added HTMLFormat tag to Counters.
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
# development/tools/updatelayouts.sh script to update all
# layout files to the new format.
-currentFormat = 21
+currentFormat = 22
def usage(prog_name):
continue
# This just involved new features, not any changes to old ones
- if format >= 14 and format <= 20:
+ if format >= 14 and format <= 21:
i += 1
continue
def layouts_l10n(input_files, output, base):
'''Generate pot file from lib/layouts/*.{layout,inc,module}'''
out = open(output, 'w')
- Style = re.compile(r'^Style\s+(.*)')
+ Style = re.compile(r'^Style\s+(.*)', re.IGNORECASE)
# include ???LabelString???, but exclude comment lines
LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*)')
GuiName = re.compile(r'\s*GuiName\s+(.*)')
I18nPreamble = re.compile(r'\s*(Lang)|(Babel)Preamble\s*$')
EndI18nPreamble = re.compile(r'\s*End(Lang)|(Babel)Preamble\s*$')
I18nString = re.compile(r'_\(([^\)]+)\)')
+ CounterFormat = re.compile(r'\s*PrettyFormat\s+(.*)')
for src in input_files:
readingDescription = False
string = res.group(1)
writeString(out, src, base, lineno, string)
continue
+ res = CounterFormat.search(line)
+ if res != None:
+ string = res.group(1)
+ writeString(out, src, base, lineno, string)
+ continue
out.close()
CT_WITHIN = 1,
CT_LABELSTRING,
CT_LABELSTRING_APPENDIX,
+ CT_PRETTYFORMAT,
CT_END
};
{ "end", CT_END },
{ "labelstring", CT_LABELSTRING },
{ "labelstringappendix", CT_LABELSTRING_APPENDIX },
+ { "prettyformat", CT_PRETTYFORMAT },
{ "within", CT_WITHIN }
};
if (master_ == "none")
master_.erase();
break;
+ case CT_PRETTYFORMAT:
+ lex.next();
+ prettyformat_ = lex.getDocString();
+ break;
case CT_LABELSTRING:
lex.next();
labelstring_ = lex.getDocString();
}
+docstring Counters::prettyCounter(docstring const & counter,
+ string const & lang) const
+{
+ CounterList::const_iterator it = counterList_.find(counter);
+ if (it == counterList_.end())
+ return from_ascii("??");
+ Counter const & ctr = it->second;
+ docstring const & format = ctr.prettyFormat();
+ if (format.empty()) {
+ docstring cntrname = translateIfPossible(counter, lang);
+ return cntrname + " " + theCounter(counter, lang);
+ }
+ return counterLabel(format, lang);
+}
+
+
docstring Counters::currentCounter() const
{
LASSERT(!counter_stack_.empty(), /* */);
* want the version shown in an appendix.
*/
docstring const & labelString(bool in_appendix) const;
+ /// Similar, but used for formatted references in XHTML output.
+ /// E.g., for a section counter it might be "section \thesection"
+ docstring const & prettyFormat() const { return prettyformat_; }
+
/// Returns a map of LaTeX-like strings to format the counter.
/** For each language, the string is similar to what one gets
* in LaTeX when using "\the<counter>". The \c in_appendix
docstring labelstring_;
/// The same as labelstring_, but in appendices.
docstring labelstringappendix_;
+ /// Similar, but used for formatted references in XHTML output
+ docstring prettyformat_;
/// Cache of the labelstring with \\the<counter> expressions expanded,
/// indexed by language
mutable StringMap flatlabelstring_;
*/
docstring counterLabel(docstring const & format,
std::string const & lang) const;
+ /// returns a formatted version of the counter, using the
+ /// format given by Counter::prettyFormat().
+ docstring prettyCounter(docstring const & cntr,
+ std::string const & lang) const;
/// Are we in appendix?
bool appendix() const { return appendix_; }
/// Set the state variable indicating whether we are in appendix.
};
// Keep the changes documented in the Customization manual.
-int const FORMAT = 21;
+int const FORMAT = 22;
bool layout2layout(FileName const & filename, FileName const & tempfile)
buffer().masterBuffer()->params().documentClass().counters();
active_counter_ = cnts.currentCounter();
Language const * lang = par->getParLanguage(buffer().params());
- if (lang && !active_counter_.empty())
+ if (lang && !active_counter_.empty()) {
counter_value_ = cnts.theCounter(active_counter_, lang->code());
- else
- counter_value_ = _("(unknown)");
+ pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code());
+ } else {
+ counter_value_ = from_ascii("??");
+ pretty_counter_ = from_ascii("??");
+ }
}
}
docstring const & activeCounter() const { return active_counter_; }
///
docstring const & counterValue() const { return counter_value_; }
+ ///
+ docstring const & prettyCounter() const { return pretty_counter_; }
protected:
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
docstring active_counter_;
///
docstring counter_value_;
+ ///
+ docstring pretty_counter_;
};
if (il && !il->counterValue().empty()) {
// Try to construct a label from the InsetLabel we reference.
- docstring const & cntr = il->activeCounter();
docstring const & value = il->counterValue();
if (cmd == "ref")
display_string = value;
else if (cmd == "vref")
- display_string = bformat(from_ascii("%1$s on page ##"), value);
+ // normally, would be "ref on page #", but we have no pages
+ display_string = value;
else if (cmd == "pageref" || cmd == "vpageref")
- display_string = _("on page ##");
+ // normally would be "on page #", but we have no pages
+ display_string = _("elsewhere");
else if (cmd == "eqref")
display_string = bformat(from_ascii("equation (%1$s)"), value);
else { // "prettyref"
- docstring cntrname = translateIfPossible(cntr);
- // FIXME Use the label string, if we have it. Otherwise, do this.
- display_string = bformat(from_ascii("%1$s %2$s"), cntrname, value);
+ display_string = il->prettyCounter();
}
} else
display_string = ref;