]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.cpp
Fix bug #12772
[lyx.git] / src / Counters.cpp
index 8477d5283ad90831ee366aa65835d3039d2d5350..0133f76bcab455f876c0f05631641313d09dfe32 100644 (file)
@@ -6,7 +6,7 @@
  * \author Lars Gullik Bjønnes
  * \author Martin Vermeer
  * \author André Pönitz
- * \author Richard Heck (roman numerals)
+ * \author Richard Kimberly Heck (roman numerals)
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -59,6 +59,7 @@ bool Counter::read(Lexer & lex)
                CT_PRETTYFORMAT,
                CT_INITIALVALUE,
                CT_GUINAME,
+               CT_LATEXNAME,
                CT_END
        };
 
@@ -68,6 +69,7 @@ bool Counter::read(Lexer & lex)
                { "initialvalue", CT_INITIALVALUE},
                { "labelstring", CT_LABELSTRING },
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
+               { "latexname", CT_LATEXNAME },
                { "prettyformat", CT_PRETTYFORMAT },
                { "within", CT_WITHIN }
        };
@@ -120,6 +122,10 @@ bool Counter::read(Lexer & lex)
                                lex.next();
                                guiname_ = lex.getDocString();
                                break;
+                       case CT_LATEXNAME:
+                               lex.next();
+                               latexname_ = lex.getDocString();
+                               break;
                        case CT_END:
                                getout = true;
                                break;
@@ -374,6 +380,22 @@ docstring const & Counters::guiName(docstring const & cntr) const
 }
 
 
+docstring const & Counters::latexName(docstring const & cntr) const
+{
+       CounterList::const_iterator it = counterList_.find(cntr);
+       if (it == counterList_.end()) {
+               lyxerr << "step: Counter does not exist: "
+                          << to_utf8(cntr) << endl;
+               return empty_docstring();
+       }
+
+       docstring const & latexname = it->second.latexName();
+       if (latexname.empty())
+               return cntr;
+       return latexname;
+}
+
+
 void Counters::reset()
 {
        appendix_ = false;
@@ -399,6 +421,16 @@ void Counters::reset(docstring const & match)
 }
 
 
+bool Counters::copy(docstring const & cnt, docstring const & newcnt)
+{
+       auto const it = counterList_.find(cnt);
+       if (it == counterList_.end())
+               return false;
+       counterList_[newcnt] = it->second;
+       return true;
+}
+
+
 bool Counters::remove(docstring const & cnt)
 {
        bool retval = counterList_.erase(cnt);
@@ -413,16 +445,6 @@ bool Counters::remove(docstring const & cnt)
 }
 
 
-void Counters::copy(Counters const & from, Counters & to, docstring const & match)
-{
-       for (auto const & ctr : counterList_) {
-               if (ctr.first.find(match) != string::npos || match == "") {
-                       to.set(ctr.first, from.value(ctr.first));
-               }
-       }
-}
-
-
 docstring Counters::labelItem(docstring const & ctr,
                              docstring const & numbertype) const
 {