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; }
47 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 HSpace const & getIndentation() const;
99 void setIndentation(HSpace const & indent);
101 VSpace const & getDefSkip() const;
103 void setDefSkip(VSpace const & vs);
105 /** Whether paragraphs are separated by using a indent like in
106 * articles or by using a little skip like in letters.
108 ParagraphSeparation paragraph_separation;
110 InsetQuotes::QuoteLanguage quotes_language;
112 std::string fontsize;
113 /// Get the LayoutFile this document is using.
114 LayoutFile const * baseClass() const;
116 LayoutFileIndex const & baseClassID() const;
117 /// Set the LyX layout file this document is using.
118 /// NOTE: This does not call makeDocumentClass() to update the local
119 /// DocumentClass. That needs to be done manually.
120 /// \param classname: the name of the layout file
121 bool setBaseClass(std::string const & classname);
122 /// Adds the module information to the baseClass information to
123 /// create our local DocumentClass.
124 /// NOTE: This should NEVER be called externally unless one immediately goes
125 /// on to class BufferView::updateDocumentClass(). The exception, of course,
126 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
127 /// the parameters from the active Buffer.
128 void makeDocumentClass(bool const clone = false);
129 /// Returns the DocumentClass currently in use: the BaseClass as modified
131 DocumentClass const & documentClass() const;
132 /// \return A pointer to the DocumentClass currently in use: the BaseClass
133 /// as modified by modules.
134 DocumentClassConstPtr documentClassPtr() const;
135 /// This bypasses the baseClass and sets the textClass directly.
136 /// Should be called with care and would be better not being here,
137 /// but it seems to be needed by CutAndPaste::putClipboard().
138 void setDocumentClass(DocumentClassConstPtr);
139 /// List of modules in use
140 LayoutModuleList const & getModules() const { return layout_modules_; }
141 /// List of default modules the user has removed
142 std::list<std::string> const & getRemovedModules() const
143 { return removed_modules_; }
145 /// Add a module to the list of modules in use. This checks only that the
146 /// module is not already in the list, so use layoutModuleCanBeAdeed first
147 /// if you want to check for compatibility.
148 /// \return true if module was successfully added.
149 bool addLayoutModule(std::string const & modName);
150 /// checks to make sure module's requriements are satisfied, that it does
151 /// not conflict with already-present modules, isn't already loaded, etc.
152 bool layoutModuleCanBeAdded(std::string const & modName) const;
153 /// same, but for citaton modules.
154 bool citationModuleCanBeAdded(std::string const & modName) const;
156 void addRemovedModule(std::string const & modName)
157 { removed_modules_.push_back(modName); }
159 void clearLayoutModules() { layout_modules_.clear(); }
160 /// Clear the removed module list
161 void clearRemovedModules() { removed_modules_.clear(); }
162 /// Get the local layouts
163 std::string getLocalLayout(bool) const;
164 /// Set the local layouts
165 void setLocalLayout(std::string const &, bool);
167 /// returns \c true if the buffer contains a LaTeX document
168 bool isLatex() const;
169 /// returns \c true if the buffer contains a DocBook document
170 bool isDocBook() const;
171 /// returns \c true if the buffer contains a Wed document
172 bool isLiterate() const;
174 /// return the format of the buffer on a string
175 std::string bufferFormat() const;
176 /// return the default output format of the current backend
177 std::string getDefaultOutputFormat() const;
178 /// return the output flavor of \p format or the default
179 OutputParams::FLAVOR getOutputFlavor(
180 std::string const & format = std::string()) const;
182 bool isExportable(std::string const & format) const;
184 std::vector<Format const *> exportableFormats(bool only_viewable) const;
186 bool isExportableFormat(std::string const & format) const;
187 /// the backends appropriate for use with this document.
188 /// so, e.g., latex is excluded , if we're using non-TeX fonts
189 std::vector<std::string> backends() const;
191 /// List of included children (for includeonly)
192 std::list<std::string> const & getIncludedChildren() const
193 { return included_children_; }
195 void addIncludedChildren(std::string const & child)
196 { included_children_.push_back(child); }
197 /// Clear the list of included children
198 void clearIncludedChildren() { included_children_.clear(); }
200 /// update aux files of unincluded children (with \includeonly)
201 bool maintain_unincluded_children;
203 /// returns the main font for the buffer (document)
204 Font const getFont() const;
206 /// translate quote style string to enum value
207 InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
209 /* these are for the PaperLayout */
211 PAPER_SIZE papersize;
213 PAPER_ORIENTATION orientation;
214 /// use custom margins
217 std::string paperwidth;
219 std::string paperheight;
221 std::string leftmargin;
223 std::string topmargin;
225 std::string rightmargin;
227 std::string bottommargin;
229 std::string headheight;
233 std::string footskip;
235 std::string columnsep;
237 /* some LaTeX options */
238 /// The graphics driver
239 std::string graphics_driver;
240 /// The default output format
241 std::string default_output_format;
242 /// customized bibliography processor
243 std::string bibtex_command;
244 /// customized index processor
245 std::string index_command;
246 /// font encoding(s) requested for this document
248 /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
249 std::string fonts_roman[2];
251 std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
252 /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
253 std::string fonts_sans[2];
255 std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
256 /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
257 std::string fonts_typewriter[2];
259 std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
260 /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
261 std::string fonts_math[2];
263 std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
264 /// the default family (rm, sf, tt)
265 std::string fonts_default_family;
266 /// use the fonts of the OS (OpenType, True Type) directly
268 /// use expert Small Caps
269 bool fonts_expert_sc;
270 /// use Old Style Figures
271 bool fonts_old_figures;
272 /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
273 int fonts_sans_scale[2];
274 /// the scale factor of the sf font
275 int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
276 /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
277 int fonts_typewriter_scale[2];
278 /// the scale factor of the tt font
279 int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
280 /// the font used by the CJK command
281 std::string fonts_cjk;
284 Spacing const & spacing() const;
290 Language const * language;
292 std::string lang_package;
294 BranchList & branchlist();
295 BranchList const & branchlist() const;
297 IndicesList & indiceslist();
298 IndicesList const & indiceslist() const;
300 * The LyX name of the input encoding for LaTeX. This can be one of
301 * - \c auto: find out the input encoding from the used languages
302 * - \c default: ditto
303 * - any encoding defined in the file lib/encodings
304 * The encoding of the LyX file is always utf8 and has nothing to
305 * do with this setting.
306 * The difference between \c auto and \c default is that \c auto also
307 * causes loading of the inputenc package, while \c default does not.
308 * \c default will not work unless the user takes additional measures
309 * (such as using special environments like the CJK environment from
311 * \c default can be seen as an unspecified 8bit encoding, since LyX
312 * does not interpret it in any way apart from display on screen.
314 std::string inputenc;
315 /// The main encoding used by this buffer for LaTeX output.
316 /// Individual pieces of text can use different encodings.
317 /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
318 /// instead of the value returned by this function.
319 Encoding const & encoding() const;
323 std::string preamble;
326 /// use the class options defined in the layout?
327 bool use_default_options;
333 std::string float_placement;
335 unsigned int columns;
338 /// parameters for the listings package
339 std::string listings_params;
343 std::string pagestyle;
345 RGBColor backgroundcolor;
347 bool isbackgroundcolor;
353 RGBColor notefontcolor;
356 /// \param index should lie in the range 0 <= \c index <= 3.
357 Bullet & temp_bullet(size_type index);
358 Bullet const & temp_bullet(size_type index) const;
359 /// \param index should lie in the range 0 <= \c index <= 3.
360 Bullet & user_defined_bullet(size_type index);
361 Bullet const & user_defined_bullet(size_type index) const;
363 /// Whether to load a package such as amsmath or esint.
364 /// The enum values must not be changed (file format!)
366 /// Don't load the package. For experts only.
368 /// Load the package if needed (recommended)
370 /// Always load the package (e.g. if the document contains
371 /// some ERT that needs the package)
374 /// Whether to load a package such as amsmath or esint.
375 Package use_package(std::string const & p) const;
376 /// Set whether to load a package such as amsmath or esint.
377 void use_package(std::string const & p, Package u);
378 /// All packages that can be switched on or off
379 static std::map<std::string, std::string> const & auto_packages();
380 /// Split bibliography?
384 /// Save trensient properties?
385 bool save_transient_properties;
386 /// revision tracking for this buffer ? (this is a transient property)
388 /** This param decides whether change tracking marks should be used
389 * in output (irrespective of how these marks are actually defined;
390 * for instance, they may differ for DVI and PDF generation)
391 * This is a transient property.
397 /// the author list for the document
398 AuthorList & authors();
399 AuthorList const & authors() const;
400 void addAuthor(Author a);
402 /// map of the file's author IDs to AuthorList indexes
403 typedef std::map<int, int> AuthorMap;
404 AuthorMap author_map_;
406 /// the buffer's active font encoding
407 std::string const font_encoding() const;
408 /// all font encodings requested by the prefs/document/main language.
409 /// This does NOT include font encodings required by secondary languages
410 std::vector<std::string> const font_encodings() const;
413 std::string const dvips_options() const;
414 /** The return value of paperSizeName() depends on the
415 * purpose for which the paper size is needed, since they
416 * support different subsets of paper sizes.
418 enum PapersizePurpose {
427 std::string paperSizeName(PapersizePurpose purpose) const;
428 /// set up if and how babel is called
429 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
430 /// return supported drivers for specific packages
431 docstring getGraphicsDriver(std::string const & package) const;
432 /// handle inputenc etc.
433 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
435 std::string const parseFontName(std::string const & name) const;
436 /// set up the document fonts
437 std::string const loadFonts(LaTeXFeatures & features) const;
439 /// the cite engine modules
440 LayoutModuleList const & citeEngine() const
441 { return cite_engine_; }
442 /// the type of cite engine (authoryear or numerical)
443 CiteEngineType const & citeEngineType() const
444 { return cite_engine_type_; }
445 /// add the module to the cite engine modules
446 bool addCiteEngine(std::string const &);
447 /// add the modules to the cite engine modules
448 bool addCiteEngine(std::vector<std::string> const &);
449 /// clear the list of cite engine modules
450 void clearCiteEngine() { cite_engine_.clear(); }
451 /// set the cite engine module
452 void setCiteEngine(std::string const &);
453 /// set the cite engine modules
454 void setCiteEngine(std::vector<std::string> const &);
455 /// set the cite engine type
456 void setCiteEngineType(CiteEngineType const & engine_type)
457 { cite_engine_type_ = engine_type; }
459 /// the available citation commands
460 std::vector<std::string> citeCommands() const;
461 /// the available citation styles
462 std::vector<CitationStyle> citeStyles() const;
464 /// the default BibTeX style file for the document
465 std::string biblio_style;
466 /// the default BibTeX style file from the TextClass
467 std::string const & defaultBiblioStyle() const;
468 /// whether the BibTeX style supports full author lists
469 bool const & fullAuthorList() const;
471 /// options for pdf output
472 PDFOptions & pdfoptions();
473 PDFOptions const & pdfoptions() const;
475 // do not change these values. we rely upon them.
482 /// what to use for math output. present choices are above
483 MathOutput html_math_output;
484 /// whether to attempt to be XHTML 1.1 compliant or instead be
485 /// a little more mellow
488 double html_math_img_scale;
490 double display_pixel_ratio;
492 std::string html_latex_start;
494 std::string html_latex_end;
496 bool html_css_as_file;
497 /// generate output usable for reverse/forward search
499 /// custom LaTeX macro from user instead our own
500 std::string output_sync_macro;
501 /// use refstyle? or prettyref?
504 /// Return true if language could be set to lang,
505 /// otherwise return false and do not change language
506 bool setLanguage(std::string const & lang);
510 void readPreamble(Lexer &);
512 void readLocalLayout(Lexer &, bool);
514 void readLanguage(Lexer &);
516 void readGraphicsDriver(Lexer &);
518 void readBullets(Lexer &);
520 void readBulletsLaTeX(Lexer &);
522 void readModules(Lexer &);
524 void readRemovedModules(Lexer &);
526 void readIncludeonly(Lexer &);
527 /// A cache for the default flavors
528 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
530 mutable DefaultFlavorCache default_flavors_;
531 /// the cite engine modules
532 LayoutModuleList cite_engine_;
533 /// the type of cite engine (authoryear or numerical)
534 CiteEngineType cite_engine_type_;
536 DocumentClassPtr doc_class_;
538 LayoutModuleList layout_modules_;
539 /// this is for modules that are required by the document class but that
540 /// the user has chosen not to use
541 std::list<std::string> removed_modules_;
542 /// The local layouts without the forced ones
543 std::string local_layout_;
544 /// Forced local layouts only for reading (use getLocalLayout() instead)
545 std::string forced_local_layout_;
547 /// the list of included children (for includeonly)
548 std::list<std::string> included_children_;
550 typedef std::map<std::string, Package> PackageMap;
551 /** Whether and how to load packages like amsmath, esint, mhchem,
552 * mathdots, stackrel, stmaryrd and undertilde.
554 PackageMap use_packages;
556 /** Use the Pimpl idiom to hide those member variables that would otherwise
557 * drag in other header files.
562 static Impl * clone(Impl const *);
563 static void destroy(Impl *);
565 support::copied_ptr<Impl, MemoryTraits> pimpl_;