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"
32 /// This represents a single counter.
38 Counter(docstring const & mc, docstring const & ls,
39 docstring const & lsa);
40 /// \return true on success
41 bool read(Lexer & lex);
52 /// Returns the master counter of this counter.
53 docstring const & master() const;
54 /// Returns a LaTeX-like string to format the counter.
55 /** This is similar to what one gets in LaTeX when using
56 * "\the<counter>". The \c in_appendix bool tells whether we
57 * want the version shown in an appendix.
59 docstring const & labelString(bool in_appendix) const;
60 /// Similar, but used for formatted references in XHTML output.
61 /// E.g., for a section counter it might be "section \thesection"
62 docstring const & prettyFormat() const { return prettyformat_; }
64 /// Returns a map of LaTeX-like strings to format the counter.
65 /** For each language, the string is similar to what one gets
66 * in LaTeX when using "\the<counter>". The \c in_appendix
67 * bool tells whether we want the version shown in an
68 * appendix. This version does not contain any \\the<counter>
71 typedef std::map<std::string, docstring> StringMap;
72 StringMap & flatLabelStrings(bool in_appendix) const;
76 /// contains master counter name.
77 /** The master counter is the counter that, if stepped
78 * (incremented) zeroes this counter. E.g. "subsection"'s
79 * master is "section".
82 /// Contains a LaTeX-like string to format the counter.
83 docstring labelstring_;
84 /// The same as labelstring_, but in appendices.
85 docstring labelstringappendix_;
86 /// Similar, but used for formatted references in XHTML output
87 docstring prettyformat_;
88 /// Cache of the labelstring with \\the<counter> expressions expanded,
89 /// indexed by language
90 mutable StringMap flatlabelstring_;
91 /// Cache of the appendix labelstring with \\the<counter> expressions expanded,
92 /// indexed by language
93 mutable StringMap flatlabelstringappendix_;
97 /// This is a class of (La)TeX type counters.
98 /// Every instantiation is an array of counters of type Counter.
103 /// Add new counter newc having masterc as its master,
104 /// ls as its label, and lsa as its appendix label.
105 void newCounter(docstring const & newc,
106 docstring const & masterc,
107 docstring const & ls,
108 docstring const & lsa);
109 /// Checks whether the given counter exists.
110 bool hasCounter(docstring const & c) const;
111 /// reads the counter name
112 /// \param makeNew whether to make a new counter if one
113 /// doesn't already exist
114 /// \return true on success
115 bool read(Lexer & lex, docstring const & name, bool makenew);
117 void set(docstring const & ctr, int val);
119 void addto(docstring const & ctr, int val);
121 int value(docstring const & ctr) const;
122 /// Increment by one counter named by arg, and zeroes slave
123 /// counter(s) for which it is the master.
124 /// Sub-slaves are not zeroed! That happens at slave's first
125 /// step 0->1. Seems to be sufficient.
126 /// \param utype determines whether we track the counters.
127 void step(docstring const & ctr, UpdateType utype);
128 /// Reset all counters.
130 /// Reset counters matched by match string.
131 void reset(docstring const & match);
132 /// Copy counters whose name matches match from the &from to
133 /// the &to array of counters. Empty string matches all.
134 void copy(Counters & from, Counters & to,
135 docstring const & match = docstring());
136 /** returns the expanded string representation of counter \c
137 * c. The \c lang code is used to translate the string.
139 docstring theCounter(docstring const & c,
140 std::string const & lang) const;
141 /** Replace in \c format all the LaTeX-like macros that depend
142 * on counters. The \c lang code is used to translate the
145 docstring counterLabel(docstring const & format,
146 std::string const & lang) const;
147 /// returns a formatted version of the counter, using the
148 /// format given by Counter::prettyFormat().
149 docstring prettyCounter(docstring const & cntr,
150 std::string const & lang) const;
151 /// Are we in appendix?
152 bool appendix() const { return appendix_; }
153 /// Set the state variable indicating whether we are in appendix.
154 void appendix(bool a) { appendix_ = a; }
155 /// Returns the current enclosing float.
156 std::string const & current_float() const { return current_float_; }
157 /// Sets the current enclosing float.
158 void current_float(std::string const & f) { current_float_ = f; }
159 /// Are we in a subfloat?
160 bool isSubfloat() const { return subfloat_; }
161 /// Set the state variable indicating whether we are in a subfloat.
162 void isSubfloat(bool s) { subfloat_ = s; }
164 /// \name refstepcounter
166 /// The currently active counter, so far as references go.
167 /// We're trying to track \refstepcounter in LaTeX, more or less.
168 /// Note that this may be empty.
169 docstring currentCounter() const;
170 /// Called during updateBuffer() as we go through various paragraphs,
171 /// to track the layouts as we go through.
172 void setActiveLayout(Layout const & lay);
173 /// Also for updateBuffer().
174 /// Call this when entering things like footnotes, where there is now
175 /// no "last layout" and we want to restore the "last layout" on exit.
176 void clearLastLayout() { layout_stack_.push_back(0); }
177 /// Call this when existing things like footnotes.
178 void restoreLastLayout() { layout_stack_.pop_back(); }
180 void saveLastCounter()
181 { counter_stack_.push_back(counter_stack_.back()); }
183 void restoreLastCounter() { counter_stack_.pop_back(); }
186 /** expands recursively any \\the<counter> macro in the
187 * labelstring of \c counter. The \c lang code is used to
188 * translate the string.
190 docstring flattenLabelString(docstring const & counter, bool in_appendix,
191 std::string const &lang,
192 std::vector<docstring> & callers) const;
193 /// Returns the value of the counter according to the
194 /// numbering scheme numbertype.
195 /** Available numbering schemes are arabic (1, 2,...), roman
196 * (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
199 docstring labelItem(docstring const & ctr,
200 docstring const & numbertype) const;
201 /// Used for managing the counter_stack_.
203 void beginEnvironment();
204 void endEnvironment();
206 /// Maps counter (layout) names to actual counters.
207 typedef std::map<docstring, Counter> CounterList;
209 CounterList counterList_;
210 /// Are we in an appendix?
212 /// The current enclosing float.
213 std::string current_float_;
214 /// Are we in a subfloat?
216 /// Used to keep track of active counters.
217 std::deque<docstring> counter_stack_;
218 /// Same, but for last layout.
219 std::deque<Layout const *> layout_stack_;