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"
31 /* Fixed labels are printed flushright, manual labels flushleft.
32 * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
33 * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
34 * This seems a funny restriction, but I think other combinations are
35 * not needed, so I will not change it yet.
36 * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC.
40 /* There is a parindent and a parskip. Which one is used depends on the
41 * paragraph_separation-flag of the text-object.
42 * BUT: parindent is only thrown away, if a parskip is defined! So if you
43 * want a space between the paragraphs and a parindent at the same time,
44 * you should set parskip to zero and use topsep, parsep and bottomsep.
46 * The standard layout is an exception: its parindent is only set, if the
47 * previous paragraph is standard too. Well, this is LateX and it is good!
55 /// is this layout a default layout created for an unknown layout
56 bool isUnknown() const { return unknown_; }
57 void setUnknown(bool unknown) { unknown_ = unknown; }
58 /// Reads a layout definition from file
59 /// \return true on success.
60 bool read(Lexer &, TextClass const &);
62 void readAlign(Lexer &);
64 void readAlignPossible(Lexer &);
66 void readLabelType(Lexer &);
68 void readEndLabelType(Lexer &);
70 void readMargin(Lexer &);
72 void readLatexType(Lexer &);
74 void readSpacing(Lexer &);
76 docstring const & name() const { return name_; }
78 void setName(docstring const & n) { name_ = n; }
80 docstring const & obsoleted_by() const { return obsoleted_by_; }
82 docstring const & depends_on() const { return depends_on_; }
84 std::string const & latexname() const { return latexname_; }
86 void setLatexName(std::string const & n) { latexname_ = n; }
88 docstring const & labelstring(bool in_appendix) const
89 { return in_appendix ? labelstring_appendix_ : labelstring_; }
91 docstring const & endlabelstring() const { return endlabelstring_; }
93 docstring const & category() const { return category_; }
95 docstring const & preamble() const { return preamble_; }
96 /// Get language dependent macro definitions needed for this layout
97 /// for language \p lang
98 docstring const langpreamble(Language const * lang) const;
99 /// Get language and babel dependent macro definitions needed for
100 /// this layout for language \p lang
101 docstring const babelpreamble(Language const * lang) const;
103 std::set<std::string> const & requires() const { return requires_; }
105 std::string const & latexparam() const { return latexparam_; }
107 std::string const & innertag() const { return innertag_; }
109 std::string const & labeltag() const { return labeltag_; }
111 std::string const & itemtag() const { return itemtag_; }
113 std::string const & htmltag() const;
115 std::string const & htmlattr() const;
117 std::string const & htmlitemtag() const;
119 std::string const & htmlitemattr() const;
121 std::string const & htmllabeltag() const;
123 std::string const & htmllabelattr() const;
125 std::string defaultCSSClass() const;
127 bool htmllabelfirst() const { return htmllabelfirst_; }
129 docstring htmlstyle() const;
131 docstring const & htmlpreamble() const { return htmlpreamble_; }
133 bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
135 bool isCommand() const { return latextype == LATEX_COMMAND; }
137 bool isEnvironment() const {
138 return latextype == LATEX_ENVIRONMENT
139 || latextype == LATEX_BIB_ENVIRONMENT
140 || latextype == LATEX_ITEM_ENVIRONMENT
141 || latextype == LATEX_LIST_ENVIRONMENT;
145 bool operator==(Layout const &) const;
147 bool operator!=(Layout const & rhs) const
148 { return !(*this == rhs); }
150 ////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////
153 /** Default font for this layout/environment.
154 The main font for this kind of environment. If an attribute has
155 INHERITED_*, it means that the value is specified by
156 the defaultfont for the entire layout. If we are nested, the
157 font is inherited from the font in the environment one level
158 up until the font is resolved. The values :IGNORE_*
159 and FONT_TOGGLE are illegal here.
163 /** Default font for labels.
164 Interpretation the same as for font above
168 /** Resolved version of the font for this layout/environment.
169 This is a resolved version the default font. The font is resolved
170 against the defaultfont of the entire layout.
174 /** Resolved version of the font used for labels.
175 This is a resolved version the label font. The font is resolved
176 against the defaultfont of the entire layout.
178 FontInfo reslabelfont;
180 /// Text that dictates how wide the left margin is on the screen
181 docstring leftmargin;
182 /// Text that dictates how wide the right margin is on the screen
183 docstring rightmargin;
184 /// Text that dictates how much space to leave after a potential label
186 /// Text that dictates how much space to leave before a potential label
187 docstring labelindent;
188 /// Text that dictates the width of the indentation of indented pars
199 double labelbottomsep;
207 LyXAlignment alignpossible;
211 EndLabelType endlabeltype;
213 MarginType margintype;
219 bool newline_allowed;
228 /// special value of toclevel for non-section layouts
229 static const int NOT_IN_TOC;
231 /** true when the fragile commands in the paragraph need to be
234 /// true when empty paragraphs should be kept.
236 /// Type of LaTeX object
238 /// Does this object belong in the title part of the document?
240 /// Is the content to go in the preamble rather than the body?
242 /// Does this layout allow for an optional parameter?
244 /// Which counter to step
246 /// Depth of XML command
249 /// Return a pointer on a new layout suitable to describe a caption.
250 /// FIXME: remove this eventually. This is only for tex2lyx
251 /// until it has proper support for the caption inset (JMarc)
252 static Layout * forCaption();
256 /// generates the default CSS for this layout
257 void makeDefaultCSS() const;
259 std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
261 std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
263 /// Name of the layout/paragraph environment
266 /// LaTeX name for environment
267 std::string latexname_;
269 /** Is this layout the default layout for an unknown layout? If
270 * so, its name will be displayed as xxx (unknown).
274 /** Name of an layout that has replaced this layout.
275 This is used to rename a layout, while keeping backward
278 docstring obsoleted_by_;
280 /** Name of an layout which preamble must come before this one
281 This is used when the preamble snippet uses macros defined in
284 docstring depends_on_;
286 /// Label string. "Abstract", "Reference", "Caption"...
287 docstring labelstring_;
289 docstring endlabelstring_;
290 /// Label string inside appendix. "Appendix", ...
291 docstring labelstring_appendix_;
292 /// LaTeX parameter for environment
293 std::string latexparam_;
294 /// Internal tag to use (e.g., <title></title> for sect header)
295 std::string innertag_;
296 /// Internal tag to use (e.g. to surround varentrylist label)
297 std::string labeltag_;
298 /// Internal tag to surround the item text in a list.
299 std::string itemtag_;
300 /// The interpretation of this tag varies depending upon the latextype.
301 /// In an environment, it is the tag enclosing all content for this set of
302 /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize,
303 /// it would be: ul. (You get the idea.)
305 /// For a command, it is the tag enclosing the content of the command.
306 /// So, for section, it might be: h2.
308 /// For the paragraph type, it is the tag that will enclose each paragraph.
310 /// Defaults to "div".
311 mutable std::string htmltag_;
312 /// Additional attributes for inclusion with the start tag. Defaults
313 /// to: class="layoutname".
314 mutable std::string htmlattr_;
315 /// Tag for individual paragraphs in an environment. In lists, this
316 /// would be something like "li". But it also needs to be set for
317 /// quotation, e.g., since the paragraphs in a quote need to be
318 /// in "p" tags. Default is "div".
319 /// Note that when I said "environment", I meant it: This has no
320 /// effect for LATEX_PARAGRAPH type layouts.
321 mutable std::string htmlitemtag_;
322 /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
323 mutable std::string htmlitemattr_;
324 /// Tag for labels, of whatever sort. One use for this is in setting
325 /// descriptions, in which case it would be: dt. Another use is to
326 /// customize the display of, say, the auto-generated label for
327 /// sections. Defaults to "span".
328 /// If set to "NONE", this suppresses the printing of the label.
329 mutable std::string htmllabeltag_;
330 /// Attributes for the label. Defaults to: class="layoutname_label".
331 mutable std::string htmllabelattr_;
332 /// Whether to put the label before the item, or within the item.
333 /// I.e., do we have (true):
334 /// <label>...</label><item>...</item>
335 /// or instead (false):
336 /// <item><label>...</label>...</item>
337 /// The latter is the default.
338 bool htmllabelfirst_;
339 /// CSS information needed by this layout.
340 docstring htmlstyle_;
341 /// Should we generate the default CSS for this layout, even if HTMLStyle
342 /// has been given? Default is false.
343 /// Note that the default CSS is output first, then the user CSS, so it is
344 /// possible to override what one does not want.
346 /// A cache for the default style info so generated.
347 mutable docstring htmldefaultstyle_;
348 /// Any other info for the HTML header.
349 docstring htmlpreamble_;
350 /// calculating this is expensive, so we cache it.
351 mutable std::string defaultcssclass_;
352 /// This is the `category' for this layout. The following are
353 /// recommended basic categories: FrontMatter, BackMatter, MainText,
354 /// Section, Starred, List, Theorem.
356 /// Macro definitions needed for this layout
358 /// Language dependent macro definitions needed for this layout
359 docstring langpreamble_;
360 /// Language and babel dependent macro definitions needed for this layout
361 docstring babelpreamble_;
362 /// Packages needed for this layout
363 std::set<std::string> requires_;