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