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.
19 #include "LayoutEnums.h"
21 #include "support/docstring.h"
32 /* Fixed labels are printed flushright, manual labels flushleft.
33 * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
34 * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
35 * This seems a funny restriction, but I think other combinations are
36 * not needed, so I will not change it yet.
37 * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC.
41 /* There is a parindent and a parskip. Which one is used depends on the
42 * paragraph_separation-flag of the text-object.
43 * BUT: parindent is only thrown away, if a parskip is defined! So if you
44 * want a space between the paragraphs and a parindent at the same time,
45 * you should set parskip to zero and use topsep, parsep and bottomsep.
47 * The standard layout is an exception: its parindent is only set, if the
48 * previous paragraph is standard too. Well, this is LateX and it is good!
56 /// is this layout a default layout created for an unknown layout
57 bool isUnknown() const { return unknown_; }
58 void setUnknown(bool unknown) { unknown_ = unknown; }
59 /// Reads a layout definition from file
60 /// \return true on success.
61 bool read(Lexer &, TextClass const &);
63 void readAlign(Lexer &);
65 void readAlignPossible(Lexer &);
67 void readLabelType(Lexer &);
69 void readEndLabelType(Lexer &);
71 void readMargin(Lexer &);
73 void readLatexType(Lexer &);
75 void readSpacing(Lexer &);
77 docstring const & name() const { return name_; }
79 void setName(docstring const & n) { name_ = n; }
81 docstring const & obsoleted_by() const { return obsoleted_by_; }
83 docstring const & depends_on() const { return depends_on_; }
85 std::string const & latexname() const { return latexname_; }
87 void setLatexName(std::string const & n) { latexname_ = n; }
89 docstring const & labelstring(bool in_appendix) const
90 { return in_appendix ? labelstring_appendix_ : labelstring_; }
92 docstring const & endlabelstring() const { return endlabelstring_; }
94 docstring const & category() const { return category_; }
96 docstring const & preamble() const { return preamble_; }
97 /// Get language dependent macro definitions needed for this layout
98 /// for language \p lang
99 docstring const langpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
100 /// Get language and babel dependent macro definitions needed for
101 /// this layout for language \p lang
102 docstring const babelpreamble(Language const * lang, Encoding const & enc, bool const polyglossia) const;
104 std::set<std::string> const & requires() const { return requires_; }
106 std::string const & latexparam() const { return latexparam_; }
108 std::string const & innertag() const { return innertag_; }
110 std::string const & labeltag() const { return labeltag_; }
112 std::string const & itemtag() const { return itemtag_; }
114 std::string const & htmltag() const;
116 std::string const & htmlattr() const;
118 std::string const & htmlitemtag() const;
120 std::string const & htmlitemattr() const;
122 std::string const & htmllabeltag() const;
124 std::string const & htmllabelattr() const;
126 std::string defaultCSSClass() const;
128 bool htmllabelfirst() const { return htmllabelfirst_; }
130 docstring htmlstyle() const;
132 docstring const & htmlpreamble() const { return htmlpreamble_; }
134 bool htmltitle() const { return htmltitle_; }
136 bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
138 bool isCommand() const { return latextype == LATEX_COMMAND; }
140 bool isEnvironment() const {
141 return latextype == LATEX_ENVIRONMENT
142 || latextype == LATEX_BIB_ENVIRONMENT
143 || latextype == LATEX_ITEM_ENVIRONMENT
144 || latextype == LATEX_LIST_ENVIRONMENT;
148 bool operator==(Layout const &) const;
150 bool operator!=(Layout const & rhs) const
151 { return !(*this == rhs); }
153 ////////////////////////////////////////////////////////////////
155 ////////////////////////////////////////////////////////////////
156 /** Default font for this layout/environment.
157 The main font for this kind of environment. If an attribute has
158 INHERITED_*, it means that the value is specified by
159 the defaultfont for the entire layout. If we are nested, the
160 font is inherited from the font in the environment one level
161 up until the font is resolved. The values :IGNORE_*
162 and FONT_TOGGLE are illegal here.
166 /** Default font for labels.
167 Interpretation the same as for font above
171 /** Resolved version of the font for this layout/environment.
172 This is a resolved version the default font. The font is resolved
173 against the defaultfont of the entire layout.
177 /** Resolved version of the font used for labels.
178 This is a resolved version the label font. The font is resolved
179 against the defaultfont of the entire layout.
181 FontInfo reslabelfont;
183 /// Text that dictates how wide the left margin is on the screen
184 docstring leftmargin;
185 /// Text that dictates how wide the right margin is on the screen
186 docstring rightmargin;
187 /// Text that dictates how much space to leave after a potential label
189 /// Text that dictates how much space to leave before a potential label
190 docstring labelindent;
191 /// Text that dictates the width of the indentation of indented pars
202 double labelbottomsep;
210 LyXAlignment alignpossible;
214 EndLabelType endlabeltype;
216 MarginType margintype;
218 bool newline_allowed;
226 bool parbreak_is_newline;
229 /// special value of toclevel for non-section layouts
230 static const int NOT_IN_TOC;
232 /** true when the fragile commands in the paragraph need to be
235 /// true when empty paragraphs should be kept.
237 /// Type of LaTeX object
239 /// Does this object belong in the title part of the document?
241 /// Is the content to go in the preamble rather than the body?
243 /// Number of requried arguments for this command or environment
244 unsigned int reqargs;
245 /// Number of optional arguments for this command or environment
246 /// These MUST come at the beginning, so:
247 /// \cmd[opt1][opt2]{req1}{here is the text from LyX}
249 /// \cmd[opt1]{req1}[opt2]{here is the text from LyX}
251 unsigned int optargs;
252 /// Which counter to step
254 /// Prefix to use when creating labels
256 /// Depth of XML command
259 /// Return a pointer on a new layout suitable to describe a caption.
260 /// FIXME: remove this eventually. This is only for tex2lyx
261 /// until it has proper support for the caption inset (JMarc)
262 static Layout * forCaption();
264 /// Is this spellchecked?
269 /// generates the default CSS for this layout
270 void makeDefaultCSS() const;
272 std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
274 std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
276 /// Name of the layout/paragraph environment
279 /// LaTeX name for environment
280 std::string latexname_;
282 /** Is this layout the default layout for an unknown layout? If
283 * so, its name will be displayed as xxx (unknown).
287 /** Name of an layout that has replaced this layout.
288 This is used to rename a layout, while keeping backward
291 docstring obsoleted_by_;
293 /** Name of an layout which preamble must come before this one
294 This is used when the preamble snippet uses macros defined in
297 docstring depends_on_;
299 /// Label string. "Abstract", "Reference", "Caption"...
300 docstring labelstring_;
302 docstring endlabelstring_;
303 /// Label string inside appendix. "Appendix", ...
304 docstring labelstring_appendix_;
305 /// LaTeX parameter for environment
306 std::string latexparam_;
307 /// Internal tag to use (e.g., <title></title> for sect header)
308 std::string innertag_;
309 /// Internal tag to use (e.g. to surround varentrylist label)
310 std::string labeltag_;
311 /// Internal tag to surround the item text in a list.
312 std::string itemtag_;
313 /// The interpretation of this tag varies depending upon the latextype.
314 /// In an environment, it is the tag enclosing all content for this set of
315 /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize,
316 /// it would be: ul. (You get the idea.)
318 /// For a command, it is the tag enclosing the content of the command.
319 /// So, for section, it might be: h2.
321 /// For the paragraph type, it is the tag that will enclose each paragraph.
323 /// Defaults to "div".
324 mutable std::string htmltag_;
325 /// Additional attributes for inclusion with the start tag. Defaults
326 /// to: class="layoutname".
327 mutable std::string htmlattr_;
328 /// Tag for individual paragraphs in an environment. In lists, this
329 /// would be something like "li". But it also needs to be set for
330 /// quotation, e.g., since the paragraphs in a quote need to be
331 /// in "p" tags. Default is "div".
332 /// Note that when I said "environment", I meant it: This has no
333 /// effect for LATEX_PARAGRAPH type layouts.
334 mutable std::string htmlitemtag_;
335 /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
336 mutable std::string htmlitemattr_;
337 /// Tag for labels, of whatever sort. One use for this is in setting
338 /// descriptions, in which case it would be: dt. Another use is to
339 /// customize the display of, say, the auto-generated label for
340 /// sections. Defaults to "span".
341 /// If set to "NONE", this suppresses the printing of the label.
342 mutable std::string htmllabeltag_;
343 /// Attributes for the label. Defaults to: class="layoutname_label".
344 mutable std::string htmllabelattr_;
345 /// Whether to put the label before the item, or within the item.
346 /// I.e., do we have (true):
347 /// <label>...</label><item>...</item>
348 /// or instead (false):
349 /// <item><label>...</label>...</item>
350 /// The latter is the default.
351 bool htmllabelfirst_;
352 /// CSS information needed by this layout.
353 docstring htmlstyle_;
354 /// Should we generate the default CSS for this layout, even if HTMLStyle
355 /// has been given? Default is false.
356 /// Note that the default CSS is output first, then the user CSS, so it is
357 /// possible to override what one does not want.
359 /// A cache for the default style info so generated.
360 mutable docstring htmldefaultstyle_;
361 /// Any other info for the HTML header.
362 docstring htmlpreamble_;
363 /// Whether this is the <title> paragraph.
365 /// calculating this is expensive, so we cache it.
366 mutable std::string defaultcssclass_;
367 /// This is the `category' for this layout. The following are
368 /// recommended basic categories: FrontMatter, BackMatter, MainText,
369 /// Section, Starred, List, Theorem.
371 /// Macro definitions needed for this layout
373 /// Language dependent macro definitions needed for this layout
374 docstring langpreamble_;
375 /// Language and babel dependent macro definitions needed for this layout
376 docstring babelpreamble_;
377 /// Packages needed for this layout
378 std::set<std::string> requires_;