4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author Martin Vermeer
12 * Full author contact details are available in file CREDITS.
18 #include "OutputEnums.h"
20 #include "support/docstring.h"
31 /// This represents a single counter.
37 Counter(docstring const & mc, docstring const & ls,
38 docstring const & lsa);
39 /// \return true on success
40 bool read(Lexer & lex);
51 /// Returns the master counter of this counter.
52 docstring const & master() const;
53 /// Returns a LaTeX-like string to format the counter.
54 /** This is similar to what one gets in LaTeX when using
55 * "\the<counter>". The \c in_appendix bool tells whether we
56 * want the version shown in an appendix.
58 docstring const & labelString(bool in_appendix) const;
59 /// Similar, but used for formatted references in XHTML output.
60 /// E.g., for a section counter it might be "section \thesection"
61 docstring const & prettyFormat() const { return prettyformat_; }
63 /// Returns a map of LaTeX-like strings to format the counter.
64 /** For each language, the string is similar to what one gets
65 * in LaTeX when using "\the<counter>". The \c in_appendix
66 * bool tells whether we want the version shown in an
67 * appendix. This version does not contain any \\the<counter>
70 typedef std::map<std::string, docstring> StringMap;
71 StringMap & flatLabelStrings(bool in_appendix) const;
75 /// contains master counter name.
76 /** The master counter is the counter that, if stepped
77 * (incremented) zeroes this counter. E.g. "subsection"'s
78 * master is "section".
81 /// Contains a LaTeX-like string to format the counter.
82 docstring labelstring_;
83 /// The same as labelstring_, but in appendices.
84 docstring labelstringappendix_;
85 /// Similar, but used for formatted references in XHTML output
86 docstring prettyformat_;
87 /// Cache of the labelstring with \\the<counter> expressions expanded,
88 /// indexed by language
89 mutable StringMap flatlabelstring_;
90 /// Cache of the appendix labelstring with \\the<counter> expressions expanded,
91 /// indexed by language
92 mutable StringMap flatlabelstringappendix_;
96 /// This is a class of (La)TeX type counters.
97 /// Every instantiation is an array of counters of type Counter.
100 /// NOTE Do not call this in an attempt to clear the counters.
101 /// That will wipe out all the information we have about them
102 /// from the document class (e.g., which ones are defined).
103 /// Instead, call Counters::reset().
105 /// Add new counter newc having masterc as its master,
106 /// ls as its label, and lsa as its appendix label.
107 void newCounter(docstring const & newc,
108 docstring const & masterc,
109 docstring const & ls,
110 docstring const & lsa);
111 /// Checks whether the given counter exists.
112 bool hasCounter(docstring const & c) const;
113 /// reads the counter name
114 /// \param makeNew whether to make a new counter if one
115 /// doesn't already exist
116 /// \return true on success
117 bool read(Lexer & lex, docstring const & name, bool makenew);
119 void set(docstring const & ctr, int val);
121 void addto(docstring const & ctr, int val);
123 int value(docstring const & ctr) const;
124 /// Increment by one counter named by arg, and zeroes slave
125 /// counter(s) for which it is the master.
126 /// Sub-slaves are not zeroed! That happens at slave's first
127 /// step 0->1. Seems to be sufficient.
128 /// \param utype determines whether we track the counters.
129 void step(docstring const & ctr, UpdateType utype);
130 /// Reset all counters, and all the internal data structures
131 /// used for keeping track of their values.
133 /// Reset counters matched by match string.
134 void reset(docstring const & match);
135 /// Copy counters whose name matches match from the &from to
136 /// the &to array of counters. Empty string matches all.
137 void copy(Counters & from, Counters & to,
138 docstring const & match = docstring());
139 /** returns the expanded string representation of counter \c
140 * c. The \c lang code is used to translate the string.
142 docstring theCounter(docstring const & c,
143 std::string const & lang) const;
144 /** Replace in \c format all the LaTeX-like macros that depend
145 * on counters. The \c lang code is used to translate the
148 docstring counterLabel(docstring const & format,
149 std::string const & lang) const;
150 /// returns a formatted version of the counter, using the
151 /// format given by Counter::prettyFormat().
152 docstring prettyCounter(docstring const & cntr,
153 std::string const & lang) const;
154 /// Are we in appendix?
155 bool appendix() const { return appendix_; }
156 /// Set the state variable indicating whether we are in appendix.
157 void appendix(bool a) { appendix_ = a; }
158 /// Returns the current enclosing float.
159 std::string const & current_float() const { return current_float_; }
160 /// Sets the current enclosing float.
161 void current_float(std::string const & f) { current_float_ = f; }
162 /// Are we in a subfloat?
163 bool isSubfloat() const { return subfloat_; }
164 /// Set the state variable indicating whether we are in a subfloat.
165 void isSubfloat(bool s) { subfloat_ = s; }
167 /// \name refstepcounter
169 /// The currently active counter, so far as references go.
170 /// We're trying to track \refstepcounter in LaTeX, more or less.
171 /// Note that this may be empty.
172 docstring currentCounter() const;
173 /// Called during updateBuffer() as we go through various paragraphs,
174 /// to track the layouts as we go through.
175 void setActiveLayout(Layout const & lay);
176 /// Also for updateBuffer().
177 /// Call this when entering things like footnotes, where there is now
178 /// no "last layout" and we want to restore the "last layout" on exit.
179 void clearLastLayout() { layout_stack_.push_back(0); }
180 /// Call this when exiting things like footnotes.
181 void restoreLastLayout() { layout_stack_.pop_back(); }
183 void saveLastCounter()
184 { counter_stack_.push_back(counter_stack_.back()); }
186 void restoreLastCounter() { counter_stack_.pop_back(); }
189 /** expands recursively any \\the<counter> macro in the
190 * labelstring of \c counter. The \c lang code is used to
191 * translate the string.
193 docstring flattenLabelString(docstring const & counter, bool in_appendix,
194 std::string const &lang,
195 std::vector<docstring> & callers) const;
196 /// Returns the value of the counter according to the
197 /// numbering scheme numbertype.
198 /** Available numbering schemes are arabic (1, 2,...), roman
199 * (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
202 docstring labelItem(docstring const & ctr,
203 docstring const & numbertype) const;
204 /// Used for managing the counter_stack_.
206 void beginEnvironment();
207 void endEnvironment();
209 /// Maps counter (layout) names to actual counters.
210 typedef std::map<docstring, Counter> CounterList;
212 CounterList counterList_;
213 /// Are we in an appendix?
215 /// The current enclosing float.
216 std::string current_float_;
217 /// Are we in a subfloat?
219 /// Used to keep track of active counters.
220 std::vector<docstring> counter_stack_;
221 /// Same, but for last layout.
222 std::vector<Layout const *> layout_stack_;