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;
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);
105 /// Whether formulas are indented
108 /// the indentation of formulas
109 std::string math_indentation;
111 /** Whether paragraphs are separated by using a indent like in
112 * articles or by using a little skip like in letters.
114 ParagraphSeparation paragraph_separation;
116 InsetQuotesParams::QuoteStyle quotes_style;
120 std::string fontsize;
121 /// Get the LayoutFile this document is using.
122 LayoutFile const * baseClass() const;
124 LayoutFileIndex const & baseClassID() const;
125 /// Set the LyX layout file this document is using.
126 /// NOTE: This does not call makeDocumentClass() to update the local
127 /// DocumentClass. That needs to be done manually.
128 /// \param classname: the name of the layout file
129 bool setBaseClass(std::string const & classname);
130 /// Adds the module information to the baseClass information to
131 /// create our local DocumentClass.
132 /// NOTE: This should NEVER be called externally unless one immediately goes
133 /// on to class BufferView::updateDocumentClass(). The exception, of course,
134 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
135 /// the parameters from the active Buffer.
136 void makeDocumentClass(bool const clone = false);
137 /// Returns the DocumentClass currently in use: the BaseClass as modified
139 DocumentClass const & documentClass() const;
140 /// \return A pointer to the DocumentClass currently in use: the BaseClass
141 /// as modified by modules.
142 DocumentClassConstPtr documentClassPtr() const;
143 /// This bypasses the baseClass and sets the textClass directly.
144 /// Should be called with care and would be better not being here,
145 /// but it seems to be needed by CutAndPaste::putClipboard().
146 void setDocumentClass(DocumentClassConstPtr);
147 /// List of modules in use
148 LayoutModuleList const & getModules() const { return layout_modules_; }
149 /// List of default modules the user has removed
150 std::list<std::string> const & getRemovedModules() const
151 { return removed_modules_; }
153 /// Add a module to the list of modules in use. This checks only that the
154 /// module is not already in the list, so use layoutModuleCanBeAdeed first
155 /// if you want to check for compatibility.
156 /// \return true if module was successfully added.
157 bool addLayoutModule(std::string const & modName);
158 /// checks to make sure module's requriements are satisfied, that it does
159 /// not conflict with already-present modules, isn't already loaded, etc.
160 bool layoutModuleCanBeAdded(std::string const & modName) const;
161 /// same, but for citaton modules.
162 bool citationModuleCanBeAdded(std::string const & modName) const;
164 void addRemovedModule(std::string const & modName)
165 { removed_modules_.push_back(modName); }
167 void clearLayoutModules() { layout_modules_.clear(); }
168 /// Clear the removed module list
169 void clearRemovedModules() { removed_modules_.clear(); }
170 /// Get the local layouts
171 docstring getLocalLayout(bool forced) const;
172 /// Set the local layouts
173 void setLocalLayout(docstring const & layout, bool forced);
175 /// returns \c true if the buffer contains a LaTeX document
176 bool isLatex() const;
177 /// returns \c true if the buffer contains a DocBook document
178 bool isDocBook() const;
179 /// returns \c true if the buffer contains a Wed document
180 bool isLiterate() const;
182 /// return the format of the buffer on a string
183 std::string bufferFormat() const;
184 /// return the default output format of the current backend
185 std::string getDefaultOutputFormat() const;
186 /// return the output flavor of \p format or the default
187 OutputParams::FLAVOR getOutputFlavor(
188 std::string const & format = std::string()) const;
190 bool isExportable(std::string const & format, bool need_viewable) const;
192 std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
193 /// the backends appropriate for use with this document.
194 /// so, e.g., latex is excluded , if we're using non-TeX fonts
195 std::vector<std::string> backends() const;
197 /// List of included children (for includeonly)
198 std::list<std::string> const & getIncludedChildren() const
199 { return included_children_; }
201 void addIncludedChildren(std::string const & child)
202 { included_children_.push_back(child); }
203 /// Clear the list of included children
204 void clearIncludedChildren() { included_children_.clear(); }
206 /// update aux files of unincluded children (with \includeonly)
207 bool maintain_unincluded_children;
209 /// returns the main font for the buffer (document)
210 Font const getFont() const;
212 /// translate quote style string to enum value
213 InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
215 /* these are for the PaperLayout */
217 PAPER_SIZE papersize;
219 PAPER_ORIENTATION orientation;
220 /// use custom margins
223 std::string paperwidth;
225 std::string paperheight;
227 std::string leftmargin;
229 std::string topmargin;
231 std::string rightmargin;
233 std::string bottommargin;
235 std::string headheight;
239 std::string footskip;
241 std::string columnsep;
243 /* some LaTeX options */
244 /// The graphics driver
245 std::string graphics_driver;
246 /// The default output format
247 std::string default_output_format;
248 /// customized bibliography processor
249 std::string bibtex_command;
250 /// customized index processor
251 std::string index_command;
252 /// font encoding(s) requested for this document
254 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
255 std::string fonts_roman[2];
257 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
258 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
259 std::string fonts_sans[2];
261 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
262 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
263 std::string fonts_typewriter[2];
265 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
266 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
267 std::string fonts_math[2];
269 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
270 /// the default family (rm, sf, tt)
271 std::string fonts_default_family;
272 /// use the fonts of the OS (OpenType, True Type) directly
274 /// use expert Small Caps
275 bool fonts_expert_sc;
276 /// use Old Style Figures
277 bool fonts_old_figures;
278 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
279 int fonts_sans_scale[2];
280 /// the scale factor of the sf font
281 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
282 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
283 int fonts_typewriter_scale[2];
284 /// the scale factor of the tt font
285 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
286 /// the font used by the CJK command
287 std::string fonts_cjk;
288 /// use LaTeX microtype package
290 /// use font ligatures for en- and em-dashes
291 bool use_dash_ligatures;
294 Spacing const & spacing() const;
300 Language const * language;
302 std::string lang_package;
304 BranchList & branchlist();
305 BranchList const & branchlist() const;
307 IndicesList & indiceslist();
308 IndicesList const & indiceslist() const;
310 * The LyX name of the input encoding for LaTeX. This can be one of
311 * - \c auto: find out the input encoding from the used languages
312 * - \c default: ditto
313 * - any encoding defined in the file lib/encodings
314 * The encoding of the LyX file is always utf8 and has nothing to
315 * do with this setting.
316 * The difference between \c auto and \c default is that \c auto also
317 * causes loading of the inputenc package, while \c default does not.
318 * \c default will not work unless the user takes additional measures
319 * (such as using special environments like the CJK environment from
321 * \c default can be seen as an unspecified 8bit encoding, since LyX
322 * does not interpret it in any way apart from display on screen.
324 std::string inputenc;
325 /// The main encoding used by this buffer for LaTeX output.
326 /// Individual pieces of text can use different encodings.
327 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
328 /// instead of the value returned by this function.
329 Encoding const & encoding() const;
336 /// use the class options defined in the layout?
337 bool use_default_options;
343 std::string float_placement;
345 unsigned int columns;
348 /// parameters for the listings package
349 std::string listings_params;
353 std::string pagestyle;
355 RGBColor backgroundcolor;
357 bool isbackgroundcolor;
363 RGBColor notefontcolor;
366 /// \param index should lie in the range 0 <= \c index <= 3.
367 Bullet & temp_bullet(size_type index);
368 Bullet const & temp_bullet(size_type index) const;
369 /// \param index should lie in the range 0 <= \c index <= 3.
370 Bullet & user_defined_bullet(size_type index);
371 Bullet const & user_defined_bullet(size_type index) const;
373 /// Whether to load a package such as amsmath or esint.
374 /// The enum values must not be changed (file format!)
376 /// Don't load the package. For experts only.
378 /// Load the package if needed (recommended)
380 /// Always load the package (e.g. if the document contains
381 /// some ERT that needs the package)
384 /// Whether to load a package such as amsmath or esint.
385 Package use_package(std::string const & p) const;
386 /// Set whether to load a package such as amsmath or esint.
387 void use_package(std::string const & p, Package u);
388 /// All packages that can be switched on or off
389 static std::map<std::string, std::string> const & auto_packages();
390 /// Do we use the bibtopic package?
391 bool useBibtopic() const;
392 /// Split bibliography?
393 bool splitbib() const { return use_bibtopic; }
394 /// Set split bibliography
395 void splitbib(bool const b) { use_bibtopic = b; }
396 /// Do we have multiple bibliographies (by chapter etc.)?
397 std::string multibib;
400 /// Save transient properties?
401 bool save_transient_properties;
402 /// revision tracking for this buffer ? (this is a transient property)
404 /** This param decides whether change tracking marks should be used
405 * in output (irrespective of how these marks are actually defined;
406 * for instance, they may differ for DVI and PDF generation)
407 * This is a transient property.
413 /// the author list for the document
414 AuthorList & authors();
415 AuthorList const & authors() const;
416 void addAuthor(Author a);
418 /// map of the file's author IDs to AuthorList indexes
419 typedef std::map<int, int> AuthorMap;
420 AuthorMap author_map_;
422 /// the buffer's active font encoding
423 std::string const main_font_encoding() const;
424 /// all font encodings requested by the prefs/document/main language.
425 /// This does NOT include font encodings required by secondary languages
426 std::vector<std::string> const font_encodings() const;
429 std::string const dvips_options() const;
430 /** The return value of paperSizeName() depends on the
431 * purpose for which the paper size is needed, since they
432 * support different subsets of paper sizes.
434 enum PapersizePurpose {
443 std::string paperSizeName(PapersizePurpose purpose) const;
444 /// set up if and how babel is called
445 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
446 /// return supported drivers for specific packages
447 docstring getGraphicsDriver(std::string const & package) const;
448 /// handle inputenc etc.
449 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
451 std::string const parseFontName(std::string const & name) const;
452 /// set up the document fonts
453 std::string const loadFonts(LaTeXFeatures & features) const;
455 /// the cite engine modules
456 LayoutModuleList const & citeEngine() const
457 { return cite_engine_; }
458 /// the type of cite engine (authoryear or numerical)
459 CiteEngineType const & citeEngineType() const
460 { return cite_engine_type_; }
461 /// add the module to the cite engine modules
462 bool addCiteEngine(std::string const &);
463 /// add the modules to the cite engine modules
464 bool addCiteEngine(std::vector<std::string> const &);
465 /// clear the list of cite engine modules
466 void clearCiteEngine() { cite_engine_.clear(); }
467 /// set the cite engine module
468 void setCiteEngine(std::string const &);
469 /// set the cite engine modules
470 void setCiteEngine(std::vector<std::string> const &);
471 /// set the cite engine type
472 void setCiteEngineType(CiteEngineType const & engine_type)
473 { cite_engine_type_ = engine_type; }
475 /// the available citation commands
476 std::vector<std::string> citeCommands() const;
477 /// the available citation styles
478 std::vector<CitationStyle> citeStyles() const;
480 /// Return the actual bibtex command (lyxrc or buffer param)
481 std::string const bibtexCommand() const;
483 /// Are we using biblatex?
484 bool useBiblatex() const;
486 /// Set the default BibTeX style file for the document
487 void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
488 /// Get the default BibTeX style file from the TextClass
489 std::string const & defaultBiblioStyle() const;
490 /// whether the BibTeX style supports full author lists
491 bool const & fullAuthorList() const;
492 /// Check if a citation style is an alias to another style
493 std::string getCiteAlias(std::string const & s) const;
495 /// Options of the bibiography package
496 std::string biblio_opts;
497 /// The biblatex bibliography style
498 std::string biblatex_bibstyle;
499 /// The biblatex citation style
500 std::string biblatex_citestyle;
502 /// options for pdf output
503 PDFOptions & pdfoptions();
504 PDFOptions const & pdfoptions() const;
506 // do not change these values. we rely upon them.
513 /// what to use for math output. present choices are above
514 MathOutput html_math_output;
515 /// whether to attempt to be XHTML 1.1 compliant or instead be
516 /// a little more mellow
519 double html_math_img_scale;
521 double display_pixel_ratio;
523 std::string html_latex_start;
525 std::string html_latex_end;
527 bool html_css_as_file;
528 /// generate output usable for reverse/forward search
530 /// custom LaTeX macro from user instead our own
531 std::string output_sync_macro;
532 /// use refstyle? or prettyref?
535 /// Return true if language could be set to lang,
536 /// otherwise return false and do not change language
537 bool setLanguage(std::string const & lang);
539 void invalidateConverterCache() const;
543 void readPreamble(Lexer &);
545 void readLocalLayout(Lexer &, bool);
547 void readLanguage(Lexer &);
549 void readGraphicsDriver(Lexer &);
551 void readBullets(Lexer &);
553 void readBulletsLaTeX(Lexer &);
555 void readModules(Lexer &);
557 void readRemovedModules(Lexer &);
559 void readIncludeonly(Lexer &);
560 /// A cache for the default flavors
561 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
563 mutable DefaultFlavorCache default_flavors_;
564 /// the cite engine modules
565 LayoutModuleList cite_engine_;
566 /// the type of cite engine (authoryear or numerical)
567 CiteEngineType cite_engine_type_;
568 /// the default BibTeX style file for the document
569 std::string biblio_style;
570 /// Split bibliography?
573 DocumentClassPtr doc_class_;
575 LayoutModuleList layout_modules_;
576 /// this is for modules that are required by the document class but that
577 /// the user has chosen not to use
578 std::list<std::string> removed_modules_;
579 /// The local layouts without the forced ones
580 docstring local_layout_;
581 /// Forced local layouts only for reading (use getLocalLayout() instead)
582 docstring forced_local_layout_;
584 /// the list of included children (for includeonly)
585 std::list<std::string> included_children_;
587 typedef std::map<std::string, Package> PackageMap;
588 /** Whether and how to load packages like amsmath, esint, mhchem,
589 * mathdots, stackrel, stmaryrd and undertilde.
591 PackageMap use_packages;
593 /** Use the Pimpl idiom to hide those member variables that would otherwise
594 * drag in other header files.
599 static Impl * clone(Impl const *);
600 static void destroy(Impl *);
602 support::copied_ptr<Impl, MemoryTraits> pimpl_;