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
20 #include "DocumentClassPtr.h"
22 #include "LayoutModuleList.h"
23 #include "OutputParams.h"
26 #include "insets/InsetQuotes.h"
28 #include "support/copied_ptr.h"
35 namespace support { class FileName; }
45 class LayoutFileIndex;
52 /** Buffer parameters.
53 * This class contains all the parameters for this buffer's use. Some
54 * work needs to be done on this class to make it nice. Now everything
60 enum ParagraphSeparation {
62 ParagraphIndentSeparation,
64 ParagraphSkipSeparation
69 /// get l10n translated to the buffers language
70 docstring B_(std::string const & l10n) const;
72 /// read a header token, if unrecognised, return it or an unknown class name
73 std::string readToken(Lexer & lex,
74 std::string const & token, ///< token to read.
75 support::FileName const & filepath);
78 void writeFile(std::ostream &, Buffer const *) const;
80 /// check what features are implied by the buffer parameters.
81 void validate(LaTeXFeatures &) const;
83 /** \returns true if the babel package is used (interrogates
84 * the BufferParams, a LyXRC variable, and the document class).
85 * This returned value can then be passed to the insets...
87 bool writeLaTeX(otexstream &, LaTeXFeatures &,
88 support::FileName const &) const;
91 void useClassDefaults();
93 bool hasClassDefaults() const;
96 Length const & getParIndent() const;
98 void setParIndent(Length const & indent);
100 VSpace const & getDefSkip() const;
102 void setDefSkip(VSpace const & vs);
105 Length const & getMathIndent() const;
107 void setMathIndent(Length const & indent);
109 /// Whether formulas are indented
113 enum MathNumber { DEFAULT, LEFT, RIGHT };
114 /// number formulas on left/right/default
115 MathNumber math_numbering_side;
117 /// Convenience function for display: like math_number, but
118 /// DEFAULT is replaced by the best guess we have.
119 MathNumber getMathNumber() const;
121 /** Whether paragraphs are separated by using a indent like in
122 * articles or by using a little skip like in letters.
124 ParagraphSeparation paragraph_separation;
126 InsetQuotesParams::QuoteStyle quotes_style;
130 std::string fontsize;
131 /// Get the LayoutFile this document is using.
132 LayoutFile const * baseClass() const;
134 LayoutFileIndex const & baseClassID() const;
135 /// Set the LyX layout file this document is using.
136 /// NOTE: This does not call makeDocumentClass() to update the local
137 /// DocumentClass. That needs to be done manually.
138 /// \param classname: the name of the layout file
139 /// \param path: non-empty only for local layout files
140 bool setBaseClass(std::string const & classname,
141 std::string const & path = std::string());
142 /// Adds the module information to the baseClass information to
143 /// create our local DocumentClass.
144 /// NOTE: This should NEVER be called externally unless one immediately goes
145 /// on to class BufferView::updateDocumentClass(). The exception, of course,
146 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
147 /// the parameters from the active Buffer.
148 void makeDocumentClass(bool const clone = false);
149 /// Returns the DocumentClass currently in use: the BaseClass as modified
151 DocumentClass const & documentClass() const;
152 /// \return A pointer to the DocumentClass currently in use: the BaseClass
153 /// as modified by modules.
154 DocumentClassConstPtr documentClassPtr() const;
155 /// This bypasses the baseClass and sets the textClass directly.
156 /// Should be called with care and would be better not being here,
157 /// but it seems to be needed by CutAndPaste::putClipboard().
158 void setDocumentClass(DocumentClassConstPtr);
159 /// List of modules in use
160 LayoutModuleList const & getModules() const { return layout_modules_; }
161 /// List of default modules the user has removed
162 std::list<std::string> const & getRemovedModules() const
163 { return removed_modules_; }
165 /// Add a module to the list of modules in use. This checks only that the
166 /// module is not already in the list, so use layoutModuleCanBeAdeed first
167 /// if you want to check for compatibility.
168 /// \return true if module was successfully added.
169 bool addLayoutModule(std::string const & modName);
170 /// checks to make sure module's requriements are satisfied, that it does
171 /// not conflict with already-present modules, isn't already loaded, etc.
172 bool layoutModuleCanBeAdded(std::string const & modName) const;
174 void addRemovedModule(std::string const & modName)
175 { removed_modules_.push_back(modName); }
177 void clearLayoutModules() { layout_modules_.clear(); }
178 /// Clear the removed module list
179 void clearRemovedModules() { removed_modules_.clear(); }
180 /// Get the local layouts
181 docstring getLocalLayout(bool forced) const;
182 /// Set the local layouts
183 void setLocalLayout(docstring const & layout, bool forced);
185 /// returns \c true if the buffer contains a LaTeX document
186 bool isLatex() const;
187 /// returns \c true if the buffer contains a Wed document
188 bool isLiterate() const;
190 /// return the format of the buffer on a string
191 std::string bufferFormat() const;
192 /// return the default output format of the current backend
193 std::string getDefaultOutputFormat() const;
194 /// return the output flavor of \p format or the default
195 OutputParams::FLAVOR getOutputFlavor(
196 std::string const & format = std::string()) const;
198 bool isExportable(std::string const & format, bool need_viewable) const;
200 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
201 /// the backends appropriate for use with this document.
202 /// so, e.g., latex is excluded , if we're using non-TeX fonts
203 std::vector<std::string> backends() const;
205 /// List of included children (for includeonly)
206 std::list<std::string> const & getIncludedChildren() const
207 { return included_children_; }
209 void addIncludedChildren(std::string const & child)
210 { included_children_.push_back(child); }
211 /// Clear the list of included children
212 void clearIncludedChildren() { included_children_.clear(); }
214 /// update aux files of unincluded children (with \includeonly)
215 enum ChildrenMaintenance {
220 ChildrenMaintenance maintain_unincluded_children;
222 /// returns the main font for the buffer (document)
223 Font const getFont() const;
225 /// translate quote style string to enum value
226 InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
228 /* these are for the PaperLayout */
230 PAPER_SIZE papersize;
232 PAPER_ORIENTATION orientation;
233 /// use custom margins
236 std::string paperwidth;
238 std::string paperheight;
240 std::string leftmargin;
242 std::string topmargin;
244 std::string rightmargin;
246 std::string bottommargin;
248 std::string headheight;
252 std::string footskip;
254 std::string columnsep;
256 /* some LaTeX options */
257 /// The graphics driver
258 std::string graphics_driver;
259 /// The default output format
260 std::string default_output_format;
261 /// customized bibliography processor
262 std::string bibtex_command;
263 /// customized index processor
264 std::string index_command;
265 /// font encoding(s) requested for this document
267 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
268 std::string fonts_roman[2];
270 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
271 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
272 std::string fonts_sans[2];
274 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
275 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
276 std::string fonts_typewriter[2];
278 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
279 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
280 std::string fonts_math[2];
282 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
283 /// the default family (rm, sf, tt)
284 std::string fonts_default_family;
285 /// use the fonts of the OS (OpenType, True Type) directly
287 /// use expert Small Caps
288 bool fonts_expert_sc;
289 /// use Old Style Figures (rm)
290 bool fonts_roman_osf;
291 /// use Old Style Figures (sf)
293 /// use Old Style Figures (tt)
294 bool fonts_typewriter_osf;
295 /// the options for the roman font
296 std::string font_roman_opts;
297 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
298 int fonts_sans_scale[2];
299 /// the scale factor of the sf font
300 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
301 // the options for the sans font
302 std::string font_sans_opts;
303 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
304 int fonts_typewriter_scale[2];
305 /// the scale factor of the tt font
306 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
307 // the options for the typewriter font
308 std::string font_typewriter_opts;
309 /// the font used by the CJK command
310 std::string fonts_cjk;
311 /// use LaTeX microtype package
313 /// use font ligatures for en- and em-dashes
314 bool use_dash_ligatures;
317 Spacing const & spacing() const;
323 Language const * language;
325 std::string lang_package;
327 BranchList & branchlist();
328 BranchList const & branchlist() const;
330 IndicesList & indiceslist();
331 IndicesList const & indiceslist() const;
333 * The LyX name of the input encoding for LaTeX. This can be one of
334 * - \c auto: find out the input encoding from the used languages
335 * - \c default: ditto
336 * - any encoding defined in the file lib/encodings
337 * The encoding of the LyX file is always utf8 and has nothing to
338 * do with this setting.
339 * The difference between \c auto and \c default is that \c auto also
340 * causes loading of the inputenc package and writes a \inputenc{} command
341 * to the file when switching to another encoding, while \c default does not.
342 * \c default will not work unless the user takes additional measures
343 * (such as using special environments like the CJK environment from
345 * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
346 * does not interpret it in any way apart from display on screen.
348 std::string inputenc;
349 /// The main encoding used by this buffer for LaTeX output.
350 /// If the main encoding is \c auto or \c default,
351 /// individual pieces of text can use different encodings.
352 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
353 /// instead of the value returned by this function (cf. #10600).
354 Encoding const & encoding() const;
361 /// use the class options defined in the layout?
362 bool use_default_options;
368 std::string float_placement;
370 std::string float_alignment;
372 unsigned int columns;
375 /// parameters for the listings package
376 std::string listings_params;
380 std::string pagestyle;
382 std::string tablestyle;
384 RGBColor backgroundcolor;
386 bool isbackgroundcolor;
392 RGBColor notefontcolor;
395 /// \param index should lie in the range 0 <= \c index <= 3.
396 Bullet & temp_bullet(size_type index);
397 Bullet const & temp_bullet(size_type index) const;
398 /// \param index should lie in the range 0 <= \c index <= 3.
399 Bullet & user_defined_bullet(size_type index);
400 Bullet const & user_defined_bullet(size_type index) const;
402 /// Whether to load a package such as amsmath or esint.
403 /// The enum values must not be changed (file format!)
405 /// Don't load the package. For experts only.
407 /// Load the package if needed (recommended)
409 /// Always load the package (e.g. if the document contains
410 /// some ERT that needs the package)
413 /// Whether to load a package such as amsmath or esint.
414 Package use_package(std::string const & p) const;
415 /// Set whether to load a package such as amsmath or esint.
416 void use_package(std::string const & p, Package u);
417 /// All packages that can be switched on or off
418 static std::map<std::string, std::string> const & auto_packages();
419 /// Do we use the bibtopic package?
420 bool useBibtopic() const;
421 /// Split bibliography?
422 bool splitbib() const { return use_bibtopic; }
423 /// Set split bibliography
424 void splitbib(bool const b) { use_bibtopic = b; }
425 /// Do we have multiple bibliographies (by chapter etc.)?
426 std::string multibib;
429 /// Save transient properties?
430 bool save_transient_properties;
431 /// revision tracking for this buffer ? (this is a transient property)
433 /** This param decides whether change tracking marks should be used
434 * in output (irrespective of how these marks are actually defined;
435 * for instance, they may differ for DVI and PDF generation)
436 * This is a transient property.
444 bool postpone_fragile_content;
446 /// the author list for the document
447 AuthorList & authors();
448 AuthorList const & authors() const;
449 void addAuthor(Author a);
451 /// map of the file's author IDs to AuthorList indexes
452 typedef std::map<int, int> AuthorMap;
453 AuthorMap author_map_;
455 /// the buffer's active font encoding
456 std::string const main_font_encoding() const;
457 /// all font encodings requested by the prefs/document/main language.
458 /// This does NOT include font encodings required by secondary languages
459 std::vector<std::string> const font_encodings() const;
462 std::string const dvips_options() const;
463 /** The return value of paperSizeName() depends on the
464 * purpose for which the paper size is needed, since they
465 * support different subsets of paper sizes.
467 enum PapersizePurpose {
476 std::string paperSizeName(PapersizePurpose purpose,
477 std::string const & psize = std::string()) const;
478 /// set up if and how babel is called
479 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
480 /// return supported drivers for specific packages
481 docstring getGraphicsDriver(std::string const & package) const;
482 /// handle inputenc etc.
483 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
485 std::string const parseFontName(std::string const & name) const;
486 /// set up the document fonts
487 std::string const loadFonts(LaTeXFeatures & features) const;
489 /// the cite engine modules
490 std::string const & citeEngine() const { return cite_engine_; }
491 /// the type of cite engine (authoryear or numerical)
492 CiteEngineType const & citeEngineType() const
493 { return cite_engine_type_; }
494 /// add the module to the cite engine modules
495 void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
496 /// set the cite engine type
497 void setCiteEngineType(CiteEngineType const & engine_type)
498 { cite_engine_type_ = engine_type; }
500 /// the available citation commands
501 std::vector<std::string> citeCommands() const;
502 /// the available citation styles
503 std::vector<CitationStyle> citeStyles() const;
505 /// Return the actual bibtex command (lyxrc or buffer param)
506 std::string const bibtexCommand() const;
508 /// Are we using biblatex?
509 bool useBiblatex() const;
511 /// Set the default BibTeX style file for the document
512 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
513 /// Get the default BibTeX style file from the TextClass
514 std::string const & defaultBiblioStyle() const;
515 /// whether the BibTeX style supports full author lists
516 bool const & fullAuthorList() const;
517 /// Check if a citation style is an alias to another style
518 std::string getCiteAlias(std::string const & s) const;
520 /// Options of the bibiography package
521 std::string biblio_opts;
522 /// The biblatex bibliography style
523 std::string biblatex_bibstyle;
524 /// The biblatex citation style
525 std::string biblatex_citestyle;
526 /// Set the bib file encoding (for biblatex)
527 void setBibEncoding(std::string const & s) { bib_encoding = s; }
528 /// Get the bib file encoding (for biblatex)
529 std::string const & bibEncoding() const { return bib_encoding; }
530 /// Set encoding for individual bib file (for biblatex)
531 void setBibFileEncoding(std::string const & file, std::string const & enc);
533 std::string const bibFileEncoding(std::string const & file) const;
535 /// options for pdf output
536 PDFOptions & pdfoptions();
537 PDFOptions const & pdfoptions() const;
539 // do not change these values. we rely upon them.
546 /// what to use for math output. present choices are above
547 MathOutput html_math_output;
548 /// whether to attempt to be XHTML 1.1 compliant or instead be
549 /// a little more mellow
552 double html_math_img_scale;
554 double display_pixel_ratio;
556 std::string html_latex_start;
558 std::string html_latex_end;
560 bool html_css_as_file;
562 // do not change these values. we rely upon them.
567 /// what format to use for table output in DocBook. present choices are above
568 TableOutput docbook_table_output;
570 /// allow the LaTeX backend to run external programs
572 /// generate output usable for reverse/forward search
574 /// custom LaTeX macro from user instead our own
575 std::string output_sync_macro;
576 /// use refstyle? or prettyref?
578 /// use minted? or listings?
580 //output line numbering
582 //optional params for lineno package
583 std::string lineno_opts;
585 /// Return true if language could be set to lang,
586 /// otherwise return false and do not change language
587 bool setLanguage(std::string const & lang);
589 void invalidateConverterCache() const;
590 /// Copies over some of the settings from \param bp,
591 /// namely the ones need by Advanced F&R. We don't want
592 /// to copy them all, e.g., not the default master.
593 void copyForAdvFR(BufferParams const & bp);
597 void readPreamble(Lexer &);
599 void readLocalLayout(Lexer &, bool);
601 void readLanguage(Lexer &);
603 void readGraphicsDriver(Lexer &);
605 void readBullets(Lexer &);
607 void readBulletsLaTeX(Lexer &);
609 void readModules(Lexer &);
611 void readRemovedModules(Lexer &);
613 void readIncludeonly(Lexer &);
614 /// A cache for the default flavors
615 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
617 mutable DefaultFlavorCache default_flavors_;
619 std::string cite_engine_;
620 /// the type of cite engine (authoryear or numerical)
621 CiteEngineType cite_engine_type_;
622 /// the default BibTeX style file for the document
623 std::string biblio_style;
624 /// The main encoding of the bib files, for Biblatex
625 std::string bib_encoding;
626 /// Individual file encodings, for Biblatex
627 std::map<std::string, std::string> bib_encodings;
628 /// Split bibliography?
631 DocumentClassPtr doc_class_;
633 LayoutModuleList layout_modules_;
634 /// this is for modules that are required by the document class but that
635 /// the user has chosen not to use
636 std::list<std::string> removed_modules_;
637 /// The local layouts without the forced ones
638 docstring local_layout_;
639 /// Forced local layouts only for reading (use getLocalLayout() instead)
640 docstring forced_local_layout_;
642 /// the list of included children (for includeonly)
643 std::list<std::string> included_children_;
645 typedef std::map<std::string, Package> PackageMap;
646 /** Whether and how to load packages like amsmath, esint, mhchem,
647 * mathdots, stackrel, stmaryrd and undertilde.
649 PackageMap use_packages;
651 /** Use the Pimpl idiom to hide those member variables that would otherwise
652 * drag in other header files.
657 static Impl * clone(Impl const *);
658 static void destroy(Impl *);
660 support::copied_ptr<Impl, MemoryTraits> pimpl_;