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"
25 #include "support/copied_ptr.h"
26 #include "support/types.h"
33 namespace support { class FileName; }
48 class LayoutFileIndex;
56 enum class Flavor : int;
57 enum class QuoteStyle : int;
59 /** Buffer parameters.
60 * This class contains all the parameters for this buffer's use. Some
61 * work needs to be done on this class to make it nice. Now everything
67 enum ParagraphSeparation {
69 ParagraphIndentSeparation,
71 ParagraphSkipSeparation
76 /// get l10n translated to the buffers language
77 docstring B_(std::string const & l10n) const;
79 /// read a header token, if unrecognised, return it or an unknown class name
80 std::string readToken(Lexer & lex,
81 std::string const & token, ///< token to read.
82 support::FileName const & filename);
85 void writeFile(std::ostream &, Buffer const *) const;
87 /// check what features are implied by the buffer parameters.
88 void validate(LaTeXFeatures &) const;
90 /** \returns true if the babel package is used (interrogates
91 * the BufferParams, a LyXRC variable, and the document class).
92 * This returned value can then be passed to the insets...
94 bool writeLaTeX(otexstream &, LaTeXFeatures &,
95 support::FileName const &) const;
98 void useClassDefaults();
100 bool hasClassDefaults() const;
103 Length const & getParIndent() const;
105 void setParIndent(Length const & indent);
107 VSpace const & getDefSkip() const;
109 void setDefSkip(VSpace const & vs);
112 Length const & getMathIndent() const;
114 void setMathIndent(Length const & indent);
116 /// Whether formulas are indented
120 enum MathNumber { DEFAULT, LEFT, RIGHT };
121 /// number formulas on left/right/default
122 MathNumber math_numbering_side;
124 /// Convenience function for display: like math_number, but
125 /// DEFAULT is replaced by the best guess we have.
126 MathNumber getMathNumber() const;
128 /** Whether paragraphs are separated by using a indent like in
129 * articles or by using a little skip like in letters.
131 ParagraphSeparation paragraph_separation;
133 QuoteStyle quotes_style;
137 std::string fontsize;
138 /// Get the LayoutFile this document is using.
139 LayoutFile const * baseClass() const;
141 LayoutFileIndex const & baseClassID() const;
142 /// Set the LyX layout file this document is using.
143 /// NOTE: This does not call makeDocumentClass() to update the local
144 /// DocumentClass. That needs to be done manually.
145 /// \param classname: the name of the layout file
146 /// \param path: non-empty only for local layout files
147 bool setBaseClass(std::string const & classname,
148 std::string const & path = std::string());
149 /// Adds the module information to the baseClass information to
150 /// create our local DocumentClass.
151 /// NOTE: This should NEVER be called externally unless one immediately goes
152 /// on to class BufferView::updateDocumentClass(). The exception, of course,
153 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
154 /// the parameters from the active Buffer.
155 void makeDocumentClass(bool clone = false, bool internal = false);
156 /// Returns the DocumentClass currently in use: the BaseClass as modified
158 DocumentClass const & documentClass() const;
159 /// \return A pointer to the DocumentClass currently in use: the BaseClass
160 /// as modified by modules.
161 DocumentClassConstPtr documentClassPtr() const;
162 /// This bypasses the baseClass and sets the textClass directly.
163 /// Should be called with care and would be better not being here,
164 /// but it seems to be needed by CutAndPaste::putClipboard().
165 void setDocumentClass(DocumentClassConstPtr);
166 /// List of modules in use
167 LayoutModuleList const & getModules() const { return layout_modules_; }
168 /// List of default modules the user has removed
169 std::list<std::string> const & getRemovedModules() const
170 { return removed_modules_; }
172 /// Add a module to the list of modules in use. This checks only that the
173 /// module is not already in the list, so use layoutModuleCanBeAdeed first
174 /// if you want to check for compatibility.
175 /// \return true if module was successfully added.
176 bool addLayoutModule(std::string const & modName);
177 /// checks to make sure module's requriements are satisfied, that it does
178 /// not conflict with already-present modules, isn't already loaded, etc.
179 bool layoutModuleCanBeAdded(std::string const & modName) const;
181 void addRemovedModule(std::string const & modName)
182 { removed_modules_.push_back(modName); }
184 void clearLayoutModules() { layout_modules_.clear(); }
185 /// Clear the removed module list
186 void clearRemovedModules() { removed_modules_.clear(); }
187 /// Get the local layouts
188 docstring getLocalLayout(bool forced) const;
189 /// Set the local layouts
190 void setLocalLayout(docstring const & layout, bool forced);
192 /// returns \c true if the buffer contains a LaTeX document
193 bool isLatex() const;
194 /// returns \c true if the buffer contains a Wed document
195 bool isLiterate() const;
197 /// return the format of the buffer on a string
198 std::string bufferFormat() const;
199 /// return the default output format of the current backend
200 std::string getDefaultOutputFormat() const;
201 /// return the output flavor of \p format or the default
202 Flavor getOutputFlavor(std::string const & format = std::string()) const;
204 bool isExportable(std::string const & format, bool need_viewable) const;
206 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
207 /// the backends appropriate for use with this document.
208 /// so, e.g., latex is excluded , if we're using non-TeX fonts
209 std::vector<std::string> backends() const;
211 /// List of included children (for includeonly)
212 std::list<std::string> const & getIncludedChildren() const
213 { return included_children_; }
215 void addIncludedChildren(std::string const & child)
216 { included_children_.push_back(child); }
217 /// Clear the list of included children
218 void clearIncludedChildren() { included_children_.clear(); }
220 /// update aux files of unincluded children (with \includeonly)
221 enum ChildrenMaintenance {
226 ChildrenMaintenance maintain_unincluded_children;
228 /// returns the main font for the buffer (document)
229 Font const getFont() const;
231 /// translate quote style string to enum value
232 QuoteStyle getQuoteStyle(std::string const & qs) const;
234 /* these are for the PaperLayout */
236 PAPER_SIZE papersize;
238 PAPER_ORIENTATION orientation;
239 /// use custom margins
242 std::string paperwidth;
244 std::string paperheight;
246 std::string leftmargin;
248 std::string topmargin;
250 std::string rightmargin;
252 std::string bottommargin;
254 std::string headheight;
258 std::string footskip;
260 std::string columnsep;
262 /* some LaTeX options */
263 /// The graphics driver
264 std::string graphics_driver;
265 /// The default output format
266 std::string default_output_format;
267 /// customized bibliography processor
268 std::string bibtex_command;
269 /// customized index processor
270 std::string index_command;
271 /// font encoding(s) requested for this document
273 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
274 std::string fonts_roman[2];
276 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
277 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
278 std::string fonts_sans[2];
280 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
281 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
282 std::string fonts_typewriter[2];
284 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
285 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
286 std::string fonts_math[2];
288 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
289 /// the default family (rm, sf, tt)
290 std::string fonts_default_family;
291 /// use the fonts of the OS (OpenType, True Type) directly
293 /// use expert Small Caps
294 bool fonts_expert_sc;
295 /// use Old Style Figures (rm)
296 bool fonts_roman_osf;
297 /// use Old Style Figures (sf)
299 /// use Old Style Figures (tt)
300 bool fonts_typewriter_osf;
301 /// the options for the roman font
302 std::string font_roman_opts;
303 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
304 int fonts_sans_scale[2];
305 /// the scale factor of the sf font
306 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
307 // the options for the sans font
308 std::string font_sans_opts;
309 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
310 int fonts_typewriter_scale[2];
311 /// the scale factor of the tt font
312 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
313 // the options for the typewriter font
314 std::string font_typewriter_opts;
315 /// the font used by the CJK command
316 std::string fonts_cjk;
317 /// use LaTeX microtype package
319 /// use font ligatures for en- and em-dashes
320 bool use_dash_ligatures;
323 Spacing const & spacing() const;
329 Language const * language;
331 std::string lang_package;
333 BranchList & branchlist();
334 BranchList const & branchlist() const;
336 IndicesList & indiceslist();
337 IndicesList const & indiceslist() const;
339 * The LyX name of the input encoding for LaTeX. This can be one of
340 * - \c auto: find out the input encoding from the used languages
341 * - \c default: ditto
342 * - any encoding defined in the file lib/encodings
343 * The encoding of the LyX file is always utf8 and has nothing to
344 * do with this setting.
345 * The difference between \c auto and \c default is that \c auto also
346 * causes loading of the inputenc package and writes a \inputenc{} command
347 * to the file when switching to another encoding, while \c default does not.
348 * \c default will not work unless the user takes additional measures
349 * (such as using special environments like the CJK environment from
351 * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
352 * does not interpret it in any way apart from display on screen.
354 std::string inputenc;
355 /// The main encoding used by this buffer for LaTeX output.
356 /// If the main encoding is \c auto or \c default,
357 /// individual pieces of text can use different encodings.
358 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
359 /// instead of the value returned by this function (cf. #10600).
360 Encoding const & encoding() const;
367 /// use the class options defined in the layout?
368 bool use_default_options;
374 std::string float_placement;
376 std::string float_alignment;
378 unsigned int columns;
381 /// parameters for the listings package
382 std::string listings_params;
386 std::string pagestyle;
388 std::string tablestyle;
390 RGBColor backgroundcolor;
392 bool isbackgroundcolor;
398 RGBColor notefontcolor;
400 bool isnotefontcolor;
405 /// \param index should lie in the range 0 <= \c index <= 3.
406 Bullet & temp_bullet(size_type index);
407 Bullet const & temp_bullet(size_type index) const;
408 /// \param index should lie in the range 0 <= \c index <= 3.
409 Bullet & user_defined_bullet(size_type index);
410 Bullet const & user_defined_bullet(size_type index) const;
412 /// Whether to load a package such as amsmath or esint.
413 /// The enum values must not be changed (file format!)
415 /// Don't load the package. For experts only.
417 /// Load the package if needed (recommended)
419 /// Always load the package (e.g. if the document contains
420 /// some ERT that needs the package)
423 /// Whether to load a package such as amsmath or esint.
424 Package use_package(std::string const & p) const;
425 /// Set whether to load a package such as amsmath or esint.
426 void use_package(std::string const & p, Package u);
427 /// All packages that can be switched on or off
428 static std::map<std::string, std::string> const & auto_packages();
429 /// Do we use the bibtopic package?
430 bool useBibtopic() const;
431 /// Split bibliography?
432 bool splitbib() const { return use_bibtopic; }
433 /// Set split bibliography
434 void splitbib(bool const b) { use_bibtopic = b; }
435 /// Do we have multiple bibliographies (by chapter etc.)?
436 std::string multibib;
439 /// Save transient properties?
440 bool save_transient_properties;
441 /// revision tracking for this buffer ? (this is a transient property)
443 /** This param decides whether change tracking marks should be used
444 * in output (irrespective of how these marks are actually defined;
445 * for instance, they may differ for DVI and PDF generation)
446 * This is a transient property.
454 bool postpone_fragile_content;
456 /// the author list for the document
457 AuthorList & authors();
458 AuthorList const & authors() const;
459 void addAuthor(Author const & a);
461 /// map of the file's author IDs to AuthorList indexes
462 typedef std::map<int, int> AuthorMap;
463 AuthorMap author_map_;
465 /// the buffer's active font encoding
466 std::string const main_font_encoding() const;
467 /// all font encodings requested by the prefs/document/main language.
468 /// This does NOT include font encodings required by secondary languages
469 std::vector<std::string> const font_encodings() const;
472 std::string const dvips_options() const;
473 /** The return value of paperSizeName() depends on the
474 * purpose for which the paper size is needed, since they
475 * support different subsets of paper sizes.
477 enum PapersizePurpose {
486 std::string paperSizeName(PapersizePurpose purpose,
487 std::string const & psize = std::string()) const;
488 /// set up if and how babel is called
489 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
490 /// return supported drivers for specific packages
491 docstring getGraphicsDriver(std::string const & package) const;
492 /// handle inputenc etc.
493 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
495 std::string const parseFontName(std::string const & name) const;
496 /// set up the document fonts
497 std::string const loadFonts(LaTeXFeatures & features) const;
499 /// the cite engine modules
500 std::string const & citeEngine() const { return cite_engine_; }
501 /// the type of cite engine (authoryear or numerical)
502 CiteEngineType const & citeEngineType() const
503 { return cite_engine_type_; }
504 /// add the module to the cite engine modules
505 void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
506 /// set the cite engine type
507 void setCiteEngineType(CiteEngineType const & engine_type)
508 { cite_engine_type_ = engine_type; }
510 /// the available citation commands
511 std::vector<std::string> citeCommands() const;
512 /// the available citation styles
513 std::vector<CitationStyle> citeStyles() const;
515 /// Return the actual bibtex command (lyxrc or buffer param)
516 std::string const bibtexCommand() const;
518 /// Are we using biblatex?
519 bool useBiblatex() const;
521 /// Set the default BibTeX style file for the document
522 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
523 /// Get the default BibTeX style file from the TextClass
524 std::string const & defaultBiblioStyle() const;
525 /// whether the BibTeX style supports full author lists
526 bool fullAuthorList() const;
527 /// Check if a citation style is an alias to another style
528 std::string getCiteAlias(std::string const & s) const;
530 /// Options of the bibiography package
531 std::string biblio_opts;
532 /// The biblatex bibliography style
533 std::string biblatex_bibstyle;
534 /// The biblatex citation style
535 std::string biblatex_citestyle;
536 /// Set the bib file encoding (for biblatex)
537 void setBibEncoding(std::string const & s) { bib_encoding = s; }
538 /// Get the bib file encoding (for biblatex)
539 std::string const & bibEncoding() const { return bib_encoding; }
540 /// Set encoding for individual bib file (for biblatex)
541 void setBibFileEncoding(std::string const & file, std::string const & enc);
543 std::string const bibFileEncoding(std::string const & file) const;
545 /// options for pdf output
546 PDFOptions & pdfoptions();
547 PDFOptions const & pdfoptions() const;
549 // do not change these values. we rely upon them.
556 /// what to use for math output. present choices are above
557 MathOutput html_math_output;
558 /// whether to attempt to be XHTML 1.1 compliant or instead be
559 /// a little more mellow
562 double html_math_img_scale;
564 double display_pixel_ratio;
566 std::string html_latex_start;
568 std::string html_latex_end;
570 bool html_css_as_file;
572 // do not change these values. we rely upon them.
577 /// what format to use for table output in DocBook. present choices are above
578 TableOutput docbook_table_output;
580 /// allow the LaTeX backend to run external programs
582 /// generate output usable for reverse/forward search
584 /// custom LaTeX macro from user instead our own
585 std::string output_sync_macro;
586 /// use refstyle? or prettyref?
588 /// use minted? or listings?
590 //output line numbering
592 //optional params for lineno package
593 std::string lineno_opts;
595 /// Return true if language could be set to lang,
596 /// otherwise return false and do not change language
597 bool setLanguage(std::string const & lang);
599 void invalidateConverterCache() const;
600 /// Copies over some of the settings from \param bp,
601 /// namely the ones need by Advanced F&R. We don't want
602 /// to copy them all, e.g., not the default master.
603 void copyForAdvFR(BufferParams const & bp);
607 void readPreamble(Lexer &);
609 void readLocalLayout(Lexer &, bool);
611 void readLanguage(Lexer &);
613 void readGraphicsDriver(Lexer &);
615 void readBullets(Lexer &);
617 void readBulletsLaTeX(Lexer &);
619 void readModules(Lexer &);
621 void readRemovedModules(Lexer &);
623 void readIncludeonly(Lexer &);
624 /// A cache for the default flavors
625 typedef std::map<std::string, Flavor> DefaultFlavorCache;
627 mutable DefaultFlavorCache default_flavors_;
629 std::string cite_engine_;
630 /// the type of cite engine (authoryear or numerical)
631 CiteEngineType cite_engine_type_;
632 /// the default BibTeX style file for the document
633 std::string biblio_style;
634 /// The main encoding of the bib files, for Biblatex
635 std::string bib_encoding;
636 /// Individual file encodings, for Biblatex
637 std::map<std::string, std::string> bib_encodings;
638 /// Split bibliography?
641 DocumentClassPtr doc_class_;
643 LayoutModuleList layout_modules_;
644 /// this is for modules that are required by the document class but that
645 /// the user has chosen not to use
646 std::list<std::string> removed_modules_;
647 /// The local layouts without the forced ones
648 docstring local_layout_;
649 /// Forced local layouts only for reading (use getLocalLayout() instead)
650 docstring forced_local_layout_;
652 /// the list of included children (for includeonly)
653 std::list<std::string> included_children_;
655 typedef std::map<std::string, Package> PackageMap;
656 /** Whether and how to load packages like amsmath, esint, mhchem,
657 * mathdots, stackrel, stmaryrd and undertilde.
659 PackageMap use_packages;
661 /** Use the Pimpl idiom to hide those member variables that would otherwise
662 * drag in other header files.
667 static Impl * clone(Impl const *);
668 static void destroy(Impl *);
670 support::copied_ptr<Impl, MemoryTraits> pimpl_;