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"
34 namespace support { class FileName; }
49 class LayoutFileIndex;
57 enum class Flavor : int;
58 enum class QuoteStyle : int;
60 /** Buffer parameters.
61 * This class contains all the parameters for this buffer's use. Some
62 * work needs to be done on this class to make it nice. Now everything
68 enum ParagraphSeparation {
70 ParagraphIndentSeparation,
72 ParagraphSkipSeparation
77 /// get l10n translated to the buffers language
78 docstring B_(std::string const & l10n) const;
80 /// read a header token, if unrecognised, return it or an unknown class name
81 std::string readToken(Lexer & lex,
82 std::string const & token, ///< token to read.
83 support::FileName const & filename);
86 void writeFile(std::ostream &, Buffer const *) const;
88 /// check what features are implied by the buffer parameters.
89 void validate(LaTeXFeatures &) const;
91 /** \returns true if the babel package is used (interrogates
92 * the BufferParams, a LyXRC variable, and the document class).
93 * This returned value can then be passed to the insets...
95 bool writeLaTeX(otexstream &, LaTeXFeatures &,
96 support::FileName const &) const;
99 void useClassDefaults();
101 bool hasClassDefaults() const;
104 Length const & getParIndent() const;
106 void setParIndent(Length const & indent);
108 VSpace const & getDefSkip() const;
110 void setDefSkip(VSpace const & vs);
113 Length const & getMathIndent() const;
115 void setMathIndent(Length const & indent);
117 /// Whether formulas are indented
121 enum MathNumber { DEFAULT, LEFT, RIGHT };
122 /// number formulas on left/right/default
123 MathNumber math_numbering_side;
125 /// Convenience function for display: like math_number, but
126 /// DEFAULT is replaced by the best guess we have.
127 MathNumber getMathNumber() const;
129 /** Whether paragraphs are separated by using a indent like in
130 * articles or by using a little skip like in letters.
132 ParagraphSeparation paragraph_separation;
134 QuoteStyle quotes_style;
138 std::string fontsize;
139 /// Get the LayoutFile this document is using.
140 LayoutFile const * baseClass() const;
142 LayoutFileIndex const & baseClassID() const;
143 /// Set the LyX layout file this document is using.
144 /// NOTE: This does not call makeDocumentClass() to update the local
145 /// DocumentClass. That needs to be done manually.
146 /// \param classname: the name of the layout file
147 /// \param path: non-empty only for local layout files
148 bool setBaseClass(std::string const & classname,
149 std::string const & path = std::string());
150 /// Adds the module information to the baseClass information to
151 /// create our local DocumentClass.
152 /// NOTE: This should NEVER be called externally unless one immediately goes
153 /// on to class BufferView::updateDocumentClass(). The exception, of course,
154 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
155 /// the parameters from the active Buffer.
156 void makeDocumentClass(bool clone = false, bool internal = false);
157 /// Returns the DocumentClass currently in use: the BaseClass as modified
159 DocumentClass const & documentClass() const;
160 /// \return A pointer to the DocumentClass currently in use: the BaseClass
161 /// as modified by modules.
162 DocumentClassConstPtr documentClassPtr() const;
163 /// This bypasses the baseClass and sets the textClass directly.
164 /// Should be called with care and would be better not being here,
165 /// but it seems to be needed by CutAndPaste::putClipboard().
166 void setDocumentClass(DocumentClassConstPtr);
167 /// List of modules in use
168 LayoutModuleList const & getModules() const { return layout_modules_; }
169 /// List of default modules the user has removed
170 std::list<std::string> const & getRemovedModules() const
171 { return removed_modules_; }
173 /// Add a module to the list of modules in use. This checks only that the
174 /// module is not already in the list, so use layoutModuleCanBeAdeed first
175 /// if you want to check for compatibility.
176 /// \return true if module was successfully added.
177 bool addLayoutModule(std::string const & modName);
178 /// checks to make sure module's requriements are satisfied, that it does
179 /// not conflict with already-present modules, isn't already loaded, etc.
180 bool layoutModuleCanBeAdded(std::string const & modName) const;
182 void addRemovedModule(std::string const & modName)
183 { removed_modules_.push_back(modName); }
185 void clearLayoutModules() { layout_modules_.clear(); }
186 /// Clear the removed module list
187 void clearRemovedModules() { removed_modules_.clear(); }
188 /// Get the local layouts
189 docstring getLocalLayout(bool forced) const;
190 /// Set the local layouts
191 void setLocalLayout(docstring const & layout, bool forced);
193 /// returns \c true if the buffer contains a LaTeX document
194 bool isLatex() const;
195 /// returns \c true if the buffer contains a Wed document
196 bool isLiterate() const;
198 /// return the format of the buffer on a string
199 std::string bufferFormat() const;
200 /// return the default output format of the current backend
201 std::string getDefaultOutputFormat() const;
202 /// return the output flavor of \p format or the default
203 Flavor getOutputFlavor(std::string const & format = std::string()) const;
205 bool isExportable(std::string const & format, bool need_viewable) const;
207 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
208 /// the backends appropriate for use with this document.
209 /// so, e.g., latex is excluded , if we're using non-TeX fonts
210 std::vector<std::string> backends() const;
212 /// List of included children (for includeonly)
213 std::list<std::string> const & getIncludedChildren() const
214 { return included_children_; }
216 void addIncludedChildren(std::string const & child)
217 { included_children_.push_back(child); }
218 /// Clear the list of included children
219 void clearIncludedChildren() { included_children_.clear(); }
221 /// update aux files of unincluded children (with \includeonly)
222 enum ChildrenMaintenance {
227 ChildrenMaintenance maintain_unincluded_children;
229 /// returns the main font for the buffer (document)
230 Font const getFont() const;
232 /// translate quote style string to enum value
233 QuoteStyle getQuoteStyle(std::string const & qs) const;
235 /* these are for the PaperLayout */
237 PAPER_SIZE papersize;
239 PAPER_ORIENTATION orientation;
240 /// use custom margins
243 std::string paperwidth;
245 std::string paperheight;
247 std::string leftmargin;
249 std::string topmargin;
251 std::string rightmargin;
253 std::string bottommargin;
255 std::string headheight;
259 std::string footskip;
261 std::string columnsep;
263 /* some LaTeX options */
264 /// The graphics driver
265 std::string graphics_driver;
266 /// The default output format
267 std::string default_output_format;
268 /// customized bibliography processor
269 std::string bibtex_command;
270 /// customized index processor
271 std::string index_command;
272 /// font encoding(s) requested for this document
274 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
275 std::string fonts_roman[2];
277 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
278 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
279 std::string fonts_sans[2];
281 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
282 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
283 std::string fonts_typewriter[2];
285 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
286 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
287 std::string fonts_math[2];
289 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
290 /// the default family (rm, sf, tt)
291 std::string fonts_default_family;
292 /// use the fonts of the OS (OpenType, True Type) directly
294 /// use expert Small Caps
295 bool fonts_expert_sc;
296 /// use Old Style Figures (rm)
297 bool fonts_roman_osf;
298 /// use Old Style Figures (sf)
300 /// use Old Style Figures (tt)
301 bool fonts_typewriter_osf;
302 /// the options for the roman font
303 std::string font_roman_opts;
304 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
305 int fonts_sans_scale[2];
306 /// the scale factor of the sf font
307 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
308 // the options for the sans font
309 std::string font_sans_opts;
310 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
311 int fonts_typewriter_scale[2];
312 /// the scale factor of the tt font
313 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
314 // the options for the typewriter font
315 std::string font_typewriter_opts;
316 /// the font used by the CJK command
317 std::string fonts_cjk;
318 /// use LaTeX microtype package
320 /// use font ligatures for en- and em-dashes
321 bool use_dash_ligatures;
324 Spacing const & spacing() const;
330 Language const * language;
332 std::string lang_package;
334 BranchList & branchlist();
335 BranchList const & branchlist() const;
337 IndicesList & indiceslist();
338 IndicesList const & indiceslist() const;
340 typedef std::vector<WordLangTuple> IgnoreList;
342 IgnoreList & spellignore();
343 IgnoreList const & spellignore() const;
344 bool spellignored(WordLangTuple const & wl) const;
346 * The LyX name of the input encoding for LaTeX. This can be one of
347 * - \c auto: find out the input encoding from the used languages
348 * - \c default: ditto
349 * - any encoding defined in the file lib/encodings
350 * The encoding of the LyX file is always utf8 and has nothing to
351 * do with this setting.
352 * The difference between \c auto and \c default is that \c auto also
353 * causes loading of the inputenc package and writes a \inputenc{} command
354 * to the file when switching to another encoding, while \c default does not.
355 * \c default will not work unless the user takes additional measures
356 * (such as using special environments like the CJK environment from
358 * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
359 * does not interpret it in any way apart from display on screen.
361 std::string inputenc;
362 /// The main encoding used by this buffer for LaTeX output.
363 /// If the main encoding is \c auto or \c default,
364 /// individual pieces of text can use different encodings.
365 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
366 /// instead of the value returned by this function (cf. #10600).
367 Encoding const & encoding() const;
374 /// use the class options defined in the layout?
375 bool use_default_options;
381 std::string float_placement;
383 std::string float_alignment;
385 unsigned int columns;
388 /// parameters for the listings package
389 std::string listings_params;
393 std::string pagestyle;
395 std::string tablestyle;
397 RGBColor backgroundcolor;
399 bool isbackgroundcolor;
405 RGBColor notefontcolor;
407 bool isnotefontcolor;
412 /// \param index should lie in the range 0 <= \c index <= 3.
413 Bullet & temp_bullet(size_type index);
414 Bullet const & temp_bullet(size_type index) const;
415 /// \param index should lie in the range 0 <= \c index <= 3.
416 Bullet & user_defined_bullet(size_type index);
417 Bullet const & user_defined_bullet(size_type index) const;
419 /// Whether to load a package such as amsmath or esint.
420 /// The enum values must not be changed (file format!)
422 /// Don't load the package. For experts only.
424 /// Load the package if needed (recommended)
426 /// Always load the package (e.g. if the document contains
427 /// some ERT that needs the package)
430 /// Whether to load a package such as amsmath or esint.
431 Package use_package(std::string const & p) const;
432 /// Set whether to load a package such as amsmath or esint.
433 void use_package(std::string const & p, Package u);
434 /// All packages that can be switched on or off
435 static std::map<std::string, std::string> const & auto_packages();
436 /// Do we use the bibtopic package?
437 bool useBibtopic() const;
438 /// Split bibliography?
439 bool splitbib() const { return use_bibtopic; }
440 /// Set split bibliography
441 void splitbib(bool const b) { use_bibtopic = b; }
442 /// Do we have multiple bibliographies (by chapter etc.)?
443 std::string multibib;
446 /// Save transient properties?
447 bool save_transient_properties;
448 /// revision tracking for this buffer ? (this is a transient property)
450 /** This param decides whether change tracking marks should be used
451 * in output (irrespective of how these marks are actually defined;
452 * for instance, they may differ for DVI and PDF generation)
453 * This is a transient property.
461 bool postpone_fragile_content;
463 /// the author list for the document
464 AuthorList & authors();
465 AuthorList const & authors() const;
466 void addAuthor(Author const & a);
468 /// map of the file's author IDs to AuthorList indexes
469 typedef std::map<int, int> AuthorMap;
470 AuthorMap author_map_;
472 /// the buffer's active font encoding
473 std::string const main_font_encoding() const;
474 /// all font encodings requested by the prefs/document/main language.
475 /// This does NOT include font encodings required by secondary languages
476 std::vector<std::string> const font_encodings() const;
479 std::string const dvips_options() const;
480 /** The return value of paperSizeName() depends on the
481 * purpose for which the paper size is needed, since they
482 * support different subsets of paper sizes.
484 enum PapersizePurpose {
493 std::string paperSizeName(PapersizePurpose purpose,
494 std::string const & psize = std::string()) const;
495 /// set up if and how babel is called
496 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
497 /// return supported drivers for specific packages
498 docstring getGraphicsDriver(std::string const & package) const;
499 /// handle inputenc etc.
500 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
502 std::string const parseFontName(std::string const & name) const;
503 /// set up the document fonts
504 std::string const loadFonts(LaTeXFeatures & features) const;
506 /// the cite engine modules
507 std::string const & citeEngine() const { return cite_engine_; }
508 /// the type of cite engine (authoryear or numerical)
509 CiteEngineType const & citeEngineType() const
510 { return cite_engine_type_; }
511 /// add the module to the cite engine modules
512 void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
513 /// set the cite engine type
514 void setCiteEngineType(CiteEngineType const & engine_type)
515 { cite_engine_type_ = engine_type; }
517 /// the available citation commands
518 std::vector<std::string> citeCommands() const;
519 /// the available citation styles
520 std::vector<CitationStyle> citeStyles() const;
522 /// Return the actual bibtex command (lyxrc or buffer param)
523 std::string const bibtexCommand() const;
525 /// Are we using biblatex?
526 bool useBiblatex() const;
528 /// Set the default BibTeX style file for the document
529 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
530 /// Get the default BibTeX style file from the TextClass
531 std::string const & defaultBiblioStyle() const;
532 /// whether the BibTeX style supports full author lists
533 bool fullAuthorList() const;
534 /// Check if a citation style is an alias to another style
535 std::string getCiteAlias(std::string const & s) const;
537 /// Options of the bibiography package
538 std::string biblio_opts;
539 /// The biblatex bibliography style
540 std::string biblatex_bibstyle;
541 /// The biblatex citation style
542 std::string biblatex_citestyle;
543 /// Set the bib file encoding (for biblatex)
544 void setBibEncoding(std::string const & s) { bib_encoding = s; }
545 /// Get the bib file encoding (for biblatex)
546 std::string const & bibEncoding() const { return bib_encoding; }
547 /// Set encoding for individual bib file (for biblatex)
548 void setBibFileEncoding(std::string const & file, std::string const & enc);
550 std::string const bibFileEncoding(std::string const & file) const;
552 /// options for pdf output
553 PDFOptions & pdfoptions();
554 PDFOptions const & pdfoptions() const;
556 // do not change these values. we rely upon them.
563 /// what to use for math output. present choices are above
564 MathOutput html_math_output;
565 /// whether to attempt to be XHTML 1.1 compliant or instead be
566 /// a little more mellow
569 double html_math_img_scale;
571 double display_pixel_ratio;
573 std::string html_latex_start;
575 std::string html_latex_end;
577 bool html_css_as_file;
579 // do not change these values. we rely upon them.
584 /// what format to use for table output in DocBook. present choices are above
585 TableOutput docbook_table_output;
587 // do not change these values. we rely upon them.
588 enum MathMLNameSpacePrefix {
593 /// what prefix to use when outputting MathML. present choices are above
594 MathMLNameSpacePrefix docbook_mathml_prefix;
596 /// allow the LaTeX backend to run external programs
598 /// generate output usable for reverse/forward search
600 /// custom LaTeX macro from user instead our own
601 std::string output_sync_macro;
602 /// use refstyle? or prettyref?
604 /// use minted? or listings?
606 //output line numbering
608 //optional params for lineno package
609 std::string lineno_opts;
611 /// Return true if language could be set to lang,
612 /// otherwise return false and do not change language
613 bool setLanguage(std::string const & lang);
615 void invalidateConverterCache() const;
616 /// Copies over some of the settings from \param bp,
617 /// namely the ones need by Advanced F&R. We don't want
618 /// to copy them all, e.g., not the default master.
619 void copyForAdvFR(BufferParams const & bp);
623 void readPreamble(Lexer &);
625 void readLocalLayout(Lexer &, bool);
627 void readLanguage(Lexer &);
629 void readGraphicsDriver(Lexer &);
631 void readBullets(Lexer &);
633 void readBulletsLaTeX(Lexer &);
635 void readModules(Lexer &);
637 void readRemovedModules(Lexer &);
639 void readIncludeonly(Lexer &);
640 /// A cache for the default flavors
641 typedef std::map<std::string, Flavor> DefaultFlavorCache;
643 mutable DefaultFlavorCache default_flavors_;
645 std::string cite_engine_;
646 /// the type of cite engine (authoryear or numerical)
647 CiteEngineType cite_engine_type_;
648 /// the default BibTeX style file for the document
649 std::string biblio_style;
650 /// The main encoding of the bib files, for Biblatex
651 std::string bib_encoding;
652 /// Individual file encodings, for Biblatex
653 std::map<std::string, std::string> bib_encodings;
654 /// Split bibliography?
657 DocumentClassPtr doc_class_;
659 LayoutModuleList layout_modules_;
660 /// this is for modules that are required by the document class but that
661 /// the user has chosen not to use
662 std::list<std::string> removed_modules_;
663 /// The local layouts without the forced ones
664 docstring local_layout_;
665 /// Forced local layouts only for reading (use getLocalLayout() instead)
666 docstring forced_local_layout_;
668 /// the list of included children (for includeonly)
669 std::list<std::string> included_children_;
671 typedef std::map<std::string, Package> PackageMap;
672 /** Whether and how to load packages like amsmath, esint, mhchem,
673 * mathdots, stackrel, stmaryrd and undertilde.
675 PackageMap use_packages;
677 /** Use the Pimpl idiom to hide those member variables that would otherwise
678 * drag in other header files.
683 static Impl * clone(Impl const *);
684 static void destroy(Impl *);
686 support::copied_ptr<Impl, MemoryTraits> pimpl_;