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; }
46 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 HSpace const & getIndentation() const;
98 void setIndentation(HSpace const & indent);
100 VSpace const & getDefSkip() const;
102 void setDefSkip(VSpace const & vs);
104 /** Whether paragraphs are separated by using a indent like in
105 * articles or by using a little skip like in letters.
107 ParagraphSeparation paragraph_separation;
109 InsetQuotesParams::QuoteStyle quotes_style;
113 std::string fontsize;
114 /// Get the LayoutFile this document is using.
115 LayoutFile const * baseClass() const;
117 LayoutFileIndex const & baseClassID() const;
118 /// Set the LyX layout file this document is using.
119 /// NOTE: This does not call makeDocumentClass() to update the local
120 /// DocumentClass. That needs to be done manually.
121 /// \param classname: the name of the layout file
122 bool setBaseClass(std::string const & classname);
123 /// Adds the module information to the baseClass information to
124 /// create our local DocumentClass.
125 /// NOTE: This should NEVER be called externally unless one immediately goes
126 /// on to class BufferView::updateDocumentClass(). The exception, of course,
127 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
128 /// the parameters from the active Buffer.
129 void makeDocumentClass(bool const clone = false);
130 /// Returns the DocumentClass currently in use: the BaseClass as modified
132 DocumentClass const & documentClass() const;
133 /// \return A pointer to the DocumentClass currently in use: the BaseClass
134 /// as modified by modules.
135 DocumentClassConstPtr documentClassPtr() const;
136 /// This bypasses the baseClass and sets the textClass directly.
137 /// Should be called with care and would be better not being here,
138 /// but it seems to be needed by CutAndPaste::putClipboard().
139 void setDocumentClass(DocumentClassConstPtr);
140 /// List of modules in use
141 LayoutModuleList const & getModules() const { return layout_modules_; }
142 /// List of default modules the user has removed
143 std::list<std::string> const & getRemovedModules() const
144 { return removed_modules_; }
146 /// Add a module to the list of modules in use. This checks only that the
147 /// module is not already in the list, so use layoutModuleCanBeAdeed first
148 /// if you want to check for compatibility.
149 /// \return true if module was successfully added.
150 bool addLayoutModule(std::string const & modName);
151 /// checks to make sure module's requriements are satisfied, that it does
152 /// not conflict with already-present modules, isn't already loaded, etc.
153 bool layoutModuleCanBeAdded(std::string const & modName) const;
154 /// same, but for citaton modules.
155 bool citationModuleCanBeAdded(std::string const & modName) const;
157 void addRemovedModule(std::string const & modName)
158 { removed_modules_.push_back(modName); }
160 void clearLayoutModules() { layout_modules_.clear(); }
161 /// Clear the removed module list
162 void clearRemovedModules() { removed_modules_.clear(); }
163 /// Get the local layouts
164 docstring getLocalLayout(bool forced) const;
165 /// Set the local layouts
166 void setLocalLayout(docstring const & layout, bool forced);
168 /// returns \c true if the buffer contains a LaTeX document
169 bool isLatex() const;
170 /// returns \c true if the buffer contains a DocBook document
171 bool isDocBook() const;
172 /// returns \c true if the buffer contains a Wed document
173 bool isLiterate() const;
175 /// return the format of the buffer on a string
176 std::string bufferFormat() const;
177 /// return the default output format of the current backend
178 std::string getDefaultOutputFormat() const;
179 /// return the output flavor of \p format or the default
180 OutputParams::FLAVOR getOutputFlavor(
181 std::string const & format = std::string()) const;
183 bool isExportable(std::string const & format, bool need_viewable) const;
185 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
186 /// the backends appropriate for use with this document.
187 /// so, e.g., latex is excluded , if we're using non-TeX fonts
188 std::vector<std::string> backends() const;
190 /// List of included children (for includeonly)
191 std::list<std::string> const & getIncludedChildren() const
192 { return included_children_; }
194 void addIncludedChildren(std::string const & child)
195 { included_children_.push_back(child); }
196 /// Clear the list of included children
197 void clearIncludedChildren() { included_children_.clear(); }
199 /// update aux files of unincluded children (with \includeonly)
200 bool maintain_unincluded_children;
202 /// returns the main font for the buffer (document)
203 Font const getFont() const;
205 /// translate quote style string to enum value
206 InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
208 /* these are for the PaperLayout */
210 PAPER_SIZE papersize;
212 PAPER_ORIENTATION orientation;
213 /// use custom margins
216 std::string paperwidth;
218 std::string paperheight;
220 std::string leftmargin;
222 std::string topmargin;
224 std::string rightmargin;
226 std::string bottommargin;
228 std::string headheight;
232 std::string footskip;
234 std::string columnsep;
236 /* some LaTeX options */
237 /// The graphics driver
238 std::string graphics_driver;
239 /// The default output format
240 std::string default_output_format;
241 /// customized bibliography processor
242 std::string bibtex_command;
243 /// customized index processor
244 std::string index_command;
245 /// font encoding(s) requested for this document
247 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
248 std::string fonts_roman[2];
250 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
251 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
252 std::string fonts_sans[2];
254 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
255 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
256 std::string fonts_typewriter[2];
258 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
259 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
260 std::string fonts_math[2];
262 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
263 /// the default family (rm, sf, tt)
264 std::string fonts_default_family;
265 /// use the fonts of the OS (OpenType, True Type) directly
267 /// use expert Small Caps
268 bool fonts_expert_sc;
269 /// use Old Style Figures
270 bool fonts_old_figures;
271 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
272 int fonts_sans_scale[2];
273 /// the scale factor of the sf font
274 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
275 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
276 int fonts_typewriter_scale[2];
277 /// the scale factor of the tt font
278 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
279 /// the font used by the CJK command
280 std::string fonts_cjk;
281 /// use LaTeX microtype package
283 /// use font ligatures for en- and em-dashes
284 bool use_dash_ligatures;
287 Spacing const & spacing() const;
293 Language const * language;
295 std::string lang_package;
297 BranchList & branchlist();
298 BranchList const & branchlist() const;
300 IndicesList & indiceslist();
301 IndicesList const & indiceslist() const;
303 * The LyX name of the input encoding for LaTeX. This can be one of
304 * - \c auto: find out the input encoding from the used languages
305 * - \c default: ditto
306 * - any encoding defined in the file lib/encodings
307 * The encoding of the LyX file is always utf8 and has nothing to
308 * do with this setting.
309 * The difference between \c auto and \c default is that \c auto also
310 * causes loading of the inputenc package, while \c default does not.
311 * \c default will not work unless the user takes additional measures
312 * (such as using special environments like the CJK environment from
314 * \c default can be seen as an unspecified 8bit encoding, since LyX
315 * does not interpret it in any way apart from display on screen.
317 std::string inputenc;
318 /// The main encoding used by this buffer for LaTeX output.
319 /// Individual pieces of text can use different encodings.
320 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
321 /// instead of the value returned by this function.
322 Encoding const & encoding() const;
329 /// use the class options defined in the layout?
330 bool use_default_options;
336 std::string float_placement;
338 unsigned int columns;
341 /// parameters for the listings package
342 std::string listings_params;
346 std::string pagestyle;
348 RGBColor backgroundcolor;
350 bool isbackgroundcolor;
356 RGBColor notefontcolor;
359 /// \param index should lie in the range 0 <= \c index <= 3.
360 Bullet & temp_bullet(size_type index);
361 Bullet const & temp_bullet(size_type index) const;
362 /// \param index should lie in the range 0 <= \c index <= 3.
363 Bullet & user_defined_bullet(size_type index);
364 Bullet const & user_defined_bullet(size_type index) const;
366 /// Whether to load a package such as amsmath or esint.
367 /// The enum values must not be changed (file format!)
369 /// Don't load the package. For experts only.
371 /// Load the package if needed (recommended)
373 /// Always load the package (e.g. if the document contains
374 /// some ERT that needs the package)
377 /// Whether to load a package such as amsmath or esint.
378 Package use_package(std::string const & p) const;
379 /// Set whether to load a package such as amsmath or esint.
380 void use_package(std::string const & p, Package u);
381 /// All packages that can be switched on or off
382 static std::map<std::string, std::string> const & auto_packages();
383 /// Do we use the bibtopic package?
384 bool useBibtopic() const;
385 /// Split bibliography?
386 bool splitbib() const { return use_bibtopic; }
387 /// Set split bibliography
388 void splitbib(bool const b) { use_bibtopic = b; }
389 /// Do we have multiple bibliographies (by chapter etc.)?
390 std::string multibib;
393 /// Save transient properties?
394 bool save_transient_properties;
395 /// revision tracking for this buffer ? (this is a transient property)
397 /** This param decides whether change tracking marks should be used
398 * in output (irrespective of how these marks are actually defined;
399 * for instance, they may differ for DVI and PDF generation)
400 * This is a transient property.
406 /// the author list for the document
407 AuthorList & authors();
408 AuthorList const & authors() const;
409 void addAuthor(Author a);
411 /// map of the file's author IDs to AuthorList indexes
412 typedef std::map<int, int> AuthorMap;
413 AuthorMap author_map_;
415 /// the buffer's active font encoding
416 std::string const main_font_encoding() const;
417 /// all font encodings requested by the prefs/document/main language.
418 /// This does NOT include font encodings required by secondary languages
419 std::vector<std::string> const font_encodings() const;
422 std::string const dvips_options() const;
423 /** The return value of paperSizeName() depends on the
424 * purpose for which the paper size is needed, since they
425 * support different subsets of paper sizes.
427 enum PapersizePurpose {
436 std::string paperSizeName(PapersizePurpose purpose) const;
437 /// set up if and how babel is called
438 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
439 /// return supported drivers for specific packages
440 docstring getGraphicsDriver(std::string const & package) const;
441 /// handle inputenc etc.
442 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
444 std::string const parseFontName(std::string const & name) const;
445 /// set up the document fonts
446 std::string const loadFonts(LaTeXFeatures & features) const;
448 /// the cite engine modules
449 LayoutModuleList const & citeEngine() const
450 { return cite_engine_; }
451 /// the type of cite engine (authoryear or numerical)
452 CiteEngineType const & citeEngineType() const
453 { return cite_engine_type_; }
454 /// add the module to the cite engine modules
455 bool addCiteEngine(std::string const &);
456 /// add the modules to the cite engine modules
457 bool addCiteEngine(std::vector<std::string> const &);
458 /// clear the list of cite engine modules
459 void clearCiteEngine() { cite_engine_.clear(); }
460 /// set the cite engine module
461 void setCiteEngine(std::string const &);
462 /// set the cite engine modules
463 void setCiteEngine(std::vector<std::string> const &);
464 /// set the cite engine type
465 void setCiteEngineType(CiteEngineType const & engine_type)
466 { cite_engine_type_ = engine_type; }
468 /// the available citation commands
469 std::vector<std::string> citeCommands() const;
470 /// the available citation styles
471 std::vector<CitationStyle> citeStyles() const;
473 /// Return the actual bibtex command (lyxrc or buffer param)
474 std::string const bibtexCommand() const;
476 /// Are we using biblatex?
477 bool useBiblatex() const;
479 /// Set the default BibTeX style file for the document
480 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
481 /// Get the default BibTeX style file from the TextClass
482 std::string const & defaultBiblioStyle() const;
483 /// whether the BibTeX style supports full author lists
484 bool const & fullAuthorList() const;
485 /// Check if a citation style is an alias to another style
486 std::string getCiteAlias(std::string const & s) const;
488 /// Options of the bibiography package
489 std::string biblio_opts;
490 /// The biblatex bibliography style
491 std::string biblatex_bibstyle;
492 /// The biblatex citation style
493 std::string biblatex_citestyle;
495 /// options for pdf output
496 PDFOptions & pdfoptions();
497 PDFOptions const & pdfoptions() const;
499 // do not change these values. we rely upon them.
506 /// what to use for math output. present choices are above
507 MathOutput html_math_output;
508 /// whether to attempt to be XHTML 1.1 compliant or instead be
509 /// a little more mellow
512 double html_math_img_scale;
514 double display_pixel_ratio;
516 std::string html_latex_start;
518 std::string html_latex_end;
520 bool html_css_as_file;
521 /// generate output usable for reverse/forward search
523 /// custom LaTeX macro from user instead our own
524 std::string output_sync_macro;
525 /// use refstyle? or prettyref?
528 /// Return true if language could be set to lang,
529 /// otherwise return false and do not change language
530 bool setLanguage(std::string const & lang);
532 void invalidateConverterCache() const;
536 void readPreamble(Lexer &);
538 void readLocalLayout(Lexer &, bool);
540 void readLanguage(Lexer &);
542 void readGraphicsDriver(Lexer &);
544 void readBullets(Lexer &);
546 void readBulletsLaTeX(Lexer &);
548 void readModules(Lexer &);
550 void readRemovedModules(Lexer &);
552 void readIncludeonly(Lexer &);
553 /// A cache for the default flavors
554 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
556 mutable DefaultFlavorCache default_flavors_;
557 /// the cite engine modules
558 LayoutModuleList cite_engine_;
559 /// the type of cite engine (authoryear or numerical)
560 CiteEngineType cite_engine_type_;
561 /// the default BibTeX style file for the document
562 std::string biblio_style;
563 /// Split bibliography?
566 DocumentClassPtr doc_class_;
568 LayoutModuleList layout_modules_;
569 /// this is for modules that are required by the document class but that
570 /// the user has chosen not to use
571 std::list<std::string> removed_modules_;
572 /// The local layouts without the forced ones
573 docstring local_layout_;
574 /// Forced local layouts only for reading (use getLocalLayout() instead)
575 docstring forced_local_layout_;
577 /// the list of included children (for includeonly)
578 std::list<std::string> included_children_;
580 typedef std::map<std::string, Package> PackageMap;
581 /** Whether and how to load packages like amsmath, esint, mhchem,
582 * mathdots, stackrel, stmaryrd and undertilde.
584 PackageMap use_packages;
586 /** Use the Pimpl idiom to hide those member variables that would otherwise
587 * drag in other header files.
592 static Impl * clone(Impl const *);
593 static void destroy(Impl *);
595 support::copied_ptr<Impl, MemoryTraits> pimpl_;