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
11 * Full author contact details are available in file CREDITS.
18 #include "LayoutEnums.h"
20 #include "support/docstring.h"
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.
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.
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!
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 &);
61 void readAlign(Lexer &);
63 void readAlignPossible(Lexer &);
65 void readLabelType(Lexer &);
67 void readEndLabelType(Lexer &);
69 void readMargin(Lexer &);
71 void readLatexType(Lexer &);
73 void readSpacing(Lexer &);
75 docstring const & name() const { return name_; }
77 void setName(docstring const & n) { name_ = n; }
79 docstring const & obsoleted_by() const { return obsoleted_by_; }
81 docstring const & depends_on() const { return depends_on_; }
83 std::string const & latexname() const { return latexname_; }
85 void setLatexName(std::string const & n) { latexname_ = n; }
87 docstring const & labelstring(bool in_appendix) const
88 { return in_appendix ? labelstring_appendix_ : labelstring_; }
90 docstring const & endlabelstring() const { return endlabelstring_; }
92 docstring const & category() const { return category_; }
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_; }
102 std::set<std::string> const & requires() const { return requires_; }
104 std::string const & latexparam() const { return latexparam_; }
106 std::string const & innertag() const { return innertag_; }
108 std::string const & labeltag() const { return labeltag_; }
110 std::string const & itemtag() const { return itemtag_; }
112 std::string const & htmltag() const;
114 std::string const & htmlattr() const;
116 std::string const & htmlitemtag() const;
118 std::string const & htmlitemattr() const;
120 std::string const & htmllabeltag() const;
122 std::string const & htmllabelattr() const;
124 std::string defaultCSSClass() const;
126 bool htmllabelfirst() const { return htmllabelfirst_; }
128 docstring htmlstyle() const;
130 docstring const & htmlpreamble() const { return htmlpreamble_; }
132 bool htmltitle() const { return htmltitle_; }
134 bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
136 bool isCommand() const { return latextype == LATEX_COMMAND; }
138 bool isEnvironment() const {
139 return latextype == LATEX_ENVIRONMENT
140 || latextype == LATEX_BIB_ENVIRONMENT
141 || latextype == LATEX_ITEM_ENVIRONMENT
142 || latextype == LATEX_LIST_ENVIRONMENT;
146 bool operator==(Layout const &) const;
148 bool operator!=(Layout const & rhs) const
149 { return !(*this == rhs); }
151 ////////////////////////////////////////////////////////////////
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.
164 /** Default font for labels.
165 Interpretation the same as for font above
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.
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.
179 FontInfo reslabelfont;
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
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
200 double labelbottomsep;
208 LyXAlignment alignpossible;
212 EndLabelType endlabeltype;
214 MarginType margintype;
216 bool newline_allowed;
224 bool parbreak_is_newline;
227 /// special value of toclevel for non-section layouts
228 static const int NOT_IN_TOC;
230 /** true when the fragile commands in the paragraph need to be
233 /// true when empty paragraphs should be kept.
235 /// Type of LaTeX object
237 /// Does this object belong in the title part of the document?
239 /// Is the content to go in the preamble rather than the body?
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}
247 /// \cmd[opt1]{req1}[opt2]{here is the text from LyX}
249 unsigned int optargs;
250 /// Which counter to step
252 /// Prefix to use when creating labels
254 /// Depth of XML command
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();
262 /// Is this spellchecked?
267 /// generates the default CSS for this layout
268 void makeDefaultCSS() const;
270 std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
272 std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
274 /// Name of the layout/paragraph environment
277 /// LaTeX name for environment
278 std::string latexname_;
280 /** Is this layout the default layout for an unknown layout? If
281 * so, its name will be displayed as xxx (unknown).
285 /** Name of an layout that has replaced this layout.
286 This is used to rename a layout, while keeping backward
289 docstring obsoleted_by_;
291 /** Name of an layout which preamble must come before this one
292 This is used when the preamble snippet uses macros defined in
295 docstring depends_on_;
297 /// Label string. "Abstract", "Reference", "Caption"...
298 docstring labelstring_;
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.)
316 /// For a command, it is the tag enclosing the content of the command.
317 /// So, for section, it might be: h2.
319 /// For the paragraph type, it is the tag that will enclose each paragraph.
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.
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.
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.
369 /// Macro definitions needed for this layout
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_;