On Mon, Aug 15, 2005 at 03:12:03PM +0200, Lars Gullik Bjønnes wrote:
> Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> | On Mon, Aug 15, 2005 at 12:46:55PM +0200, Lars Gullik Bjønnes wrote:
> >> Martin Vermeer <[EMAIL PROTECTED]> writes:
> >
> | ...
> >
> >> >> If at all possible I'd like to avoid all layout changes now.
> >> >> what are the implications?
> >> >
> >> | 1) LtR should remain unaffected. Business as usual.
> >> | 2) It will be possible to define label strings that depend on the
> >> | language of the document. Currently used to revert the
> >> | section/sub/sub-sub order for Hebrew; but could be generalized.
> >> >
> >> | It looks like this:
> >> >
> >> |  LabelString         "[EMAIL PROTECTED]@[EMAIL 
> >> PROTECTED]@.\arabic{subsection}}"
> >> >
> >> | [Note that "hebrew" refers to language, "arabic" to number type. Quite
> >> | different thing]
> >> >
> >> | So at this point we should decide if we want such an extension to the
> >> | format, and if it should look like this. I dislike hardwiring Hebrew
> >> | into the LyX code, as we have in some places today. Fixing the section
> >> | header bug without this format change would require such hardwiring.
> >> 
> >> Note that inside LyX "hebrew" is sometimes used instead of "rtl".
> >> 
> >> How is all this solved in 1.3.x?
> >
> | It isn't. These numeric labels just come out in Latin order (which thus
> | violates WYSIWYG, but may be OK with WYSIWYM). But... earlier it worked,
> | I believe. Look at the patch
> >
> | 
> http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel/src/counters.C.diff?r1=1.7&r2=1.8
> >
> | where I import a large piece of code from somewhere else that does a
> | number of Hebrew things. E.g. enumerate labels, and the letters for
> | appendices become Hebrew. This is probably where I broke it.
> >
> | This stuff was originally in text2.C and looked like this:
> >
> | 
> http://www.lyx.org/cgi-bin/viewcvs.cgi/lyx-devel/src/text2.C.diff?r1=1.241&r2=1.242
> >
> | where there is at least an attempt to output Hebrew letters for
> | appendix labels. And there 'langtype', is defined, on which enumerate
> | labels depended; later we somehow lost this and they stopped working.
> >
> | So, concludingly, I am pretty sure some of this (at least the enum
> | stuff, and appendix number labels, which my patch doesn't even address
> | yet) worked right around version 1.2. I could prepare a patch only fixing
> | those two things if you like... but the .[Ch] stuff of it would look
> | just the same as in this one.
> 
> My main reaons for being so unwilling is the changes to the .layout
> format. It really looks like a cludge to me. (even the existing one)

Well I don't like it any more than you. But what would you do instead?
Hardwire it? It used to be hardwired.

At least I can fix the enum bug without touching the layout format.

- Martin

BTW attached the patch as I have it here, now including the appendix
labels. The changes to to the layout files are not that big. Actually
the order of the numbers in a sectioning header is LtR also in Hebrew,
as my research found out :-)

Index: src/buffer_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.C,v
retrieving revision 1.31
diff -u -p -r1.31 buffer_funcs.C
--- src/buffer_funcs.C  9 Jun 2005 09:58:05 -0000       1.31
+++ src/buffer_funcs.C  15 Aug 2005 13:23:02 -0000
@@ -23,6 +23,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "gettext.h"
+#include "language.h"
 #include "LaTeX.h"
 #include "lyxtextclass.h"
 #include "paragraph.h"
@@ -440,7 +441,8 @@ void setCounter(Buffer const & buf, ParI
 
                counters.step(enumcounter);
 
-               par.params().labelString(counters.enumLabel(enumcounter));
+               par.params().labelString(counters.enumLabel(enumcounter,
+                       par.getParLanguage(bufparams)->lang()));
        } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
                counters.step("bibitem");
                int number = counters.value("bibitem");
