]> git.lyx.org Git - lyx.git/blob - src/Layout.h
Update tex2lyx test files
[lyx.git] / src / Layout.h
1 // -*- C++ -*-
2 /**
3  * \file Layout.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author André Pönitz
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LAYOUT_H
15 #define LAYOUT_H
16
17 #include "FontInfo.h"
18 #include "LayoutEnums.h"
19 #include "Spacing.h"
20 #include "support/docstring.h"
21
22 #include <set>
23 #include <string>
24
25 namespace lyx {
26
27 class Lexer;
28 class TextClass;
29
30 /* Fixed labels are printed flushright, manual labels flushleft.
31  * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
32  * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
33  * This seems a funny restriction, but I think other combinations are
34  * not needed, so I will not change it yet.
35  * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC.
36  */
37
38
39 /* There is a parindent and a parskip. Which one is used depends on the
40  * paragraph_separation-flag of the text-object.
41  * BUT: parindent is only thrown away, if a parskip is defined! So if you
42  * want a space between the paragraphs and a parindent at the same time,
43  * you should set parskip to zero and use topsep, parsep and bottomsep.
44  *
45  * The standard layout is an exception: its parindent is only set, if the
46  * previous paragraph is standard too. Well, this is LateX and it is good!
47  */
48
49 ///
50 class Layout {
51 public:
52         ///
53         Layout();
54         /// is this layout a default layout created for an unknown layout
55         bool isUnknown() const { return unknown_; }
56         void setUnknown(bool unknown) { unknown_ = unknown; }
57         /// Reads a layout definition from file
58         /// \return true on success.
59         bool read(Lexer &, TextClass const &);
60         ///
61         void readAlign(Lexer &);
62         ///
63         void readAlignPossible(Lexer &);
64         ///
65         void readLabelType(Lexer &);
66         ///
67         void readEndLabelType(Lexer &);
68         ///
69         void readMargin(Lexer &);
70         ///
71         void readLatexType(Lexer &);
72         ///
73         void readSpacing(Lexer &);
74         ///
75         docstring const & name() const { return name_; }
76         ///
77         void setName(docstring const & n) { name_ = n; }
78         ///
79         docstring const & obsoleted_by() const { return obsoleted_by_; }
80         ///
81         docstring const & depends_on() const { return depends_on_; }
82         ///
83         std::string const & latexname() const { return latexname_; }
84         ///
85         void setLatexName(std::string const & n) { latexname_ = n; }
86         ///
87         docstring const & labelstring(bool in_appendix) const 
88         { return in_appendix ? labelstring_appendix_ : labelstring_; }
89         ///
90         docstring const & endlabelstring() const { return endlabelstring_; }
91         ///
92         docstring const & category() const { return category_; }
93         ///
94         docstring const & preamble() const { return preamble_; }
95         /// Get language dependent macro definitions needed for this layout
96         /// for language \p lang
97         docstring const langpreamble() const { return langpreamble_; }
98         /// Get language and babel dependent macro definitions needed for
99         /// this layout for language \p lang
100         docstring const babelpreamble() const { return babelpreamble_; }
101         ///
102         std::set<std::string> const & requires() const { return requires_; }
103         ///
104         std::string const & latexparam() const { return latexparam_; }
105         ///
106         std::string const & innertag() const { return innertag_; }
107         ///
108         std::string const & labeltag() const { return labeltag_; }
109         ///
110         std::string const & itemtag() const { return itemtag_; }
111         /// 
112         std::string const & htmltag() const;
113         /// 
114         std::string const & htmlattr() const;
115         /// 
116         std::string const & htmlitemtag() const;
117         /// 
118         std::string const & htmlitemattr() const;
119         /// 
120         std::string const & htmllabeltag() const;
121         /// 
122         std::string const & htmllabelattr() const;
123         ///
124         std::string defaultCSSClass() const;
125         ///
126         bool htmllabelfirst() const { return htmllabelfirst_; }
127         /// 
128         docstring htmlstyle() const;
129         /// 
130         docstring const & htmlpreamble() const { return htmlpreamble_; }
131         ///
132         bool htmltitle() const { return htmltitle_; }
133         ///
134         bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
135         ///
136         bool isCommand() const { return latextype == LATEX_COMMAND; }
137         ///
138         bool isEnvironment() const {
139                 return latextype == LATEX_ENVIRONMENT
140                         || latextype == LATEX_BIB_ENVIRONMENT
141                         || latextype == LATEX_ITEM_ENVIRONMENT
142                         || latextype == LATEX_LIST_ENVIRONMENT;
143         }
144
145         ///
146         bool operator==(Layout const &) const;
147         ///
148         bool operator!=(Layout const & rhs) const 
149                 { return !(*this == rhs); }
150
151         ////////////////////////////////////////////////////////////////
152         // members
153         ////////////////////////////////////////////////////////////////
154         /** Default font for this layout/environment.
155             The main font for this kind of environment. If an attribute has
156             INHERITED_*, it means that the value is specified by
157             the defaultfont for the entire layout. If we are nested, the
158             font is inherited from the font in the environment one level
159             up until the font is resolved. The values :IGNORE_*
160             and FONT_TOGGLE are illegal here.
161         */
162         FontInfo font;
163
164         /** Default font for labels.
165             Interpretation the same as for font above
166         */
167         FontInfo labelfont;
168
169         /** Resolved version of the font for this layout/environment.
170             This is a resolved version the default font. The font is resolved
171             against the defaultfont of the entire layout.
172         */
173         FontInfo resfont;
174
175         /** Resolved version of the font used for labels.
176             This is a resolved version the label font. The font is resolved
177             against the defaultfont of the entire layout.
178         */
179         FontInfo reslabelfont;
180
181         /// Text that dictates how wide the left margin is on the screen
182         docstring leftmargin;
183         /// Text that dictates how wide the right margin is on the screen
184         docstring rightmargin;
185         /// Text that dictates how much space to leave after a potential label
186         docstring labelsep;
187         /// Text that dictates how much space to leave before a potential label
188         docstring labelindent;
189         /// Text that dictates the width of the indentation of indented pars
190         docstring parindent;
191         ///
192         double parskip;
193         ///
194         double itemsep;
195         ///
196         double topsep;
197         ///
198         double bottomsep;
199         ///
200         double labelbottomsep;
201         ///
202         double parsep;
203         ///
204         Spacing spacing;
205         ///
206         LyXAlignment align;
207         ///
208         LyXAlignment alignpossible;
209         ///
210         LabelType labeltype;
211         ///
212         EndLabelType endlabeltype;
213         ///
214         MarginType margintype;
215         ///
216         bool newline_allowed;
217         ///
218         bool nextnoindent;
219         ///
220         bool free_spacing;
221         ///
222         bool pass_thru;
223         ///
224         bool parbreak_is_newline;
225         /// show this in toc
226         int toclevel;
227         /// special value of toclevel for non-section layouts
228         static const int NOT_IN_TOC;
229
230         /** true when the fragile commands in the paragraph need to be
231             \protect'ed. */
232         bool needprotect;
233         /// true when empty paragraphs should be kept.
234         bool keepempty;
235         /// Type of LaTeX object
236         LatexType latextype;
237         /// Does this object belong in the title part of the document?
238         bool intitle;
239         /// Is the content to go in the preamble rather than the body?
240         bool inpreamble;
241         /// Number of requried arguments for this command or environment
242         unsigned int reqargs;
243         /// Number of optional arguments for this command or environment
244         /// These MUST come at the beginning, so:
245         ///  \cmd[opt1][opt2]{req1}{here is the text from LyX}
246         /// is fine. But:
247         ///  \cmd[opt1]{req1}[opt2]{here is the text from LyX}
248         /// is not.
249         unsigned int optargs;
250         /// Which counter to step
251         docstring counter;
252         /// Prefix to use when creating labels
253         docstring refprefix;
254         /// Depth of XML command
255         int commanddepth;
256
257         /// Return a pointer on a new layout suitable to describe a caption.
258         /// FIXME: remove this eventually. This is only for tex2lyx
259         /// until it has proper support for the caption inset (JMarc)
260         static Layout * forCaption();
261
262         /// Is this spellchecked?
263         bool spellcheck;
264
265
266 private:
267         /// generates the default CSS for this layout
268         void makeDefaultCSS() const;
269         ///
270         std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
271         ///
272         std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
273         
274         /// Name of the layout/paragraph environment
275         docstring name_;
276
277         /// LaTeX name for environment
278         std::string latexname_;
279
280         /** Is this layout the default layout for an unknown layout? If
281          * so, its name will be displayed as xxx (unknown).
282          */
283         bool unknown_;
284
285         /** Name of an layout that has replaced this layout.
286             This is used to rename a layout, while keeping backward
287             compatibility
288         */
289         docstring obsoleted_by_;
290
291         /** Name of an layout which preamble must come before this one
292             This is used when the preamble snippet uses macros defined in
293             another preamble
294          */
295         docstring depends_on_;
296
297         /// Label string. "Abstract", "Reference", "Caption"...
298         docstring labelstring_;
299         ///
300         docstring endlabelstring_;
301         /// Label string inside appendix. "Appendix", ...
302         docstring labelstring_appendix_;
303         /// LaTeX parameter for environment
304         std::string latexparam_;
305         /// Internal tag to use (e.g., <title></title> for sect header)
306         std::string innertag_;
307         /// Internal tag to use (e.g. to surround varentrylist label)
308         std::string labeltag_;
309         /// Internal tag to surround the item text in a list.
310         std::string itemtag_;
311         /// The interpretation of this tag varies depending upon the latextype.
312         /// In an environment, it is the tag enclosing all content for this set of 
313         /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize, 
314         /// it would be: ul. (You get the idea.)
315         ///
316         /// For a command, it is the tag enclosing the content of the command.
317         /// So, for section, it might be: h2.
318         /// 
319         /// For the paragraph type, it is the tag that will enclose each paragraph.
320         ///
321         /// Defaults to "div".
322         mutable std::string htmltag_;
323         /// Additional attributes for inclusion with the start tag. Defaults
324         /// to: class="layoutname".
325         mutable std::string htmlattr_;
326         /// Tag for individual paragraphs in an environment. In lists, this
327         /// would be something like "li". But it also needs to be set for
328         /// quotation, e.g., since the paragraphs in a quote need to be 
329         /// in "p" tags. Default is "div".
330         /// Note that when I said "environment", I meant it: This has no
331         /// effect for LATEX_PARAGRAPH type layouts.
332         mutable std::string htmlitemtag_;
333         /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
334         mutable std::string htmlitemattr_;
335         /// Tag for labels, of whatever sort. One use for this is in setting
336         /// descriptions, in which case it would be: dt. Another use is to
337         /// customize the display of, say, the auto-generated label for 
338         /// sections. Defaults to "span".
339         /// If set to "NONE", this suppresses the printing of the label.
340         mutable std::string htmllabeltag_;
341         /// Attributes for the label. Defaults to: class="layoutname_label".
342         mutable std::string htmllabelattr_;
343         /// Whether to put the label before the item, or within the item.
344         /// I.e., do we have (true):
345         ///    <label>...</label><item>...</item>
346         /// or instead (false):
347         ///    <item><label>...</label>...</item>
348         /// The latter is the default.
349         bool htmllabelfirst_;
350         /// CSS information needed by this layout.
351         docstring htmlstyle_;
352         /// Should we generate the default CSS for this layout, even if HTMLStyle
353         /// has been given? Default is false.
354         /// Note that the default CSS is output first, then the user CSS, so it is
355         /// possible to override what one does not want.
356         bool htmlforcecss_;
357         /// A cache for the default style info so generated.
358         mutable docstring htmldefaultstyle_;
359         /// Any other info for the HTML header.
360         docstring htmlpreamble_;
361         /// Whether this is the <title> paragraph.
362         bool htmltitle_;
363         /// calculating this is expensive, so we cache it.
364         mutable std::string defaultcssclass_;
365         /// This is the `category' for this layout. The following are
366         /// recommended basic categories: FrontMatter, BackMatter, MainText,
367         /// Section, Starred, List, Theorem.
368         docstring category_;
369         /// Macro definitions needed for this layout
370         docstring preamble_;
371         /// Language dependent macro definitions needed for this layout
372         docstring langpreamble_;
373         /// Language and babel dependent macro definitions needed for this layout
374         docstring babelpreamble_;
375         /// Packages needed for this layout
376         std::set<std::string> requires_;
377 };
378
379 } // namespace lyx
380
381 #endif