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
19 #include "DocumentClassPtr.h"
21 #include "LayoutModuleList.h"
22 #include "OutputParams.h"
25 #include "insets/InsetQuotes.h"
27 #include "support/copied_ptr.h"
34 namespace support { class FileName; }
47 class LayoutFileIndex;
54 /** Buffer parameters.
55 * This class contains all the parameters for this buffer's use. Some
56 * work needs to be done on this class to make it nice. Now everything
62 enum ParagraphSeparation {
64 ParagraphIndentSeparation,
66 ParagraphSkipSeparation
71 /// get l10n translated to the buffers language
72 docstring B_(std::string const & l10n) const;
74 /// read a header token, if unrecognised, return it or an unknown class name
75 std::string readToken(Lexer & lex,
76 std::string const & token, ///< token to read.
77 support::FileName const & filepath);
80 void writeFile(std::ostream &) const;
82 /// check what features are implied by the buffer parameters.
83 void validate(LaTeXFeatures &) const;
85 /** \returns true if the babel package is used (interogates
86 * the BufferParams, a LyXRC variable, and the document class).
87 * This returned value can then be passed to the insets...
89 bool writeLaTeX(otexstream &, LaTeXFeatures &,
90 support::FileName const &) const;
93 void useClassDefaults();
95 bool hasClassDefaults() const;
98 HSpace const & getIndentation() const;
100 void setIndentation(HSpace const & indent);
102 VSpace const & getDefSkip() const;
104 void setDefSkip(VSpace const & vs);
106 /** Whether paragraphs are separated by using a indent like in
107 * articles or by using a little skip like in letters.
109 ParagraphSeparation paragraph_separation;
111 InsetQuotes::QuoteLanguage quotes_language;
113 InsetQuotes::QuoteTimes quotes_times;
115 std::string fontsize;
116 /// Get the LayoutFile this document is using.
117 LayoutFile const * baseClass() const;
119 LayoutFileIndex const & baseClassID() const;
120 /// Set the LyX layout file this document is using.
121 /// NOTE: This does not call makeDocumentClass() to update the local
122 /// DocumentClass. That needs to be done manually.
123 /// \param filename the name of the layout file
124 bool setBaseClass(std::string const & classname);
125 /// Adds the module information to the baseClass information to
126 /// create our local DocumentClass.
127 /// NOTE: This should NEVER be called externally unless one immediately goes
128 /// on to class BufferView::updateDocumentClass(). The exception, of course,
129 /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
130 /// the parameters from the active Buffer.
131 void makeDocumentClass();
132 /// Returns the DocumentClass currently in use: the BaseClass as modified
134 DocumentClass const & documentClass() const;
135 /// \return A pointer to the DocumentClass currently in use: the BaseClass
136 /// as modified by modules.
137 DocumentClassConstPtr documentClassPtr() const;
138 /// This bypasses the baseClass and sets the textClass directly.
139 /// Should be called with care and would be better not being here,
140 /// but it seems to be needed by CutAndPaste::putClipboard().
141 void setDocumentClass(DocumentClassConstPtr);
142 /// List of modules in use
143 LayoutModuleList const & getModules() const { return layout_modules_; }
144 /// List of default modules the user has removed
145 std::list<std::string> const & getRemovedModules() const
146 { return removed_modules_; }
148 /// Add a module to the list of modules in use. This checks only that the
149 /// module is not already in the list, so use moduleIsCompatible first if
150 /// you want to check for compatibility.
151 /// \return true if module was successfully added.
152 bool addLayoutModule(std::string const & modName);
153 /// checks to make sure module's requriements are satisfied, that it does
154 /// not conflict with already-present modules, isn't already loaded, etc.
155 bool moduleCanBeAdded(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(); }
164 /// returns \c true if the buffer contains a LaTeX document
165 bool isLatex() const;
166 /// returns \c true if the buffer contains a DocBook document
167 bool isDocBook() const;
168 /// returns \c true if the buffer contains a Wed document
169 bool isLiterate() const;
171 /// return the format of the buffer on a string
172 std::string bufferFormat() const;
173 /// return the default output format of the current backend
174 std::string getDefaultOutputFormat() const;
175 /// return the output flavor of \p format or the default
176 OutputParams::FLAVOR getOutputFlavor(
177 std::string const format = std::string()) const;
179 bool isExportable(std::string const & format) const;
181 std::vector<Format const *> exportableFormats(bool only_viewable) const;
183 bool isExportableFormat(std::string const & format) const;
184 /// the backends appropriate for use with this document.
185 /// so, e.g., latex is excluded , if we're using non-TeX fonts
186 std::vector<std::string> backends() const;
188 /// List of included children (for includeonly)
189 std::list<std::string> const & getIncludedChildren() const
190 { return included_children_; }
192 void addIncludedChildren(std::string const & child)
193 { included_children_.push_back(child); }
194 /// Clear the list of included children
195 void clearIncludedChildren() { included_children_.clear(); }
197 /// update aux files of unincluded children (with \includeonly)
198 bool maintain_unincluded_children;
200 /// returns the main font for the buffer (document)
201 Font const getFont() const;
203 /// translate quote style string to enum value
204 InsetQuotes::QuoteLanguage getQuoteStyle(std::string const qs) const;
206 /* these are for the PaperLayout */
208 PAPER_SIZE papersize;
210 PAPER_ORIENTATION orientation;
211 /// use custom margins
214 std::string paperwidth;
216 std::string paperheight;
218 std::string leftmargin;
220 std::string topmargin;
222 std::string rightmargin;
224 std::string bottommargin;
226 std::string headheight;
230 std::string footskip;
232 std::string columnsep;
234 /* some LaTeX options */
235 /// The graphics driver
236 std::string graphics_driver;
237 /// The default output format
238 std::string default_output_format;
239 /// customized bibliography processor
240 std::string bibtex_command;
241 /// customized index processor
242 std::string index_command;
246 std::string fonts_roman;
248 std::string fonts_sans;
250 std::string fonts_typewriter;
252 std::string fonts_math;
253 /// the default family (rm, sf, tt)
254 std::string fonts_default_family;
255 /// use the fonts of the OS (OpenType, True Type) directly
257 /// use expert Small Caps
258 bool fonts_expert_sc;
259 /// use Old Style Figures
260 bool fonts_old_figures;
261 /// the scale factor of the sf font
262 int fonts_sans_scale;
263 /// the scale factor of the tt font
264 int fonts_typewriter_scale;
265 /// the font used by the CJK command
266 std::string fonts_cjk;
269 Spacing const & spacing() const;
275 Language const * language;
277 std::string lang_package;
279 BranchList & branchlist();
280 BranchList const & branchlist() const;
282 IndicesList & indiceslist();
283 IndicesList const & indiceslist() const;
285 * The input encoding for LaTeX. This can be one of
286 * - \c auto: find out the input encoding from the used languages
287 * - \c default: ditto
288 * - any encoding supported by the inputenc package
289 * The encoding of the LyX file is always utf8 and has nothing to
290 * do with this setting.
291 * The difference between \c auto and \c default is that \c auto also
292 * causes loading of the inputenc package, while \c default does not.
293 * \c default will not work unless the user takes additional measures
294 * (such as using special environments like the CJK environment from
296 * \c default can be seen as an unspecified 8bit encoding, since LyX
297 * does not interpret it in any way apart from display on screen.
299 std::string inputenc;
300 /// The main encoding used by this buffer for LaTeX output.
301 /// Individual pieces of text can use different encodings.
302 Encoding const & encoding() const;
304 std::string preamble;
306 std::string local_layout;
309 /// use the class options defined in the layout?
310 bool use_default_options;
316 std::string float_placement;
318 unsigned int columns;
321 /// parameters for the listings package
322 std::string listings_params;
326 std::string pagestyle;
328 RGBColor backgroundcolor;
330 bool isbackgroundcolor;
336 RGBColor notefontcolor;
339 /// \param index should lie in the range 0 <= \c index <= 3.
340 Bullet & temp_bullet(size_type index);
341 Bullet const & temp_bullet(size_type index) const;
342 /// \param index should lie in the range 0 <= \c index <= 3.
343 Bullet & user_defined_bullet(size_type index);
344 Bullet const & user_defined_bullet(size_type index) const;
346 /// Whether to load a package such as amsmath or esint.
347 /// The enum values must not be changed (file format!)
349 /// Don't load the package. For experts only.
351 /// Load the package if needed (recommended)
353 /// Always load the package (e.g. if the document contains
354 /// some ERT that needs the package)
357 /// Whether to load a package such as amsmath or esint.
358 Package use_package(std::string const & p) const;
359 /// Set whether to load a package such as amsmath or esint.
360 void use_package(std::string const & p, Package u);
361 /// All packages that can be switched on or off
362 static std::vector<std::string> const & auto_packages();
363 /// Split bibliography?
367 /// revision tracking for this buffer ?
369 /** This param decides whether change tracking marks should be used
370 * in output (irrespective of how these marks are actually defined;
371 * for instance, they may differ for DVI and PDF generation)
377 /// the author list for the document
378 AuthorList & authors();
379 AuthorList const & authors() const;
381 /// map of the file's author IDs to AuthorList indexes
382 typedef std::map<int, int> AuthorMap;
383 AuthorMap author_map;
384 /// the buffer's font encoding
385 std::string const font_encoding() const;
387 std::string const dvips_options() const;
388 /** The return value of paperSizeName() depends on the
389 * purpose for which the paper size is needed, since they
390 * support different subsets of paper sizes.
392 enum PapersizePurpose {
401 std::string paperSizeName(PapersizePurpose purpose) const;
402 /// set up if and how babel is called
403 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
404 /// return supported drivers for specific packages
405 docstring getGraphicsDriver(std::string const & package) const;
406 /// handle inputenc etc.
407 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
409 std::string const parseFontName(std::string const & name) const;
410 /// set up the document fonts
411 std::string const loadFonts(LaTeXFeatures & features) const;
413 /// the cite engine modules
414 LayoutModuleList const & citeEngine() const
415 { return cite_engine_; }
416 /// the type of cite engine (authoryear or numerical)
417 CiteEngineType const & citeEngineType() const
418 { return cite_engine_type_; }
419 /// add the module to the cite engine modules
420 bool addCiteEngine(std::string const &);
421 /// add the modules to the cite engine modules
422 bool addCiteEngine(std::vector<std::string> const &);
423 /// clear the list of cite engine modules
424 void clearCiteEngine() { cite_engine_.clear(); }
425 /// set the cite engine module
426 void setCiteEngine(std::string const &);
427 /// set the cite engine modules
428 void setCiteEngine(std::vector<std::string> const &);
429 /// set the cite engine type
430 void setCiteEngineType(CiteEngineType const & engine_type)
431 { cite_engine_type_ = engine_type; }
433 /// the available citation commands
434 std::vector<std::string> citeCommands() const;
435 /// the available citation styles
436 std::vector<CitationStyle> citeStyles() const;
438 /// the default BibTeX style file for the document
439 std::string biblio_style;
440 /// the default BibTeX style file from the TextClass
441 std::string const & defaultBiblioStyle() const;
442 /// whether the BibTeX style supports full author lists
443 bool const & fullAuthorList() const;
445 /// options for pdf output
446 PDFOptions & pdfoptions();
447 PDFOptions const & pdfoptions() const;
449 // do not change these values. we rely upon them.
456 /// what to use for math output. present choices are above
457 MathOutput html_math_output;
458 /// whether to attempt to be XHTML 1.1 compliant or instead be
459 /// a little more mellow
462 double html_math_img_scale;
464 std::string html_latex_start;
466 std::string html_latex_end;
468 bool html_css_as_file;
469 /// generate output usable for reverse/forward search
471 /// custom LaTeX macro from user instead our own
472 std::string output_sync_macro;
473 /// use refstyle? or prettyref?
476 /// Return true if language could be set to lang,
477 /// otherwise return false and do not change language
478 bool setLanguage(std::string const & lang);
482 void readPreamble(Lexer &);
484 void readLocalLayout(Lexer &);
486 void readLanguage(Lexer &);
488 void readGraphicsDriver(Lexer &);
490 void readBullets(Lexer &);
492 void readBulletsLaTeX(Lexer &);
494 void readModules(Lexer &);
496 void readRemovedModules(Lexer &);
498 void readIncludeonly(Lexer &);
499 /// A cache for the default flavors
500 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
502 mutable DefaultFlavorCache default_flavors_;
503 /// the cite engine modules
504 LayoutModuleList cite_engine_;
505 /// the type of cite engine (authoryear or numerical)
506 CiteEngineType cite_engine_type_;
508 DocumentClassPtr doc_class_;
510 LayoutModuleList layout_modules_;
511 /// this is for modules that are required by the document class but that
512 /// the user has chosen not to use
513 std::list<std::string> removed_modules_;
515 /// the list of included children (for includeonly)
516 std::list<std::string> included_children_;
518 typedef std::map<std::string, Package> PackageMap;
519 /** Whether and how to load packages like amsmath, esint, mhchem,
520 * mathdots and undertilde.
522 PackageMap use_packages;
524 /** Use the Pimpl idiom to hide those member variables that would otherwise
525 * drag in other header files.
530 static Impl * clone(Impl const *);
531 static void destroy(Impl *);
533 support::copied_ptr<Impl, MemoryTraits> pimpl_;