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/debug.h"
21 #include "support/docstring.h"
29 namespace support { class Lexer; }
33 /* Fixed labels are printed flushright, manual labels flushleft.
34 * MARGIN_MANUAL and MARGIN_FIRST_DYNAMIC are *only* for LABEL_MANUAL,
35 * MARGIN_DYNAMIC and MARGIN_STATIC are *not* for LABEL_MANUAL.
36 * This seems a funny restriction, but I think other combinations are
37 * not needed, so I will not change it yet.
38 * Correction: MARGIN_FIRST_DYNAMIC also usable with LABEL_STATIC.
42 /* There is a parindent and a parskip. Which one is used depends on the
43 * paragraph_separation-flag of the text-object.
44 * BUT: parindent is only thrown away, if a parskip is defined! So if you
45 * want a space between the paragraphs and a parindent at the same time,
46 * you should set parskip to zero and use topsep, parsep and bottomsep.
48 * The standard layout is an exception: its parindent is only set, if the
49 * previous paragraph is standard too. Well, this is LateX and it is good!
57 /// is this layout a default layout created for an unknown layout
58 bool isUnknown() const { return unknown_; }
59 void setUnknown(bool unknown) { unknown_ = unknown; }
60 /// Reads a layout definition from file
61 /// \return true on success.
62 bool read(support::Lexer &, TextClass const &, bool validating = false);
64 void readAlign(support::Lexer &);
66 void readAlignPossible(support::Lexer &);
68 void readLabelType(support::Lexer &);
70 void readEndLabelType(support::Lexer &);
72 void readMargin(support::Lexer &);
74 void readLatexType(support::Lexer &);
76 void readSpacing(support::Lexer &);
78 void readArgument(support::Lexer &, bool);
79 /// Write a layout definition in utf8 encoding
80 void write(std::ostream &) const;
82 docstring const & name() const { return name_; }
84 void setName(docstring const & n) { name_ = n; }
86 docstring const & obsoleted_by() const { return obsoleted_by_; }
88 docstring const & depends_on() const { return depends_on_; }
90 std::string const & latexname() const { return latexname_; }
92 std::string const & itemcommand() const { return itemcommand_; }
93 /// One argument of this layout
95 docstring labelstring;
97 bool mandatory = false;
98 bool nodelims = false;
101 docstring defaultarg;
104 std::string required;
105 std::string decoration;
106 FontInfo font = inherit_font;
107 FontInfo labelfont = inherit_font;
108 bool autoinsert = false;
109 bool insertcotext = false;
110 bool insertonnewline = false;
111 ArgPassThru passthru = PT_INHERITED;
112 docstring pass_thru_chars;
113 bool is_toc_caption = false;
114 bool free_spacing = false;
115 std::string newlinecmd;
116 /// The DocBook tag corresponding to this argument.
117 docstring docbooktag;
118 docstring docbooktagtype;
119 docstring docbookattr;
120 /// Whether this argument should be output after the main tag (default: inside). The result if the argument
121 /// should be output both before and after the main tag is undefined.
122 bool docbookargumentbeforemaintag = false;
123 /// Whether this argument should be output before the main tag (default: inside). The result if the argument
124 /// should be output both before and after the main tag is undefined.
125 bool docbookargumentaftermaintag = false;
128 typedef std::map<std::string, latexarg> LaTeXArgMap;
130 LaTeXArgMap const & latexargs() const { return latexargs_; }
132 LaTeXArgMap const & postcommandargs() const { return postcommandargs_; }
134 LaTeXArgMap const & listpreamble() const { return listpreamble_; }
136 LaTeXArgMap const & itemargs() const { return itemargs_; }
137 /// Returns true is the layout has arguments. If false, then an
138 /// InsetArgument in this layout stands for the parent InsetText.
139 bool hasArgs() const;
140 /// Returns latexargs() + postcommandargs() + itemargs().
141 /// But note that it returns a *copy*, not a reference, so do not do
143 /// Layout::LaTeXArgMap::iterator it = args().begin();
144 /// Layout::LaTeXArgMap::iterator en = args().end();
145 /// Those are iterators for different containers.
146 LaTeXArgMap args() const;
150 int requiredArgs() const;
152 docstring const & labelstring(bool in_appendix) const
153 { return in_appendix ? labelstring_appendix_ : labelstring_; }
155 docstring const & endlabelstring() const { return endlabelstring_; }
157 docstring const & category() const { return category_; }
159 docstring const & preamble() const { return preamble_; }
160 /// Get language dependent macro definitions needed for this layout
161 /// for language \p lang
162 docstring const langpreamble() const { return langpreamble_; }
163 /// Get language and babel dependent macro definitions needed for
164 /// this layout for language \p lang
165 docstring const babelpreamble() const { return babelpreamble_; }
167 std::set<std::string> const & required() const { return required_; }
169 std::set<docstring> const & autonests() const { return autonests_; }
171 std::set<docstring> const & isAutonestedBy() const { return autonested_by_; }
173 std::string const & latexparam() const { return latexparam_; }
175 docstring leftdelim() const { return leftdelim_; }
177 docstring rightdelim() const { return rightdelim_; }
179 std::string const & innertag() const { return innertag_; }
181 std::string const & labeltag() const { return labeltag_; }
183 std::string const & itemtag() const { return itemtag_; }
185 std::string const & htmltag() const;
187 std::string const & htmlattr() const { return htmlattr_; }
189 std::string const & htmlclass() const;
190 /// Returns a complete attribute string, including class, etc.
191 std::string const & htmlGetAttrString() const;
193 std::string const & htmlitemtag() const;
195 std::string const & htmlitemattr() const;
197 std::string const & htmllabeltag() const;
199 std::string const & htmllabelattr() const;
201 bool htmlintoc() const { return htmlintoc_; }
203 std::string defaultCSSClass() const;
205 bool htmllabelfirst() const { return htmllabelfirst_; }
207 docstring htmlstyle() const;
209 docstring const & htmlpreamble() const { return htmlpreamble_; }
211 bool htmltitle() const { return htmltitle_; }
213 std::string const & docbooktag() const;
215 std::string const & docbookattr() const;
217 std::string const & docbooktagtype() const;
219 std::string const & docbookinnertag() const;
221 std::string const & docbookinnerattr() const;
223 std::string const & docbookinnertagtype() const;
225 std::string const & docbookininfo() const;
227 bool docbookabstract() const { return docbookabstract_; }
229 std::string const & docbookwrappertag() const;
231 std::string const & docbookwrapperattr() const;
233 std::string const & docbookwrappertagtype() const;
235 bool docbookwrappermergewithprevious() const { return docbookwrappermergewithprevious_; }
237 std::string const & docbooksectiontag() const;
239 bool docbooksection() const { return docbooksection_; }
241 std::string const & docbookitemwrappertag() const;
243 std::string const & docbookitemwrapperattr() const;
245 std::string const & docbookitemwrappertagtype() const;
247 std::string const & docbookitemlabeltag() const;
249 std::string const & docbookitemlabelattr() const;
251 std::string const & docbookitemlabeltagtype() const;
253 std::string const & docbookiteminnertag() const;
255 std::string const & docbookiteminnerattr() const;
257 std::string const & docbookiteminnertagtype() const;
259 std::string const & docbookitemtag() const;
261 std::string const & docbookitemattr() const;
263 std::string const & docbookitemtagtype() const;
265 std::string const & docbookforceabstracttag() const;
267 bool docbooknofontinside() const { return docbooknofontinside_; }
269 bool docbookgeneratetitle() const { return docbookgeneratetitle_; }
271 bool isParagraph() const { return latextype == LATEX_PARAGRAPH; }
273 bool isCommand() const { return latextype == LATEX_COMMAND; }
275 bool isEnvironment() const {
276 return latextype == LATEX_ENVIRONMENT
277 || latextype == LATEX_BIB_ENVIRONMENT
278 || latextype == LATEX_ITEM_ENVIRONMENT
279 || latextype == LATEX_LIST_ENVIRONMENT;
281 /// Is this the kind of layout in which adjacent paragraphs
282 /// are handled as one group?
283 bool isParagraphGroup() const { return par_group_; }
285 bool labelIsInline() const {
286 return labeltype == LABEL_STATIC
287 || labeltype == LABEL_SENSITIVE
288 || labeltype == LABEL_ENUMERATE
289 || labeltype == LABEL_ITEMIZE;
291 bool labelIsAbove() const {
292 return labeltype == LABEL_ABOVE
293 || labeltype == LABEL_CENTERED
294 || labeltype == LABEL_BIBLIO;
296 bool isNumHeadingLabelType() const {
297 return labeltype == LABEL_ABOVE
298 || labeltype == LABEL_CENTERED
299 || labeltype == LABEL_STATIC;
302 bool addToToc() const { return add_to_toc_; }
304 std::string tocType() const { return toc_type_; }
306 bool isTocCaption() const { return is_toc_caption_; }
309 bool operator==(Layout const &) const;
311 bool operator!=(Layout const & rhs) const
312 { return !(*this == rhs); }
314 ////////////////////////////////////////////////////////////////
316 ////////////////////////////////////////////////////////////////
317 /** Default font for this layout/environment.
318 The main font for this kind of environment. If an attribute has
319 INHERITED_*, it means that the value is specified by
320 the defaultfont for the entire layout. If we are nested, the
321 font is inherited from the font in the environment one level
322 up until the font is resolved. The values :IGNORE_*
323 and FONT_TOGGLE are illegal here.
327 /** Default font for labels.
328 Interpretation the same as for font above
332 /** Resolved version of the font for this layout/environment.
333 This is a resolved version the default font. The font is resolved
334 against the defaultfont of the entire layout.
338 /** Resolved version of the font used for labels.
339 This is a resolved version the label font. The font is resolved
340 against the defaultfont of the entire layout.
342 FontInfo reslabelfont;
344 /// Text that dictates how wide the left margin is on the screen
345 docstring leftmargin;
346 /// Text that dictates how wide the right margin is on the screen
347 docstring rightmargin;
348 /// Text that dictates how much space to leave after a potential label
350 /// Text that dictates how much space to leave before a potential label
351 docstring labelindent;
352 /// Text that dictates the width of the indentation of indented pars
363 double labelbottomsep;
371 LyXAlignment alignpossible;
375 EndLabelType endlabeltype;
377 MarginType margintype;
379 bool newline_allowed;
383 ToggleIndentation toggle_indent;
388 /// Individual chars to be passed verbatim
389 docstring pass_thru_chars;
391 bool parbreak_is_newline;
394 /// special value of toclevel for non-section layouts
395 static const int NOT_IN_TOC;
397 /** true when the fragile commands in the paragraph need to be
400 /** true when the verbatim stuff of this layout needs to be
403 /** true when specific commands in this paragraph need to be
404 protected in an \mbox. */
405 bool needmboxprotect;
406 /// true when empty paragraphs should be kept.
408 /// Type of LaTeX object
410 /// Does this object belong in the title part of the document?
412 /// Is the content to go in the preamble rather than the body?
414 /// Which counter to step
418 /// Step parent counter?
419 bool stepparentcounter;
420 /// Prefix to use when creating labels
422 /// Depth of XML command
425 /// Is this spellchecked?
428 * Should this layout definition always be written to the document preamble?
429 * Possible values are:
430 * 0: Do not enforce local layout
431 * >=1: Enforce local layout with version forcelocal
432 * -1: Enforce local layout with infinite version
433 * On reading, the forced local layout is only used if its version
434 * number is greater than the version number of the same layout in the
435 * document class. Otherwise, it is ignored.
441 /// Reads a layout definition from file
442 /// \return true on success.
443 bool readIgnoreForcelocal(support::Lexer &, TextClass const &, bool validating);
444 /// generates the default CSS for this layout
445 void makeDefaultCSS() const;
447 std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
449 std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
451 /// Name of the layout/paragraph environment
454 /// LaTeX name for environment
455 std::string latexname_;
457 /** Is this layout the default layout for an unknown layout? If
458 * so, its name will be displayed as xxx (unknown).
462 /** Name of an layout that has replaced this layout.
463 This is used to rename a layout, while keeping backward
466 docstring obsoleted_by_;
468 /** Name of an layout which preamble must come before this one
469 This is used when the preamble snippet uses macros defined in
472 docstring depends_on_;
474 /// Label string. "Abstract", "Reference", "Caption"...
475 docstring labelstring_;
477 docstring endlabelstring_;
478 /// Label string inside appendix. "Appendix", ...
479 docstring labelstring_appendix_;
480 /// LaTeX parameter for environment
481 std::string latexparam_;
482 /// Item command in lists
483 std::string itemcommand_;
484 /// Left delimiter of the content
485 docstring leftdelim_;
486 /// Right delimiter of the content
487 docstring rightdelim_;
488 /// Internal tag to use (e.g., <title></title> for sect header)
489 std::string innertag_;
490 /// Internal tag to use (e.g. to surround varentrylist label)
491 std::string labeltag_;
492 /// Internal tag to surround the item text in a list.
493 std::string itemtag_;
494 /// The interpretation of this tag varies depending upon the latextype.
495 /// In an environment, it is the tag enclosing all content for this set of
496 /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize,
497 /// it would be: ul. (You get the idea.)
499 /// For a command, it is the tag enclosing the content of the command.
500 /// So, for section, it might be: h2.
502 /// For the paragraph type, it is the tag that will enclose each paragraph.
504 /// Defaults to "div".
505 mutable std::string htmltag_;
506 /// Additional attributes for inclusion with the start tag.
507 /// Note that the CSS class is handled separately.
508 std::string htmlattr_;
509 /// The CSS class to use. Calculated from the layout name if not given.
510 mutable std::string htmlclass_;
512 mutable std::string htmlfullattrs_;
513 /// Tag for individual paragraphs in an environment. In lists, this
514 /// would be something like "li". But it also needs to be set for
515 /// quotation, e.g., since the paragraphs in a quote need to be
516 /// in "p" tags. Default is "div".
517 /// Note that when I said "environment", I meant it: This has no
518 /// effect for LATEX_PARAGRAPH type layouts.
519 mutable std::string htmlitemtag_;
520 /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
521 mutable std::string htmlitemattr_;
522 /// Tag for labels, of whatever sort. One use for this is in setting
523 /// descriptions, in which case it would be: dt. Another use is to
524 /// customize the display of, say, the auto-generated label for
525 /// sections. Defaults to "span".
526 /// If set to "NONE", this suppresses the printing of the label.
527 mutable std::string htmllabeltag_;
528 /// Attributes for the label. Defaults to: class="layoutname_label".
529 mutable std::string htmllabelattr_;
530 /// Whether to put the label before the item, or within the item.
531 /// I.e., do we have (true):
532 /// <label>...</label><item>...</item>
533 /// or instead (false):
534 /// <item><label>...</label>...</item>
535 /// The latter is the default.
536 bool htmllabelfirst_;
537 /// Is this to be output with the toc?
539 /// CSS information needed by this layout.
540 docstring htmlstyle_;
541 /// DocBook tag corresponding to this layout.
542 mutable std::string docbooktag_;
543 /// Roles to add to docbooktag_, if any (default: none).
544 mutable std::string docbookattr_;
545 /// DocBook tag type corresponding to this layout (block, paragraph, or inline; default: block).
546 mutable std::string docbooktagtype_;
547 /// DocBook inner tag corresponding to this layout.
548 mutable std::string docbookinnertag_;
549 /// Roles to add to docbookinnertag_, if any (default: none).
550 mutable std::string docbookinnerattr_;
551 /// DocBook inner-tag type corresponding to this layout (block, paragraph, or inline; default: block).
552 mutable std::string docbookinnertagtype_;
553 /// DocBook tag corresponding to this item (mainly for lists).
554 mutable std::string docbookitemtag_;
555 /// Roles to add to docbookitemtag_, if any (default: none).
556 mutable std::string docbookitemattr_;
557 /// DocBook tag type corresponding to this item (block, paragraph, or inline; default: block).
558 mutable std::string docbookitemtagtype_;
559 /// DocBook tag corresponding to the wrapper around an item (mainly for lists).
560 mutable std::string docbookitemwrappertag_;
561 /// Roles to add to docbookitemwrappertag_, if any (default: none).
562 mutable std::string docbookitemwrapperattr_;
563 /// DocBook tag type corresponding to the wrapper around an item (block, paragraph, or inline; default: block).
564 mutable std::string docbookitemwrappertagtype_;
565 /// DocBook tag corresponding to this label (mostly for description lists;
566 /// labels in the common sense do not exist with DocBook).
567 mutable std::string docbookitemlabeltag_;
568 /// Roles to add to docbooklabeltag_, if any (default: none).
569 mutable std::string docbookitemlabelattr_;
570 /// DocBook tag corresponding to this label (block, paragraph, or inline; default: block).
571 mutable std::string docbookitemlabeltagtype_;
572 /// DocBook tag to add within the item, around its direct content (mainly for lists).
573 mutable std::string docbookiteminnertag_;
574 /// Roles to add to docbookiteminnertag_, if any (default: none).
575 mutable std::string docbookiteminnerattr_;
576 /// DocBook tag to add within the item, around its direct content (block, paragraph, or inline; default: block).
577 mutable std::string docbookiteminnertagtype_;
578 /// DocBook tag corresponding to this wrapper around the main tag.
579 mutable std::string docbookwrappertag_;
580 /// Roles to add to docbookwrappertag_, if any (default: none).
581 mutable std::string docbookwrapperattr_;
582 /// DocBook tag corresponding to this wrapper around the main tag (block, paragraph, or inline; default: block).
583 mutable std::string docbookwrappertagtype_;
584 /// Whether this wrapper tag may be merged with the previously opened wrapper tag.
585 bool docbookwrappermergewithprevious_;
586 /// Outer tag for this section, only if this layout represent a sectionning item, including chapters
587 /// (default: section).
588 mutable std::string docbooksectiontag_;
589 /// Whether this element should be considered as a section-level element in DocBook.
590 bool docbooksection_;
591 /// Whether this tag must/can/can't go into an <info> tag (default: never, as it only makes sense for metadata).
592 mutable std::string docbookininfo_;
593 /// Whether this paragraph should be considered as abstract. Such paragraphs are output as a part of the document
594 /// abstract element (corresponding to the root tag).
595 bool docbookabstract_;
596 /// Whether this element (root or not) does not accept text without a section (i.e. the first text that is met
597 /// in LyX must be considered as the abstract if this is true); this text must be output with the specific tag
598 /// held by this attribute.
599 mutable std::string docbookforceabstracttag_;
600 /// Whether font tags are allowed inside this tag.
601 bool docbooknofontinside_ = false;
602 /// Whether LyX should create a title on its own, just after the wrapper tag. Typically, this parameter is required
603 /// because the wrapper tag requires a title (like a figure). The generated title will be similar to a LyXHTML label
604 /// (environment type and a number).
605 bool docbookgeneratetitle_ = false;
606 /// Should we generate the default CSS for this layout, even if HTMLStyle
607 /// has been given? Default is false.
608 /// Note that the default CSS is output first, then the user CSS, so it is
609 /// possible to override what one does not want.
611 /// A cache for the default style info so generated.
612 mutable docstring htmldefaultstyle_;
613 /// Any other info for the HTML header.
614 docstring htmlpreamble_;
615 /// Whether this is the <title> paragraph.
617 /// calculating this is expensive, so we cache it.
618 mutable std::string defaultcssclass_;
619 /// This is the `category' for this layout. The following are
620 /// recommended basic categories: FrontMatter, BackMatter, MainText,
621 /// Sectioning, Starred, List, Reasoning.
623 /// Macro definitions needed for this layout
625 /// Language dependent macro definitions needed for this layout
626 docstring langpreamble_;
627 /// Language and babel dependent macro definitions needed for this layout
628 docstring babelpreamble_;
629 /// Are adjacent paragraphs handled as one group?
631 /// Packages needed for this layout
632 std::set<std::string> required_;
633 /// Layouts that are by default nested after this one
634 std::set<docstring> autonests_;
635 /// Layouts that by auto-nest this one
636 std::set<docstring> autonested_by_;
638 LaTeXArgMap latexargs_;
640 LaTeXArgMap postcommandargs_;
642 LaTeXArgMap listpreamble_;
644 LaTeXArgMap itemargs_;
648 std::string toc_type_;
650 bool is_toc_caption_;