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;
390 /// Individual characters that must not be
391 /// passed verbatim even if normally requested
392 docstring no_pass_thru_chars;
394 bool parbreak_is_newline;
397 /// special value of toclevel for non-section layouts
398 static const int NOT_IN_TOC;
400 /** true when the fragile commands in the paragraph need to be
403 /** true when the verbatim stuff of this layout needs to be
406 /** true when the verbatim stuff of this layout never should be
409 /** true when specific commands in this paragraph need to be
410 protected in an \mbox. */
411 bool needmboxprotect;
412 /// true when empty paragraphs should be kept.
414 /// Type of LaTeX object
416 /// Does this object belong in the title part of the document?
418 /// Is the content to go in the preamble rather than the body?
420 /// Which counter to step
424 /// Step parent counter?
425 bool stepparentcounter;
426 /// Prefix to use when creating labels
428 /// Depth of XML command
431 /// Is this spellchecked?
434 * Should this layout definition always be written to the document preamble?
435 * Possible values are:
436 * 0: Do not enforce local layout
437 * >=1: Enforce local layout with version forcelocal
438 * -1: Enforce local layout with infinite version
439 * On reading, the forced local layout is only used if its version
440 * number is greater than the version number of the same layout in the
441 * document class. Otherwise, it is ignored.
447 /// Reads a layout definition from file
448 /// \return true on success.
449 bool readIgnoreForcelocal(support::Lexer &, TextClass const &, bool validating);
450 /// generates the default CSS for this layout
451 void makeDefaultCSS() const;
453 std::string defaultCSSItemClass() const { return defaultCSSClass() + "_item"; }
455 std::string defaultCSSLabelClass() const { return defaultCSSClass() + "_label"; }
457 /// Name of the layout/paragraph environment
460 /// LaTeX name for environment
461 std::string latexname_;
463 /** Is this layout the default layout for an unknown layout? If
464 * so, its name will be displayed as xxx (unknown).
468 /** Name of an layout that has replaced this layout.
469 This is used to rename a layout, while keeping backward
472 docstring obsoleted_by_;
474 /** Name of an layout which preamble must come before this one
475 This is used when the preamble snippet uses macros defined in
478 docstring depends_on_;
480 /// Label string. "Abstract", "Reference", "Caption"...
481 docstring labelstring_;
483 docstring endlabelstring_;
484 /// Label string inside appendix. "Appendix", ...
485 docstring labelstring_appendix_;
486 /// LaTeX parameter for environment
487 std::string latexparam_;
488 /// Item command in lists
489 std::string itemcommand_;
490 /// Left delimiter of the content
491 docstring leftdelim_;
492 /// Right delimiter of the content
493 docstring rightdelim_;
494 /// Internal tag to use (e.g., <title></title> for sect header)
495 std::string innertag_;
496 /// Internal tag to use (e.g. to surround varentrylist label)
497 std::string labeltag_;
498 /// Internal tag to surround the item text in a list.
499 std::string itemtag_;
500 /// The interpretation of this tag varies depending upon the latextype.
501 /// In an environment, it is the tag enclosing all content for this set of
502 /// paragraphs. So for quote, e.g,. it would be: blockquote. For itemize,
503 /// it would be: ul. (You get the idea.)
505 /// For a command, it is the tag enclosing the content of the command.
506 /// So, for section, it might be: h2.
508 /// For the paragraph type, it is the tag that will enclose each paragraph.
510 /// Defaults to "div".
511 mutable std::string htmltag_;
512 /// Additional attributes for inclusion with the start tag.
513 /// Note that the CSS class is handled separately.
514 std::string htmlattr_;
515 /// The CSS class to use. Calculated from the layout name if not given.
516 mutable std::string htmlclass_;
518 mutable std::string htmlfullattrs_;
519 /// Tag for individual paragraphs in an environment. In lists, this
520 /// would be something like "li". But it also needs to be set for
521 /// quotation, e.g., since the paragraphs in a quote need to be
522 /// in "p" tags. Default is "div".
523 /// Note that when I said "environment", I meant it: This has no
524 /// effect for LATEX_PARAGRAPH type layouts.
525 mutable std::string htmlitemtag_;
526 /// Attributes for htmlitemtag_. Default is: class="layoutname_item".
527 mutable std::string htmlitemattr_;
528 /// Tag for labels, of whatever sort. One use for this is in setting
529 /// descriptions, in which case it would be: dt. Another use is to
530 /// customize the display of, say, the auto-generated label for
531 /// sections. Defaults to "span".
532 /// If set to "NONE", this suppresses the printing of the label.
533 mutable std::string htmllabeltag_;
534 /// Attributes for the label. Defaults to: class="layoutname_label".
535 mutable std::string htmllabelattr_;
536 /// Whether to put the label before the item, or within the item.
537 /// I.e., do we have (true):
538 /// <label>...</label><item>...</item>
539 /// or instead (false):
540 /// <item><label>...</label>...</item>
541 /// The latter is the default.
542 bool htmllabelfirst_;
543 /// Is this to be output with the toc?
545 /// CSS information needed by this layout.
546 docstring htmlstyle_;
547 /// DocBook tag corresponding to this layout.
548 mutable std::string docbooktag_;
549 /// Roles to add to docbooktag_, if any (default: none).
550 mutable std::string docbookattr_;
551 /// DocBook tag type corresponding to this layout (block, paragraph, or inline; default: block).
552 mutable std::string docbooktagtype_;
553 /// DocBook inner tag corresponding to this layout.
554 mutable std::string docbookinnertag_;
555 /// Roles to add to docbookinnertag_, if any (default: none).
556 mutable std::string docbookinnerattr_;
557 /// DocBook inner-tag type corresponding to this layout (block, paragraph, or inline; default: block).
558 mutable std::string docbookinnertagtype_;
559 /// DocBook tag corresponding to this item (mainly for lists).
560 mutable std::string docbookitemtag_;
561 /// Roles to add to docbookitemtag_, if any (default: none).
562 mutable std::string docbookitemattr_;
563 /// DocBook tag type corresponding to this item (block, paragraph, or inline; default: block).
564 mutable std::string docbookitemtagtype_;
565 /// DocBook tag corresponding to the wrapper around an item (mainly for lists).
566 mutable std::string docbookitemwrappertag_;
567 /// Roles to add to docbookitemwrappertag_, if any (default: none).
568 mutable std::string docbookitemwrapperattr_;
569 /// DocBook tag type corresponding to the wrapper around an item (block, paragraph, or inline; default: block).
570 mutable std::string docbookitemwrappertagtype_;
571 /// DocBook tag corresponding to this label (mostly for description lists;
572 /// labels in the common sense do not exist with DocBook).
573 mutable std::string docbookitemlabeltag_;
574 /// Roles to add to docbooklabeltag_, if any (default: none).
575 mutable std::string docbookitemlabelattr_;
576 /// DocBook tag corresponding to this label (block, paragraph, or inline; default: block).
577 mutable std::string docbookitemlabeltagtype_;
578 /// DocBook tag to add within the item, around its direct content (mainly for lists).
579 mutable std::string docbookiteminnertag_;
580 /// Roles to add to docbookiteminnertag_, if any (default: none).
581 mutable std::string docbookiteminnerattr_;
582 /// DocBook tag to add within the item, around its direct content (block, paragraph, or inline; default: block).
583 mutable std::string docbookiteminnertagtype_;
584 /// DocBook tag corresponding to this wrapper around the main tag.
585 mutable std::string docbookwrappertag_;
586 /// Roles to add to docbookwrappertag_, if any (default: none).
587 mutable std::string docbookwrapperattr_;
588 /// DocBook tag corresponding to this wrapper around the main tag (block, paragraph, or inline; default: block).
589 mutable std::string docbookwrappertagtype_;
590 /// Whether this wrapper tag may be merged with the previously opened wrapper tag.
591 bool docbookwrappermergewithprevious_;
592 /// Outer tag for this section, only if this layout represent a sectionning item, including chapters
593 /// (default: section).
594 mutable std::string docbooksectiontag_;
595 /// Whether this element should be considered as a section-level element in DocBook.
596 bool docbooksection_;
597 /// Whether this tag must/can/can't go into an <info> tag (default: never, as it only makes sense for metadata).
598 mutable std::string docbookininfo_;
599 /// Whether this paragraph should be considered as abstract. Such paragraphs are output as a part of the document
600 /// abstract element (corresponding to the root tag).
601 bool docbookabstract_;
602 /// Whether this element (root or not) does not accept text without a section (i.e. the first text that is met
603 /// in LyX must be considered as the abstract if this is true); this text must be output with the specific tag
604 /// held by this attribute.
605 mutable std::string docbookforceabstracttag_;
606 /// Whether font tags are allowed inside this tag.
607 bool docbooknofontinside_ = false;
608 /// Whether LyX should create a title on its own, just after the wrapper tag. Typically, this parameter is required
609 /// because the wrapper tag requires a title (like a figure). The generated title will be similar to a LyXHTML label
610 /// (environment type and a number).
611 bool docbookgeneratetitle_ = false;
612 /// Should we generate the default CSS for this layout, even if HTMLStyle
613 /// has been given? Default is false.
614 /// Note that the default CSS is output first, then the user CSS, so it is
615 /// possible to override what one does not want.
617 /// A cache for the default style info so generated.
618 mutable docstring htmldefaultstyle_;
619 /// Any other info for the HTML header.
620 docstring htmlpreamble_;
621 /// Whether this is the <title> paragraph.
623 /// calculating this is expensive, so we cache it.
624 mutable std::string defaultcssclass_;
625 /// This is the `category' for this layout. The following are
626 /// recommended basic categories: FrontMatter, BackMatter, MainText,
627 /// Sectioning, Starred, List, Reasoning.
629 /// Macro definitions needed for this layout
631 /// Language dependent macro definitions needed for this layout
632 docstring langpreamble_;
633 /// Language and babel dependent macro definitions needed for this layout
634 docstring babelpreamble_;
635 /// Are adjacent paragraphs handled as one group?
637 /// Packages needed for this layout
638 std::set<std::string> required_;
639 /// Layouts that are by default nested after this one
640 std::set<docstring> autonests_;
641 /// Layouts that by auto-nest this one
642 std::set<docstring> autonested_by_;
644 LaTeXArgMap latexargs_;
646 LaTeXArgMap postcommandargs_;
648 LaTeXArgMap listpreamble_;
650 LaTeXArgMap itemargs_;
654 std::string toc_type_;
656 bool is_toc_caption_;