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"
20 #include "DocumentClassPtr.h"
21 #include "LayoutModuleList.h"
24 #include "support/copied_ptr.h"
25 #include "support/types.h"
32 namespace support { class FileName; }
47 class LayoutFileIndex;
55 enum class Flavor : int;
56 enum class QuoteStyle : int;
58 /** Buffer parameters.
59 * This class contains all the parameters for this buffer's use. Some
60 * work needs to be done on this class to make it nice. Now everything
66 enum ParagraphSeparation {
68 ParagraphIndentSeparation,
70 ParagraphSkipSeparation
75 /// get l10n translated to the buffers language
76 docstring B_(std::string const & l10n) const;
78 /// read a header token, if unrecognised, return it or an unknown class name
79 std::string readToken(Lexer & lex,
80 std::string const & token, ///< token to read.
81 support::FileName const & filepath);
84 void writeFile(std::ostream &, Buffer const *) const;
86 /// check what features are implied by the buffer parameters.
87 void validate(LaTeXFeatures &) const;
89 /** \returns true if the babel package is used (interrogates
90 * the BufferParams, a LyXRC variable, and the document class).
91 * This returned value can then be passed to the insets...
93 bool writeLaTeX(otexstream &, LaTeXFeatures &,
94 support::FileName const &) const;
97 void useClassDefaults();
99 bool hasClassDefaults() const;
102 Length const & getParIndent() const;
104 void setParIndent(Length const & indent);
106 VSpace const & getDefSkip() const;
108 void setDefSkip(VSpace const & vs);
111 Length const & getMathIndent() const;
113 void setMathIndent(Length const & indent);
115 /// Whether formulas are indented
119 enum MathNumber { DEFAULT, LEFT, RIGHT };
120 /// number formulas on left/right/default
121 MathNumber math_numbering_side;
123 /// Convenience function for display: like math_number, but
124 /// DEFAULT is replaced by the best guess we have.
125 MathNumber getMathNumber() const;
127 /** Whether paragraphs are separated by using a indent like in
128 * articles or by using a little skip like in letters.
130 ParagraphSeparation paragraph_separation;
132 QuoteStyle quotes_style;
136 std::string fontsize;
137 /// Get the LayoutFile this document is using.
138 LayoutFile const * baseClass() const;
140 LayoutFileIndex const & baseClassID() const;
141 /// Set the LyX layout file this document is using.
142 /// NOTE: This does not call makeDocumentClass() to update the local
143 /// DocumentClass. That needs to be done manually.
144 /// \param classname: the name of the layout file
145 /// \param path: non-empty only for local layout files
146 bool setBaseClass(std::string const & classname,
147 std::string const & path = std::string());
148 /// Adds the module information to the baseClass information to
149 /// create our local DocumentClass.
150 /// NOTE: This should NEVER be called externally unless one immediately goes
151 /// on to class BufferView::updateDocumentClass(). The exception, of course,
152 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
153 /// the parameters from the active Buffer.
154 void makeDocumentClass(bool const clone = false);
155 /// Returns the DocumentClass currently in use: the BaseClass as modified
157 DocumentClass const & documentClass() const;
158 /// \return A pointer to the DocumentClass currently in use: the BaseClass
159 /// as modified by modules.
160 DocumentClassConstPtr documentClassPtr() const;
161 /// This bypasses the baseClass and sets the textClass directly.
162 /// Should be called with care and would be better not being here,
163 /// but it seems to be needed by CutAndPaste::putClipboard().
164 void setDocumentClass(DocumentClassConstPtr);
165 /// List of modules in use
166 LayoutModuleList const & getModules() const { return layout_modules_; }
167 /// List of default modules the user has removed
168 std::list<std::string> const & getRemovedModules() const
169 { return removed_modules_; }
171 /// Add a module to the list of modules in use. This checks only that the
172 /// module is not already in the list, so use layoutModuleCanBeAdeed first
173 /// if you want to check for compatibility.
174 /// \return true if module was successfully added.
175 bool addLayoutModule(std::string const & modName);
176 /// checks to make sure module's requriements are satisfied, that it does
177 /// not conflict with already-present modules, isn't already loaded, etc.
178 bool layoutModuleCanBeAdded(std::string const & modName) const;
180 void addRemovedModule(std::string const & modName)
181 { removed_modules_.push_back(modName); }
183 void clearLayoutModules() { layout_modules_.clear(); }
184 /// Clear the removed module list
185 void clearRemovedModules() { removed_modules_.clear(); }
186 /// Get the local layouts
187 docstring getLocalLayout(bool forced) const;
188 /// Set the local layouts
189 void setLocalLayout(docstring const & layout, bool forced);
191 /// returns \c true if the buffer contains a LaTeX document
192 bool isLatex() const;
193 /// returns \c true if the buffer contains a Wed document
194 bool isLiterate() const;
196 /// return the format of the buffer on a string
197 std::string bufferFormat() const;
198 /// return the default output format of the current backend
199 std::string getDefaultOutputFormat() const;
200 /// return the output flavor of \p format or the default
201 Flavor getOutputFlavor(std::string const & format = std::string()) const;
203 bool isExportable(std::string const & format, bool need_viewable) const;
205 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
206 /// the backends appropriate for use with this document.
207 /// so, e.g., latex is excluded , if we're using non-TeX fonts
208 std::vector<std::string> backends() const;
210 /// List of included children (for includeonly)
211 std::list<std::string> const & getIncludedChildren() const
212 { return included_children_; }
214 void addIncludedChildren(std::string const & child)
215 { included_children_.push_back(child); }
216 /// Clear the list of included children
217 void clearIncludedChildren() { included_children_.clear(); }
219 /// update aux files of unincluded children (with \includeonly)
220 enum ChildrenMaintenance {
225 ChildrenMaintenance maintain_unincluded_children;
227 /// returns the main font for the buffer (document)
228 Font const getFont() const;
230 /// translate quote style string to enum value
231 QuoteStyle getQuoteStyle(std::string const & qs) const;
233 /* these are for the PaperLayout */
235 PAPER_SIZE papersize;
237 PAPER_ORIENTATION orientation;
238 /// use custom margins
241 std::string paperwidth;
243 std::string paperheight;
245 std::string leftmargin;
247 std::string topmargin;
249 std::string rightmargin;
251 std::string bottommargin;
253 std::string headheight;
257 std::string footskip;
259 std::string columnsep;
261 /* some LaTeX options */
262 /// The graphics driver
263 std::string graphics_driver;
264 /// The default output format
265 std::string default_output_format;
266 /// customized bibliography processor
267 std::string bibtex_command;
268 /// customized index processor
269 std::string index_command;
270 /// font encoding(s) requested for this document
272 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
273 std::string fonts_roman[2];
275 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
276 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
277 std::string fonts_sans[2];
279 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
280 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
281 std::string fonts_typewriter[2];
283 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
284 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
285 std::string fonts_math[2];
287 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
288 /// the default family (rm, sf, tt)
289 std::string fonts_default_family;
290 /// use the fonts of the OS (OpenType, True Type) directly
292 /// use expert Small Caps
293 bool fonts_expert_sc;
294 /// use Old Style Figures (rm)
295 bool fonts_roman_osf;
296 /// use Old Style Figures (sf)
298 /// use Old Style Figures (tt)
299 bool fonts_typewriter_osf;
300 /// the options for the roman font
301 std::string font_roman_opts;
302 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
303 int fonts_sans_scale[2];
304 /// the scale factor of the sf font
305 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
306 // the options for the sans font
307 std::string font_sans_opts;
308 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
309 int fonts_typewriter_scale[2];
310 /// the scale factor of the tt font
311 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
312 // the options for the typewriter font
313 std::string font_typewriter_opts;
314 /// the font used by the CJK command
315 std::string fonts_cjk;
316 /// use LaTeX microtype package
318 /// use font ligatures for en- and em-dashes
319 bool use_dash_ligatures;
322 Spacing const & spacing() const;
328 Language const * language;
330 std::string lang_package;
332 BranchList & branchlist();
333 BranchList const & branchlist() const;
335 IndicesList & indiceslist();
336 IndicesList const & indiceslist() const;
338 * The LyX name of the input encoding for LaTeX. This can be one of
339 * - \c auto: find out the input encoding from the used languages
340 * - \c default: ditto
341 * - any encoding defined in the file lib/encodings
342 * The encoding of the LyX file is always utf8 and has nothing to
343 * do with this setting.
344 * The difference between \c auto and \c default is that \c auto also
345 * causes loading of the inputenc package and writes a \inputenc{} command
346 * to the file when switching to another encoding, while \c default does not.
347 * \c default will not work unless the user takes additional measures
348 * (such as using special environments like the CJK environment from
350 * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
351 * does not interpret it in any way apart from display on screen.
353 std::string inputenc;
354 /// The main encoding used by this buffer for LaTeX output.
355 /// If the main encoding is \c auto or \c default,
356 /// individual pieces of text can use different encodings.
357 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
358 /// instead of the value returned by this function (cf. #10600).
359 Encoding const & encoding() const;
366 /// use the class options defined in the layout?
367 bool use_default_options;
373 std::string float_placement;
375 std::string float_alignment;
377 unsigned int columns;
380 /// parameters for the listings package
381 std::string listings_params;
385 std::string pagestyle;
387 std::string tablestyle;
389 RGBColor backgroundcolor;
391 bool isbackgroundcolor;
397 RGBColor notefontcolor;
400 /// \param index should lie in the range 0 <= \c index <= 3.
401 Bullet & temp_bullet(size_type index);
402 Bullet const & temp_bullet(size_type index) const;
403 /// \param index should lie in the range 0 <= \c index <= 3.
404 Bullet & user_defined_bullet(size_type index);
405 Bullet const & user_defined_bullet(size_type index) const;
407 /// Whether to load a package such as amsmath or esint.
408 /// The enum values must not be changed (file format!)
410 /// Don't load the package. For experts only.
412 /// Load the package if needed (recommended)
414 /// Always load the package (e.g. if the document contains
415 /// some ERT that needs the package)
418 /// Whether to load a package such as amsmath or esint.
419 Package use_package(std::string const & p) const;
420 /// Set whether to load a package such as amsmath or esint.
421 void use_package(std::string const & p, Package u);
422 /// All packages that can be switched on or off
423 static std::map<std::string, std::string> const & auto_packages();
424 /// Do we use the bibtopic package?
425 bool useBibtopic() const;
426 /// Split bibliography?
427 bool splitbib() const { return use_bibtopic; }
428 /// Set split bibliography
429 void splitbib(bool const b) { use_bibtopic = b; }
430 /// Do we have multiple bibliographies (by chapter etc.)?
431 std::string multibib;
434 /// Save transient properties?
435 bool save_transient_properties;
436 /// revision tracking for this buffer ? (this is a transient property)
438 /** This param decides whether change tracking marks should be used
439 * in output (irrespective of how these marks are actually defined;
440 * for instance, they may differ for DVI and PDF generation)
441 * This is a transient property.
449 bool postpone_fragile_content;
451 /// the author list for the document
452 AuthorList & authors();
453 AuthorList const & authors() const;
454 void addAuthor(Author const & a);
456 /// map of the file's author IDs to AuthorList indexes
457 typedef std::map<int, int> AuthorMap;
458 AuthorMap author_map_;
460 /// the buffer's active font encoding
461 std::string const main_font_encoding() const;
462 /// all font encodings requested by the prefs/document/main language.
463 /// This does NOT include font encodings required by secondary languages
464 std::vector<std::string> const font_encodings() const;
467 std::string const dvips_options() const;
468 /** The return value of paperSizeName() depends on the
469 * purpose for which the paper size is needed, since they
470 * support different subsets of paper sizes.
472 enum PapersizePurpose {
481 std::string paperSizeName(PapersizePurpose purpose,
482 std::string const & psize = std::string()) const;
483 /// set up if and how babel is called
484 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
485 /// return supported drivers for specific packages
486 docstring getGraphicsDriver(std::string const & package) const;
487 /// handle inputenc etc.
488 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
490 std::string const parseFontName(std::string const & name) const;
491 /// set up the document fonts
492 std::string const loadFonts(LaTeXFeatures & features) const;
494 /// the cite engine modules
495 std::string const & citeEngine() const { return cite_engine_; }
496 /// the type of cite engine (authoryear or numerical)
497 CiteEngineType const & citeEngineType() const
498 { return cite_engine_type_; }
499 /// add the module to the cite engine modules
500 void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
501 /// set the cite engine type
502 void setCiteEngineType(CiteEngineType const & engine_type)
503 { cite_engine_type_ = engine_type; }
505 /// the available citation commands
506 std::vector<std::string> citeCommands() const;
507 /// the available citation styles
508 std::vector<CitationStyle> citeStyles() const;
510 /// Return the actual bibtex command (lyxrc or buffer param)
511 std::string const bibtexCommand() const;
513 /// Are we using biblatex?
514 bool useBiblatex() const;
516 /// Set the default BibTeX style file for the document
517 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
518 /// Get the default BibTeX style file from the TextClass
519 std::string const & defaultBiblioStyle() const;
520 /// whether the BibTeX style supports full author lists
521 bool fullAuthorList() const;
522 /// Check if a citation style is an alias to another style
523 std::string getCiteAlias(std::string const & s) const;
525 /// Options of the bibiography package
526 std::string biblio_opts;
527 /// The biblatex bibliography style
528 std::string biblatex_bibstyle;
529 /// The biblatex citation style
530 std::string biblatex_citestyle;
531 /// Set the bib file encoding (for biblatex)
532 void setBibEncoding(std::string const & s) { bib_encoding = s; }
533 /// Get the bib file encoding (for biblatex)
534 std::string const & bibEncoding() const { return bib_encoding; }
535 /// Set encoding for individual bib file (for biblatex)
536 void setBibFileEncoding(std::string const & file, std::string const & enc);
538 std::string const bibFileEncoding(std::string const & file) const;
540 /// options for pdf output
541 PDFOptions & pdfoptions();
542 PDFOptions const & pdfoptions() const;
544 // do not change these values. we rely upon them.
551 /// what to use for math output. present choices are above
552 MathOutput html_math_output;
553 /// whether to attempt to be XHTML 1.1 compliant or instead be
554 /// a little more mellow
557 double html_math_img_scale;
559 double display_pixel_ratio;
561 std::string html_latex_start;
563 std::string html_latex_end;
565 bool html_css_as_file;
567 // do not change these values. we rely upon them.
572 /// what format to use for table output in DocBook. present choices are above
573 TableOutput docbook_table_output;
575 /// allow the LaTeX backend to run external programs
577 /// generate output usable for reverse/forward search
579 /// custom LaTeX macro from user instead our own
580 std::string output_sync_macro;
581 /// use refstyle? or prettyref?
583 /// use minted? or listings?
585 //output line numbering
587 //optional params for lineno package
588 std::string lineno_opts;
590 /// Return true if language could be set to lang,
591 /// otherwise return false and do not change language
592 bool setLanguage(std::string const & lang);
594 void invalidateConverterCache() const;
595 /// Copies over some of the settings from \param bp,
596 /// namely the ones need by Advanced F&R. We don't want
597 /// to copy them all, e.g., not the default master.
598 void copyForAdvFR(BufferParams const & bp);
602 void readPreamble(Lexer &);
604 void readLocalLayout(Lexer &, bool);
606 void readLanguage(Lexer &);
608 void readGraphicsDriver(Lexer &);
610 void readBullets(Lexer &);
612 void readBulletsLaTeX(Lexer &);
614 void readModules(Lexer &);
616 void readRemovedModules(Lexer &);
618 void readIncludeonly(Lexer &);
619 /// A cache for the default flavors
620 typedef std::map<std::string, Flavor> DefaultFlavorCache;
622 mutable DefaultFlavorCache default_flavors_;
624 std::string cite_engine_;
625 /// the type of cite engine (authoryear or numerical)
626 CiteEngineType cite_engine_type_;
627 /// the default BibTeX style file for the document
628 std::string biblio_style;
629 /// The main encoding of the bib files, for Biblatex
630 std::string bib_encoding;
631 /// Individual file encodings, for Biblatex
632 std::map<std::string, std::string> bib_encodings;
633 /// Split bibliography?
636 DocumentClassPtr doc_class_;
638 LayoutModuleList layout_modules_;
639 /// this is for modules that are required by the document class but that
640 /// the user has chosen not to use
641 std::list<std::string> removed_modules_;
642 /// The local layouts without the forced ones
643 docstring local_layout_;
644 /// Forced local layouts only for reading (use getLocalLayout() instead)
645 docstring forced_local_layout_;
647 /// the list of included children (for includeonly)
648 std::list<std::string> included_children_;
650 typedef std::map<std::string, Package> PackageMap;
651 /** Whether and how to load packages like amsmath, esint, mhchem,
652 * mathdots, stackrel, stmaryrd and undertilde.
654 PackageMap use_packages;
656 /** Use the Pimpl idiom to hide those member variables that would otherwise
657 * drag in other header files.
662 static Impl * clone(Impl const *);
663 static void destroy(Impl *);
665 support::copied_ptr<Impl, MemoryTraits> pimpl_;