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