@@ -512,17 +514,21 @@ string expandLabel(Buffer const & buf,
 
        // handle 'inherited level parts' in 'fmt',
        // i.e. the stuff between '@' in   '@[EMAIL PROTECTED]'
-       size_t const i = fmt.find('@', 0);
-       if (i != string::npos) {
-               size_t const j = fmt.find('@', i + 1);
-               if (j != string::npos) {
-                       string parent(fmt, i + 1, j - i - 1);
-                       string label = expandLabel(buf, tclass[parent], 
appendix);
-                       fmt = string(fmt, 0, i) + label + string(fmt, j + 1, 
string::npos);
+       
+       while (fmt.find('@', 0) != string::npos) {
+               size_t const i = fmt.find('@', 0);
+               if (i != string::npos) {
+                       size_t const j = fmt.find('@', i + 1);
+                       if (j != string::npos) {
+                               string parent(fmt, i + 1, j - i - 1);
+                               string label = expandLabel(buf, tclass[parent], 
appendix);
+                               fmt = string(fmt, 0, i) + label + string(fmt, j 
+ 1, string::npos);
+                       }
                }
        }
 
-       return tclass.counters().counterLabel(fmt);
+       // Label format may depend on buffer language (hebrew!)
+       return tclass.counters().counterLabel(fmt, 
buf.params().language->lang());
 }
 
 
Index: src/counters.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.C,v
retrieving revision 1.34
diff -u -p -r1.34 counters.C
--- src/counters.C      6 Jan 2005 16:39:22 -0000       1.34
+++ src/counters.C      15 Aug 2005 13:23:03 -0000
@@ -286,7 +286,7 @@ string Counters::labelItem(string const 
 }
 
 
-string Counters::counterLabel(string const & format)
+string Counters::counterLabel(string const & format, string const & language)
 {
        string label = format;
        while (true) {
@@ -294,7 +294,9 @@ string Counters::counterLabel(string con
 #warning Using boost::regex or boost::spirit would make this code a lot 
simpler... (Lgb)
 #endif
 
-               size_t const i = label.find('\\', 0);
+               size_t i = label.find('\\', 0);
+               while (i != string::npos && label.substr(i, 3) == "\\if")
+                       i = label.find('\\', i + 1);
                if (i == string::npos)
                        break;
                size_t const j = label.find('{', i + 1);
@@ -311,15 +313,37 @@ string Counters::counterLabel(string con
                //      << numbertype << ") -> " << label << endl;
        }
        //lyxerr << "counterLabel: " << format  << " -> "       << label << 
endl;
+       while (true) {
+               // To allow recursion. There may not be any other
+               // backslashes left in the string than "\if".
+               size_t const i = label.find_last_of('\\', 0);
+               if (i == string::npos)
+                       break;
+               size_t const j = label.find('{', i + 3);
+               if (j == string::npos)
+                       break;
+               size_t const m = label.find("}{", j + 1);
+               if (m == string::npos)
+                       break;
+               size_t const k = label.find('}', m + 1);
+               if (k == string::npos)
+                       break;
+               string const lang(label, i + 3, j - i - 3);
+               string const ifyes(label, j + 1, m - j - 1);
+               string const ifno(label, m + 2, k - m - 2);
+               string const rep(language == lang ? ifyes : ifno);
+               label = string(label, 0, i) + rep + string(label, k + 1, 
string::npos);
+       }
+
        return label;
 }
 
 
-string Counters::enumLabel(string const & ctr, string const & langtype)
+string Counters::enumLabel(string const & ctr, string const & language)
 {
        ostringstream os;
 
-       if (langtype == "hebrew") {
+       if (language == "hebrew") {
                if (ctr == "enumi")
                        os << '.' << value("enumi");
                else if (ctr == "enumii")
Index: src/counters.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/counters.h,v
retrieving revision 1.17
diff -u -p -r1.17 counters.h
--- src/counters.h      6 Oct 2003 15:42:13 -0000       1.17
+++ src/counters.h      15 Aug 2005 13:23:03 -0000
@@ -76,9 +76,11 @@ public:
        void copy(Counters & from, Counters & to, std::string const & match = 
std::string());
        /// A complete expanded label, like 2.1.4 for a subsubsection
        /// according to the given format
-       std::string counterLabel(std::string const & format);
+       std::string counterLabel(std::string const & format, 
+               std::string const & language);
        /// A complete label, like 1.a for enumerations
-       std::string enumLabel(std::string const & ctr, std::string const & 
langtype = "latin");
+       std::string enumLabel(std::string const & ctr, 
+               std::string const & language);
 private:
        /// A counter label's single item, 1 for subsection number in
        /// the 2.1.4 subsubsection number label.
Index: lib/layouts/numarticle.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/numarticle.inc,v
retrieving revision 1.4
diff -u -p -r1.4 numarticle.inc
--- lib/layouts/numarticle.inc  19 Apr 2005 09:00:32 -0000      1.4
+++ lib/layouts/numarticle.inc  15 Aug 2005 13:23:03 -0000
@@ -13,7 +13,7 @@ Style Section
        LabelType             Counter
        LabelCounter          section
        LabelString           "\arabic{section}"
-       LabelStringAppendix   "\Alph{section}"
+       LabelStringAppendix   "\ifhebrew{\hebrew{section}}{\Alph{section}}"
        TocLevel              1
 End
 
Index: lib/layouts/numreport.inc
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/layouts/numreport.inc,v
retrieving revision 1.4
diff -u -p -r1.4 numreport.inc
--- lib/layouts/numreport.inc   19 Apr 2005 09:00:32 -0000      1.4
+++ lib/layouts/numreport.inc   15 Aug 2005 13:23:03 -0000
@@ -12,13 +12,13 @@ Style Chapter
        LabelType             Counter
        LabelCounter          chapter
        LabelString           "Chapter \arabic{chapter}"
-       LabelStringAppendix   "Appendix \Alph{chapter}"
+       LabelStringAppendix   "Appendix 
\ifhebrew{\hebrew{chapter}}{\Alph{chapter}}"
        TocLevel              0
 End
 
 
 Style Section
        LabelString           "\arabic{chapter}.\arabic{section}"
-       LabelStringAppendix   "\Alph{chapter}.\arabic{section}"
+       LabelStringAppendix   "@[EMAIL PROTECTED]"
 End
 

Attachment: pgpyWJrJu90fh.pgp
Description: PGP signature

Reply via email to