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
10 * \author André Pönitz
12 * Full author contact details are available in file CREDITS.
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
19 #include "ColorCode.h"
21 #include "DocumentClassPtr.h"
22 #include "LayoutModuleList.h"
24 #include "WordLangTuple.h"
26 #include "support/copied_ptr.h"
27 #include "support/types.h"
52 class LayoutFileIndex;
60 enum class Flavor : int;
61 enum class QuoteStyle : int;
63 /** Buffer parameters.
64 * This class contains all the parameters for this buffer's use. Some
65 * work needs to be done on this class to make it nice. Now everything
71 enum ParagraphSeparation {
73 ParagraphIndentSeparation,
75 ParagraphSkipSeparation
80 /// get l10n translated to the buffers language
81 docstring B_(std::string const & l10n) const;
83 /// read a header token, if unrecognised, return it or an unknown class name
84 std::string readToken(support::Lexer & lex,
85 std::string const & token, ///< token to read.
86 support::FileName const & filename);
89 void writeFile(std::ostream &, Buffer const *) const;
91 /// check what features are implied by the buffer parameters.
92 void validate(LaTeXFeatures &) const;
94 /** \returns true if the babel package is used (interrogates
95 * the BufferParams, a LyXRC variable, and the document class).
96 * This returned value can then be passed to the insets...
98 bool writeLaTeX(otexstream &, LaTeXFeatures &,
99 support::FileName const &) const;
102 void useClassDefaults();
104 bool hasClassDefaults() const;
107 Length const & getParIndent() const;
109 void setParIndent(Length const & indent);
111 VSpace const & getDefSkip() const;
113 void setDefSkip(VSpace const & vs);
116 Length const & getMathIndent() const;
118 void setMathIndent(Length const & indent);
120 /// Whether formulas are indented
124 enum MathNumber { DEFAULT, LEFT, RIGHT };
125 /// number formulas on left/right/default
126 MathNumber math_numbering_side;
128 /// Convenience function for display: like math_number, but
129 /// DEFAULT is replaced by the best guess we have.
130 MathNumber getMathNumber() const;
132 /** Whether paragraphs are separated by using a indent like in
133 * articles or by using a little skip like in letters.
135 ParagraphSeparation paragraph_separation;
137 QuoteStyle quotes_style;
141 std::string fontsize;
142 /// Get the LayoutFile this document is using.
143 LayoutFile const * baseClass() const;
145 LayoutFileIndex const & baseClassID() const;
146 /// Set the LyX layout file this document is using.
147 /// NOTE: This does not call makeDocumentClass() to update the local
148 /// DocumentClass. That needs to be done manually.
149 /// \param classname: the name of the layout file
150 /// \param path: non-empty only for local layout files
151 bool setBaseClass(std::string const & classname,
152 std::string const & path = std::string());
153 /// Adds the module information to the baseClass information to
154 /// create our local DocumentClass.
155 /// NOTE: This should NEVER be called externally unless one immediately goes
156 /// on to class BufferView::updateDocumentClass(). The exception, of course,
157 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
158 /// the parameters from the active Buffer.
159 void makeDocumentClass(bool clone = false, bool internal = false);
160 /// Returns the DocumentClass currently in use: the BaseClass as modified
162 DocumentClass const & documentClass() const;
163 /// \return A pointer to the DocumentClass currently in use: the BaseClass
164 /// as modified by modules.
165 DocumentClassConstPtr documentClassPtr() const;
166 /// This bypasses the baseClass and sets the textClass directly.
167 /// Should be called with care and would be better not being here,
168 /// but it seems to be needed by CutAndPaste::putClipboard().
169 void setDocumentClass(DocumentClassConstPtr);
170 /// List of modules in use
171 LayoutModuleList const & getModules() const { return layout_modules_; }
172 /// List of default modules the user has removed
173 std::list<std::string> const & getRemovedModules() const
174 { return removed_modules_; }
176 /// Add a module to the list of modules in use. This checks only that the
177 /// module is not already in the list, so use layoutModuleCanBeAdeed first
178 /// if you want to check for compatibility.
179 /// \return true if module was successfully added.
180 bool addLayoutModule(std::string const & modName);
181 /// checks to make sure module's requriements are satisfied, that it does
182 /// not conflict with already-present modules, isn't already loaded, etc.
183 bool layoutModuleCanBeAdded(std::string const & modName) const;
185 void addRemovedModule(std::string const & modName)
186 { removed_modules_.push_back(modName); }
188 void clearLayoutModules() { layout_modules_.clear(); }
189 /// Clear the removed module list
190 void clearRemovedModules() { removed_modules_.clear(); }
191 /// Get the local layouts
192 docstring getLocalLayout(bool forced) const;
193 /// Set the local layouts
194 void setLocalLayout(docstring const & layout, bool forced);
196 /// returns \c true if the buffer contains a LaTeX document
197 bool isLatex() const;
198 /// returns \c true if the buffer contains a Wed document
199 bool isLiterate() const;
200 /// Is this package option requested?
201 bool hasPackageOption(std::string const package, std::string const opt) const;
202 /// Get the options requested for a given package
203 std::string getPackageOptions(std::string const package) const;
204 /// Do we use the bidi package (which does some reordering and stuff)?
205 bool useBidiPackage(OutputParams const & rp) const;
207 /// return the format of the buffer on a string
208 std::string bufferFormat() const;
209 /// return the default output format of the current backend
210 std::string getDefaultOutputFormat() const;
211 /// return the output flavor of \p format or the default
212 Flavor getOutputFlavor(std::string const & format = std::string()) const;
214 bool isExportable(std::string const & format, bool need_viewable) const;
216 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
217 /// the backends appropriate for use with this document.
218 /// so, e.g., latex is excluded , if we're using non-TeX fonts
219 std::vector<std::string> backends() const;
221 /// List of included children (for includeonly)
222 std::list<std::string> const & getIncludedChildren() const
223 { return included_children_; }
225 void addIncludedChildren(std::string const & child)
226 { included_children_.push_back(child); }
227 /// Clear the list of included children
228 void clearIncludedChildren() { included_children_.clear(); }
230 /// update aux files of unincluded children (with \includeonly)
231 enum ChildrenMaintenance {
236 ChildrenMaintenance maintain_unincluded_children;
238 /// returns the main font for the buffer (document)
239 Font const getFont() const;
241 /// translate quote style string to enum value
242 QuoteStyle getQuoteStyle(std::string const & qs) const;
244 /* these are for the PaperLayout */
246 PAPER_SIZE papersize;
248 PAPER_ORIENTATION orientation;
249 /// use custom margins
252 std::string paperwidth;
254 std::string paperheight;
256 std::string leftmargin;
258 std::string topmargin;
260 std::string rightmargin;
262 std::string bottommargin;
264 std::string headheight;
268 std::string footskip;
270 std::string columnsep;
272 /* some LaTeX options */
273 /// The graphics driver
274 std::string graphics_driver;
275 /// The default output format
276 std::string default_output_format;
277 /// customized bibliography processor
278 std::string bibtex_command;
279 /// customized index processor
280 std::string index_command;
281 /// font encoding(s) requested for this document
283 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
284 std::string fonts_roman[2];
286 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
287 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
288 std::string fonts_sans[2];
290 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
291 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
292 std::string fonts_typewriter[2];
294 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
295 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
296 std::string fonts_math[2];
298 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
299 /// the default family (rm, sf, tt)
300 std::string fonts_default_family;
301 /// use the fonts of the OS (OpenType, True Type) directly
303 /// use expert Small Caps
304 bool fonts_expert_sc;
305 /// use Old Style Figures (rm)
306 bool fonts_roman_osf;
307 /// use Old Style Figures (sf)
309 /// use Old Style Figures (tt)
310 bool fonts_typewriter_osf;
311 /// the options for the roman font
312 std::string font_roman_opts;
313 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
314 int fonts_sans_scale[2];
315 /// the scale factor of the sf font
316 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
317 // the options for the sans font
318 std::string font_sans_opts;
319 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
320 int fonts_typewriter_scale[2];
321 /// the scale factor of the tt font
322 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
323 // the options for the typewriter font
324 std::string font_typewriter_opts;
325 /// the font used by the CJK command
326 std::string fonts_cjk;
327 /// use LaTeX microtype package
329 /// use font ligatures for en- and em-dashes
330 bool use_dash_ligatures;
333 Spacing const & spacing() const;
339 Language const * language;
341 std::string lang_package;
343 BranchList & branchlist();
344 BranchList const & branchlist() const;
346 IndicesList & indiceslist();
347 IndicesList const & indiceslist() const;
349 WordLangTable & spellignore();
350 WordLangTable const & spellignore() const;
351 bool spellignored(WordLangTuple const & wl) const;
353 * The LyX name of the input encoding for LaTeX. This can be one of
354 * - \c auto: find out the input encoding from the used languages
355 * - \c default: ditto
356 * - any encoding defined in the file lib/encodings
357 * The encoding of the LyX file is always utf8 and has nothing to
358 * do with this setting.
359 * The difference between \c auto and \c default is that \c auto also
360 * causes loading of the inputenc package and writes a \inputenc{} command
361 * to the file when switching to another encoding, while \c default does not.
362 * \c default will not work unless the user takes additional measures
363 * (such as using special environments like the CJK environment from
365 * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
366 * does not interpret it in any way apart from display on screen.
368 std::string inputenc;
369 /// The main encoding used by this buffer for LaTeX output.
370 /// If the main encoding is \c auto or \c default,
371 /// individual pieces of text can use different encodings.
372 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
373 /// instead of the value returned by this function (cf. #10600).
374 Encoding const & encoding() const;
379 /// DocumentMetadata as introduced by LaTeX 2022/06
380 docstring document_metadata;
383 /// use the class options defined in the layout?
384 bool use_default_options;
390 std::string float_placement;
392 std::string float_alignment;
394 unsigned int columns;
397 /// parameters for the listings package
398 std::string listings_params;
402 std::string pagestyle;
404 std::string tablestyle;
406 RGBColor backgroundcolor;
408 bool isbackgroundcolor;
414 RGBColor notefontcolor;
416 bool isnotefontcolor;
421 /// \param index should lie in the range 0 <= \c index <= 3.
422 Bullet & temp_bullet(size_type index);
423 Bullet const & temp_bullet(size_type index) const;
424 /// \param index should lie in the range 0 <= \c index <= 3.
425 Bullet & user_defined_bullet(size_type index);
426 Bullet const & user_defined_bullet(size_type index) const;
428 /// Whether to load a package such as amsmath or esint.
429 /// The enum values must not be changed (file format!)
431 /// Don't load the package. For experts only.
433 /// Load the package if needed (recommended)
435 /// Always load the package (e.g. if the document contains
436 /// some ERT that needs the package)
439 /// Whether to load a package such as amsmath or esint.
440 Package use_package(std::string const & p) const;
441 /// Set whether to load a package such as amsmath or esint.
442 void use_package(std::string const & p, Package u);
443 /// All packages that can be switched on or off
444 static std::map<std::string, std::string> const & auto_packages();
445 /// Do we use the bibtopic package?
446 bool useBibtopic() const;
447 /// Split bibliography?
448 bool splitbib() const { return use_bibtopic; }
449 /// Set split bibliography
450 void splitbib(bool const b) { use_bibtopic = b; }
451 /// Do we have multiple bibliographies (by chapter etc.)?
452 std::string multibib;
455 /// Save transient properties?
456 bool save_transient_properties;
457 /// revision tracking for this buffer ? (this is a transient property)
459 /** This param decides whether change tracking marks should be used
460 * in output (irrespective of how these marks are actually defined;
461 * for instance, they may differ for DVI and PDF generation)
462 * This is a transient property.
470 bool postpone_fragile_content;
472 /// the author list for the document
473 AuthorList & authors();
474 AuthorList const & authors() const;
475 void addAuthor(Author const & a);
477 /// map of the file's author IDs to AuthorList indexes
478 typedef std::map<int, int> AuthorMap;
479 AuthorMap author_map_;
481 /// the buffer's active font encoding
482 std::string const main_font_encoding() const;
483 /// all font encodings requested by the prefs/document/main language.
484 /// This does NOT include font encodings required by secondary languages
485 std::vector<std::string> const font_encodings() const;
488 std::string const dvips_options() const;
489 /** The return value of paperSizeName() depends on the
490 * purpose for which the paper size is needed, since they
491 * support different subsets of paper sizes.
493 enum PapersizePurpose {
502 std::string paperSizeName(PapersizePurpose purpose,
503 std::string const & psize = std::string()) const;
504 /// set up if and how babel is called
505 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
506 /// return supported drivers for specific packages
507 docstring getGraphicsDriver(std::string const & package) const;
508 /// handle inputenc etc.
509 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
511 std::string const parseFontName(std::string const & name) const;
512 /// set up the document fonts
513 std::string const loadFonts(LaTeXFeatures & features) const;
515 /// the cite engine modules
516 std::string const & citeEngine() const { return cite_engine_; }
517 /// the type of cite engine (authoryear or numerical)
518 CiteEngineType const & citeEngineType() const
519 { return cite_engine_type_; }
520 /// add the module to the cite engine modules
521 void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
522 /// set the cite engine type
523 void setCiteEngineType(CiteEngineType const & engine_type)
524 { cite_engine_type_ = engine_type; }
526 /// the available citation commands
527 std::vector<std::string> citeCommands() const;
528 /// the available citation styles
529 std::vector<CitationStyle> citeStyles() const;
531 /// Return the actual bibtex command (lyxrc or buffer param)
532 std::string const bibtexCommand(bool const warn = false) const;
534 /// Are we using biblatex?
535 bool useBiblatex() const;
537 /// Set the default BibTeX style file for the document
538 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
539 /// Get the default BibTeX style file from the TextClass
540 std::string const & defaultBiblioStyle() const;
541 /// whether the BibTeX style supports full author lists
542 bool fullAuthorList() const;
543 /// Check if a citation style is an alias to another style
544 std::string getCiteAlias(std::string const & s) const;
546 /// Options of the bibiography package
547 std::string biblio_opts;
548 /// The biblatex bibliography style
549 std::string biblatex_bibstyle;
550 /// The biblatex citation style
551 std::string biblatex_citestyle;
552 /// Set the bib file encoding (for biblatex)
553 void setBibEncoding(std::string const & s) { bib_encoding = s; }
554 /// Get the bib file encoding (for biblatex)
555 std::string const & bibEncoding() const { return bib_encoding; }
556 /// Set encoding for individual bib file (for biblatex)
557 void setBibFileEncoding(std::string const & file, std::string const & enc);
559 std::string const bibFileEncoding(std::string const & file) const;
561 /// options for pdf output
562 PDFOptions & pdfoptions();
563 PDFOptions const & pdfoptions() const;
565 // do not change these values. we rely upon them.
572 /// what to use for math output. present choices are above
573 MathOutput html_math_output;
574 /// whether to attempt to be XHTML 1.1 compliant or instead be
575 /// a little more mellow
578 double html_math_img_scale;
580 double display_pixel_ratio;
582 std::string html_latex_start;
584 std::string html_latex_end;
586 bool html_css_as_file;
588 // do not change these values. we rely upon them.
593 /// what format to use for table output in DocBook. present choices are above
594 TableOutput docbook_table_output;
596 // do not change these values. we rely upon them.
597 enum MathMLNameSpacePrefix {
602 /// what prefix to use when outputting MathML. present choices are above
603 MathMLNameSpacePrefix docbook_mathml_prefix;
605 /// allow the LaTeX backend to run external programs
607 /// generate output usable for reverse/forward search
609 /// custom LaTeX macro from user instead our own
610 std::string output_sync_macro;
611 /// use refstyle? or prettyref?
613 /// use formatted references in the workarea?
614 bool use_formatted_ref;
615 /// use minted? or listings?
617 //output line numbering
619 //optional params for lineno package
620 std::string lineno_opts;
622 /// Return true if language could be set to lang,
623 /// otherwise return false and do not change language
624 bool setLanguage(std::string const & lang);
626 void invalidateConverterCache() const;
627 /// Copies over some of the settings from \param bp,
628 /// namely the ones need by Advanced F&R. We don't want
629 /// to copy them all, e.g., not the default master.
630 void copyForAdvFR(BufferParams const & bp);
634 void readPreamble(support::Lexer &);
636 void readDocumentMetadata(support::Lexer &);
638 void readLocalLayout(support::Lexer &, bool);
640 void readLanguage(support::Lexer &);
642 void readGraphicsDriver(support::Lexer &);
644 void readBullets(support::Lexer &);
646 void readBulletsLaTeX(support::Lexer &);
648 void readModules(support::Lexer &);
650 void readRemovedModules(support::Lexer &);
652 void readIncludeonly(support::Lexer &);
653 /// A cache for the default flavors
654 typedef std::map<std::string, Flavor> DefaultFlavorCache;
656 mutable DefaultFlavorCache default_flavors_;
658 std::string cite_engine_;
659 /// the type of cite engine (authoryear or numerical)
660 CiteEngineType cite_engine_type_;
661 /// the default BibTeX style file for the document
662 std::string biblio_style;
663 /// The main encoding of the bib files, for Biblatex
664 std::string bib_encoding;
665 /// Individual file encodings, for Biblatex
666 std::map<std::string, std::string> bib_encodings;
667 /// Split bibliography?
669 /// Return the actual or an appropriate fallback bibtex command
670 std::string const getBibtexCommand(std::string const cmd,
671 bool const warn) const;
673 DocumentClassPtr doc_class_;
675 LayoutModuleList layout_modules_;
676 /// this is for modules that are required by the document class but that
677 /// the user has chosen not to use
678 std::list<std::string> removed_modules_;
679 /// The local layouts without the forced ones
680 docstring local_layout_;
681 /// Forced local layouts only for reading (use getLocalLayout() instead)
682 docstring forced_local_layout_;
684 /// the list of included children (for includeonly)
685 std::list<std::string> included_children_;
687 typedef std::map<std::string, Package> PackageMap;
688 /** Whether and how to load packages like amsmath, esint, mhchem,
689 * mathdots, stackrel, stmaryrd and undertilde.
691 PackageMap use_packages;
693 /** Use the Pimpl idiom to hide those member variables that would otherwise
694 * drag in other header files.
699 static Impl * clone(Impl const *);
700 static void destroy(Impl *);
702 support::copied_ptr<Impl, MemoryTraits> pimpl_;
707 BufferParams const & defaultBufferParams();