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 "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 &) 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 (interogates
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 InsetQuotes::QuoteTimes quotes_times;
114 std::string fontsize;
115 /// Get the LayoutFile this document is using.
116 LayoutFile const * baseClass() const;
118 LayoutFileIndex const & baseClassID() const;
119 /// Set the LyX layout file this document is using.
120 /// NOTE: This does not call makeDocumentClass() to update the local
121 /// DocumentClass. That needs to be done manually.
122 /// \param filename the name of the layout file
123 bool setBaseClass(std::string const & classname);
124 /// Adds the module information to the baseClass information to
125 /// create our local DocumentClass.
126 void makeDocumentClass();
127 /// Returns the DocumentClass currently in use: the BaseClass as modified
129 DocumentClass const & documentClass() const;
130 /// \return A pointer to the DocumentClass currently in use: the BaseClass
131 /// as modified by modules.
132 DocumentClass const * documentClassPtr() const;
133 /// This bypasses the baseClass and sets the textClass directly.
134 /// Should be called with care and would be better not being here,
135 /// but it seems to be needed by CutAndPaste::putClipboard().
136 void setDocumentClass(DocumentClass const * const);
137 /// List of modules in use
138 LayoutModuleList const & getModules() const { return layout_modules_; }
139 /// List of default modules the user has removed
140 std::list<std::string> const & getRemovedModules() const
141 { return removed_modules_; }
143 /// Add a module to the list of modules in use. This checks only that the
144 /// module is not already in the list, so use moduleIsCompatible first if
145 /// you want to check for compatibility.
146 /// \return true if module was successfully added.
147 bool addLayoutModule(std::string const & modName);
148 /// checks to make sure module's requriements are satisfied, that it does
149 /// not conflict with already-present modules, isn't already loaded, etc.
150 bool moduleCanBeAdded(std::string const & modName) const;
152 void addRemovedModule(std::string const & modName)
153 { removed_modules_.push_back(modName); }
155 void clearLayoutModules() { layout_modules_.clear(); }
156 /// Clear the removed module list
157 void clearRemovedModules() { removed_modules_.clear(); }
159 /// returns \c true if the buffer contains a LaTeX document
160 bool isLatex() const;
161 /// returns \c true if the buffer contains a DocBook document
162 bool isDocBook() const;
163 /// returns \c true if the buffer contains a Wed document
164 bool isLiterate() const;
166 /// return the format of the buffer on a string
167 std::string bufferFormat() const;
168 /// return the default output format of the current backend
169 std::string getDefaultOutputFormat() const;
170 /// return the output flavor of \p format or the default
171 OutputParams::FLAVOR getOutputFlavor(
172 std::string const format = std::string()) const;
174 bool isExportable(std::string const & format) const;
176 std::vector<Format const *> exportableFormats(bool only_viewable) const;
178 bool isExportableFormat(std::string const & format) const;
179 /// the backends appropriate for use with this document.
180 /// so, e.g., latex is excluded , if we're using non-TeX fonts
181 std::vector<std::string> backends() const;
183 /// List of included children (for includeonly)
184 std::list<std::string> const & getIncludedChildren() const
185 { return included_children_; }
187 void addIncludedChildren(std::string const & child)
188 { included_children_.push_back(child); }
189 /// Clear the list of included children
190 void clearIncludedChildren() { included_children_.clear(); }
192 /// update aux files of unincluded children (with \includeonly)
193 bool maintain_unincluded_children;
195 /// returns the main font for the buffer (document)
196 Font const getFont() const;
198 /* these are for the PaperLayout */
200 PAPER_SIZE papersize;
202 PAPER_ORIENTATION orientation;
203 /// use custom margins
206 std::string paperwidth;
208 std::string paperheight;
210 std::string leftmargin;
212 std::string topmargin;
214 std::string rightmargin;
216 std::string bottommargin;
218 std::string headheight;
222 std::string footskip;
224 std::string columnsep;
226 /* some LaTeX options */
227 /// The graphics driver
228 std::string graphics_driver;
229 /// The default output format
230 std::string default_output_format;
231 /// customized bibliography processor
232 std::string bibtex_command;
233 /// customized index processor
234 std::string index_command;
238 std::string fonts_roman;
240 std::string fonts_sans;
242 std::string fonts_typewriter;
243 /// the default family (rm, sf, tt)
244 std::string fonts_default_family;
245 /// use the fonts of the OS (OpenType, True Type) directly
247 /// use expert Small Caps
248 bool fonts_expert_sc;
249 /// use Old Style Figures
250 bool fonts_old_figures;
251 /// the scale factor of the sf font
252 int fonts_sans_scale;
253 /// the scale factor of the tt font
254 int fonts_typewriter_scale;
255 /// the font used by the CJK command
256 std::string fonts_cjk;
259 Spacing const & spacing() const;
265 Language const * language;
267 std::string lang_package;
269 BranchList & branchlist();
270 BranchList const & branchlist() const;
272 IndicesList & indiceslist();
273 IndicesList const & indiceslist() const;
275 * The input encoding for LaTeX. This can be one of
276 * - \c auto: find out the input encoding from the used languages
277 * - \c default: ditto
278 * - any encoding supported by the inputenc package
279 * The encoding of the LyX file is always utf8 and has nothing to
280 * do with this setting.
281 * The difference between \c auto and \c default is that \c auto also
282 * causes loading of the inputenc package, while \c default does not.
283 * \c default will not work unless the user takes additional measures
284 * (such as using special environments like the CJK environment from
286 * \c default can be seen as an unspecified 8bit encoding, since LyX
287 * does not interpret it in any way apart from display on screen.
289 std::string inputenc;
290 /// The main encoding used by this buffer for LaTeX output.
291 /// Individual pieces of text can use different encodings.
292 Encoding const & encoding() const;
294 std::string preamble;
296 std::string local_layout;
299 /// use the class options defined in the layout?
300 bool use_default_options;
306 std::string float_placement;
308 unsigned int columns;
311 /// parameters for the listings package
312 std::string listings_params;
316 std::string pagestyle;
318 RGBColor backgroundcolor;
320 bool isbackgroundcolor;
326 RGBColor notefontcolor;
329 /// \param index should lie in the range 0 <= \c index <= 3.
330 Bullet & temp_bullet(size_type index);
331 Bullet const & temp_bullet(size_type index) const;
332 /// \param index should lie in the range 0 <= \c index <= 3.
333 Bullet & user_defined_bullet(size_type index);
334 Bullet const & user_defined_bullet(size_type index) const;
336 /// Whether to load a package such as amsmath or esint.
337 /// The enum values must not be changed (file format!)
339 /// Don't load the package. For experts only.
341 /// Load the package if needed (recommended)
343 /// Always load the package (e.g. if the document contains
344 /// some ERT that needs the package)
347 /// Whether to load a package such as amsmath or esint.
348 Package use_package(std::string const & p) const;
349 /// Set whether to load a package such as amsmath or esint.
350 void use_package(std::string const & p, Package u);
351 /// All packages that can be switched on or off
352 static std::vector<std::string> const & auto_packages();
353 /// Split bibliography?
357 /// revision tracking for this buffer ?
359 /** This param decides whether change tracking marks should be used
360 * in output (irrespective of how these marks are actually defined;
361 * for instance, they may differ for DVI and PDF generation)
367 /// the author list for the document
368 AuthorList & authors();
369 AuthorList const & authors() const;
371 /// map of the file's author IDs to AuthorList indexes
372 typedef std::map<int, int> AuthorMap;
373 AuthorMap author_map;
374 /// the buffer's font encoding
375 std::string const font_encoding() const;
377 std::string const dvips_options() const;
378 /** The return value of paperSizeName() depends on the
379 * purpose for which the paper size is needed, since they
380 * support different subsets of paper sizes.
382 enum PapersizePurpose {
391 std::string paperSizeName(PapersizePurpose purpose) const;
392 /// set up if and how babel is called
393 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
394 /// return supported drivers for specific packages
395 docstring getGraphicsDriver(std::string const & package) const;
396 /// handle inputenc etc.
397 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
399 std::string const parseFontName(std::string const & name) const;
400 /// set up the document fonts
401 std::string const loadFonts(std::string const & rm,
402 std::string const & sf, std::string const & tt,
403 bool const & sc, bool const & osf,
404 int const & sfscale, int const & ttscale,
405 bool const & use_nonlatexfonts,
406 LaTeXFeatures & features) const;
408 /// the cite engine modules
409 LayoutModuleList const & citeEngine() const
410 { return cite_engine_; }
411 /// the type of cite engine (authoryear or numerical)
412 CiteEngineType const & citeEngineType() const
413 { return cite_engine_type_; }
414 /// add the module to the cite engine modules
415 bool addCiteEngine(std::string const &);
416 /// add the modules to the cite engine modules
417 bool addCiteEngine(std::vector<std::string> const &);
418 /// clear the list of cite engine modules
419 void clearCiteEngine() { cite_engine_.clear(); }
420 /// set the cite engine module
421 void setCiteEngine(std::string const &);
422 /// set the cite engine modules
423 void setCiteEngine(std::vector<std::string> const &);
424 /// set the cite engine type
425 void setCiteEngineType(CiteEngineType const & engine_type)
426 { cite_engine_type_ = engine_type; }
428 /// the available citation commands
429 std::vector<std::string> citeCommands() const;
430 /// the available citation styles
431 std::vector<CitationStyle> citeStyles() const;
433 /// the default BibTeX style file for the document
434 std::string biblio_style;
435 /// the default BibTeX style file from the TextClass
436 std::string const & defaultBiblioStyle() const;
437 /// whether the BibTeX style supports full author lists
438 bool const & fullAuthorList() const;
440 /// options for pdf output
441 PDFOptions & pdfoptions();
442 PDFOptions const & pdfoptions() const;
444 // do not change these values. we rely upon them.
451 /// what to use for math output. present choices are above
452 MathOutput html_math_output;
453 /// whether to attempt to be XHTML 1.1 compliant or instead be
454 /// a little more mellow
457 double html_math_img_scale;
459 std::string html_latex_start;
461 std::string html_latex_end;
463 bool html_css_as_file;
464 /// generate output usable for reverse/forward search
466 /// custom LaTeX macro from user instead our own
467 std::string output_sync_macro;
468 /// use refstyle? or prettyref?
471 /// Return true if language could be set to lang,
472 /// otherwise return false and do not change language
473 bool setLanguage(std::string const & lang);
477 void readPreamble(Lexer &);
479 void readLocalLayout(Lexer &);
481 void readLanguage(Lexer &);
483 void readGraphicsDriver(Lexer &);
485 void readBullets(Lexer &);
487 void readBulletsLaTeX(Lexer &);
489 void readModules(Lexer &);
491 void readRemovedModules(Lexer &);
493 void readIncludeonly(Lexer &);
494 /// A cache for the default flavors
495 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
497 mutable DefaultFlavorCache default_flavors_;
498 /// the cite engine modules
499 LayoutModuleList cite_engine_;
500 /// the type of cite engine (authoryear or numerical)
501 CiteEngineType cite_engine_type_;
503 DocumentClass * doc_class_;
505 LayoutModuleList layout_modules_;
506 /// this is for modules that are required by the document class but that
507 /// the user has chosen not to use
508 std::list<std::string> removed_modules_;
510 /// the list of included children (for includeonly)
511 std::list<std::string> included_children_;
513 typedef std::map<std::string, Package> PackageMap;
514 /** Whether and how to load packages like amsmath, esint, mhchem,
515 * mathdots and undertilde.
517 PackageMap use_packages;
519 /** Use the Pimpl idiom to hide those member variables that would otherwise
520 * drag in other header files.
525 static Impl * clone(Impl const *);
526 static void destroy(Impl *);
528 support::copied_ptr<Impl, MemoryTraits> pimpl_;