Jean-Marc Lasgouttes wrote:
rgheck <rgh...@bobjweil.com> writes:
The point of this patch is that sometimes one wants enumerations that
behave differently, even within a single document. E.g, I've got an
Enumerati environment that gives me enumerations with \roman, \Roman,
\alph, \Alph, and I'd like to see them that way. Your solution changes
everything globally.
What I would do is work in a more latex-ish way: define a new set of
counters "myenumi"..."myenumiv" with the corresponding labelstring and
set Enumerati to use "myenum" as counter (which means that we will have
to read the layout counter for enumrations).
Starting from the patch below [snip].
OK, that seems to work. I've committed it to trunk and asked about branch.
One remaining bug is that theCounter does not translate its string, it
would need for that to get an extra BufferParams argument.
I've worked on this a bit, but it is a bit harder than it seemed it
might be. I don't think there's anything we can reliably translate where
you put the FIXME. We do this:
counterLabel(it->second.flatLabelString(appendix()))
but flatLabelString() is calculated, so we can't reliably translate
that. What we need to translate is the LabelString itself, I think, but
it's not at all clear when to do that. One idea would be to do it when
we calculate the flat label string, but we don't have information on the
paragraph language at that point, so that would be less than ideal. But
I don't really see what else we can do.
Toward doing something here, though, and starting from a FIXME of yours,
I've got the following patch, which seems to work. Does this seem OK? If
we had this, then we could do the translation, as suggested, just when
we calculate flat label strings, which will be only when the document
class is changed. Though maybe we'd also need to do it whenever the
BufferParams change, since then the Buffer language might have been changed.
rh
Index: src/Counters.cpp
===================================================================
--- src/Counters.cpp (revision 29907)
+++ src/Counters.cpp (working copy)
@@ -13,6 +13,7 @@
#include <config.h>
+#include "BufferParams.h"
#include "Counters.h"
#include "Lexer.h"
@@ -257,14 +258,19 @@
current_float_.erase();
CounterList::iterator it = counterList_.begin();
CounterList::iterator const end = counterList_.end();
+ for (; it != end; ++it)
+ it->second.reset();
+}
+
+
+void Counters::calculateLabelStrings()
+{
+ // Compute the explicit counter labels without any
+ // \thexxx strings, in order to avoid recursion.
std::vector<docstring> callers;
+ CounterList::iterator it = counterList_.begin();
+ CounterList::iterator const end = counterList_.end();
for (; it != end; ++it) {
- it->second.reset();
- // Compute the explicit counter labels without any
- // \thexxx strings, in order to avoid recursion.
- // It only needs to be done when the textclass is
- // updated, but in practice the extra work is probably
- // not noticeable (JMarc)
docstring const fls = flattenLabelString(it->first, false,
callers);
docstring const flsa = flattenLabelString(it->first, true,
callers);
it->second.setFlatLabelStrings(fls, flsa);
@@ -441,8 +447,7 @@
docstring Counters::flattenLabelString(docstring const & counter,
- bool in_appendix,
- vector<docstring> & callers) const
+ bool in_appendix, vector<docstring> & callers) const
{
docstring label;
Index: src/Counters.h
===================================================================
--- src/Counters.h (revision 29903)
+++ src/Counters.h (working copy)
@@ -23,6 +23,7 @@
namespace lyx {
+class BufferParams;
class Lexer;
/// This represents a single counter.
@@ -113,6 +114,8 @@
void step(docstring const & ctr);
/// Reset all counters.
void reset();
+ ///
+ void calculateLabelStrings();
/// Reset counters matched by match string.
void reset(docstring const & match);
/// Copy counters whose name matches match from the &from to
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp (revision 29903)
+++ src/BufferParams.cpp (working copy)
@@ -1665,6 +1665,8 @@
frontend::Alert::warning(_("Read Error"), msg);
}
}
+
+ doc_class_->counters().calculateLabelStrings(*this);
}
bool BufferParams::moduleCanBeAdded(string const & modName) const