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 classname: 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(bool const clone = false);
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 layoutModuleCanBeAdeed first
150 /// if 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 layoutModuleCanBeAdded(std::string const & modName) const;
156 /// same, but for citaton modules.
157 bool citationModuleCanBeAdded(std::string const & modName) const;
159 void addRemovedModule(std::string const & modName)
160 { removed_modules_.push_back(modName); }
162 void clearLayoutModules() { layout_modules_.clear(); }
163 /// Clear the removed module list
164 void clearRemovedModules() { removed_modules_.clear(); }
165 /// Get the local layouts
166 std::string getLocalLayout(bool) const;
167 /// Set the local layouts
168 void setLocalLayout(std::string const &, bool);
170 /// returns \c true if the buffer contains a LaTeX document
171 bool isLatex() const;
172 /// returns \c true if the buffer contains a DocBook document
173 bool isDocBook() const;
174 /// returns \c true if the buffer contains a Wed document
175 bool isLiterate() const;
177 /// return the format of the buffer on a string
178 std::string bufferFormat() const;
179 /// return the default output format of the current backend
180 std::string getDefaultOutputFormat() const;
181 /// return the output flavor of \p format or the default
182 OutputParams::FLAVOR getOutputFlavor(
183 std::string const & format = std::string()) const;
185 bool isExportable(std::string const & format) const;
187 std::vector<Format const *> exportableFormats(bool only_viewable) const;
189 bool isExportableFormat(std::string const & format) const;
190 /// the backends appropriate for use with this document.
191 /// so, e.g., latex is excluded , if we're using non-TeX fonts
192 std::vector<std::string> backends() const;
194 /// List of included children (for includeonly)
195 std::list<std::string> const & getIncludedChildren() const
196 { return included_children_; }
198 void addIncludedChildren(std::string const & child)
199 { included_children_.push_back(child); }
200 /// Clear the list of included children
201 void clearIncludedChildren() { included_children_.clear(); }
203 /// update aux files of unincluded children (with \includeonly)
204 bool maintain_unincluded_children;
206 /// returns the main font for the buffer (document)
207 Font const getFont() const;
209 /// translate quote style string to enum value
210 InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
212 /* these are for the PaperLayout */
214 PAPER_SIZE papersize;
216 PAPER_ORIENTATION orientation;
217 /// use custom margins
220 std::string paperwidth;
222 std::string paperheight;
224 std::string leftmargin;
226 std::string topmargin;
228 std::string rightmargin;
230 std::string bottommargin;
232 std::string headheight;
236 std::string footskip;
238 std::string columnsep;
240 /* some LaTeX options */
241 /// The graphics driver
242 std::string graphics_driver;
243 /// The default output format
244 std::string default_output_format;
245 /// customized bibliography processor
246 std::string bibtex_command;
247 /// customized index processor
248 std::string index_command;
252 std::string fonts_roman;
254 std::string fonts_sans;
256 std::string fonts_typewriter;
258 std::string fonts_math;
259 /// the default family (rm, sf, tt)
260 std::string fonts_default_family;
261 /// use the fonts of the OS (OpenType, True Type) directly
263 /// use expert Small Caps
264 bool fonts_expert_sc;
265 /// use Old Style Figures
266 bool fonts_old_figures;
267 /// the scale factor of the sf font
268 int fonts_sans_scale;
269 /// the scale factor of the tt font
270 int fonts_typewriter_scale;
271 /// the font used by the CJK command
272 std::string fonts_cjk;
275 Spacing const & spacing() const;
281 Language const * language;
283 std::string lang_package;
285 BranchList & branchlist();
286 BranchList const & branchlist() const;
288 IndicesList & indiceslist();
289 IndicesList const & indiceslist() const;
291 * The LyX name of the input encoding for LaTeX. This can be one of
292 * - \c auto: find out the input encoding from the used languages
293 * - \c default: ditto
294 * - any encoding defined in the file lib/encodings
295 * The encoding of the LyX file is always utf8 and has nothing to
296 * do with this setting.
297 * The difference between \c auto and \c default is that \c auto also
298 * causes loading of the inputenc package, while \c default does not.
299 * \c default will not work unless the user takes additional measures
300 * (such as using special environments like the CJK environment from
302 * \c default can be seen as an unspecified 8bit encoding, since LyX
303 * does not interpret it in any way apart from display on screen.
305 std::string inputenc;
306 /// The main encoding used by this buffer for LaTeX output.
307 /// Individual pieces of text can use different encodings.
308 Encoding const & encoding() const;
310 std::string preamble;
313 /// use the class options defined in the layout?
314 bool use_default_options;
320 std::string float_placement;
322 unsigned int columns;
325 /// parameters for the listings package
326 std::string listings_params;
330 std::string pagestyle;
332 RGBColor backgroundcolor;
334 bool isbackgroundcolor;
340 RGBColor notefontcolor;
343 /// \param index should lie in the range 0 <= \c index <= 3.
344 Bullet & temp_bullet(size_type index);
345 Bullet const & temp_bullet(size_type index) const;
346 /// \param index should lie in the range 0 <= \c index <= 3.
347 Bullet & user_defined_bullet(size_type index);
348 Bullet const & user_defined_bullet(size_type index) const;
350 /// Whether to load a package such as amsmath or esint.
351 /// The enum values must not be changed (file format!)
353 /// Don't load the package. For experts only.
355 /// Load the package if needed (recommended)
357 /// Always load the package (e.g. if the document contains
358 /// some ERT that needs the package)
361 /// Whether to load a package such as amsmath or esint.
362 Package use_package(std::string const & p) const;
363 /// Set whether to load a package such as amsmath or esint.
364 void use_package(std::string const & p, Package u);
365 /// All packages that can be switched on or off
366 static std::map<std::string, std::string> const & auto_packages();
367 /// Split bibliography?
371 /// revision tracking for this buffer ?
373 /** This param decides whether change tracking marks should be used
374 * in output (irrespective of how these marks are actually defined;
375 * for instance, they may differ for DVI and PDF generation)
381 /// the author list for the document
382 AuthorList & authors();
383 AuthorList const & authors() const;
385 /// map of the file's author IDs to AuthorList indexes
386 typedef std::map<int, int> AuthorMap;
387 AuthorMap author_map;
388 /// the buffer's font encoding
389 std::string const font_encoding() const;
391 std::string const dvips_options() const;
392 /** The return value of paperSizeName() depends on the
393 * purpose for which the paper size is needed, since they
394 * support different subsets of paper sizes.
396 enum PapersizePurpose {
405 std::string paperSizeName(PapersizePurpose purpose) const;
406 /// set up if and how babel is called
407 std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
408 /// return supported drivers for specific packages
409 docstring getGraphicsDriver(std::string const & package) const;
410 /// handle inputenc etc.
411 void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
413 std::string const parseFontName(std::string const & name) const;
414 /// set up the document fonts
415 std::string const loadFonts(LaTeXFeatures & features) const;
417 /// the cite engine modules
418 LayoutModuleList const & citeEngine() const
419 { return cite_engine_; }
420 /// the type of cite engine (authoryear or numerical)
421 CiteEngineType const & citeEngineType() const
422 { return cite_engine_type_; }
423 /// add the module to the cite engine modules
424 bool addCiteEngine(std::string const &);
425 /// add the modules to the cite engine modules
426 bool addCiteEngine(std::vector<std::string> const &);
427 /// clear the list of cite engine modules
428 void clearCiteEngine() { cite_engine_.clear(); }
429 /// set the cite engine module
430 void setCiteEngine(std::string const &);
431 /// set the cite engine modules
432 void setCiteEngine(std::vector<std::string> const &);
433 /// set the cite engine type
434 void setCiteEngineType(CiteEngineType const & engine_type)
435 { cite_engine_type_ = engine_type; }
437 /// the available citation commands
438 std::vector<std::string> citeCommands() const;
439 /// the available citation styles
440 std::vector<CitationStyle> citeStyles() const;
442 /// the default BibTeX style file for the document
443 std::string biblio_style;
444 /// the default BibTeX style file from the TextClass
445 std::string const & defaultBiblioStyle() const;
446 /// whether the BibTeX style supports full author lists
447 bool const & fullAuthorList() const;
449 /// options for pdf output
450 PDFOptions & pdfoptions();
451 PDFOptions const & pdfoptions() const;
453 // do not change these values. we rely upon them.
460 /// what to use for math output. present choices are above
461 MathOutput html_math_output;
462 /// whether to attempt to be XHTML 1.1 compliant or instead be
463 /// a little more mellow
466 double html_math_img_scale;
468 double display_pixel_ratio;
470 std::string html_latex_start;
472 std::string html_latex_end;
474 bool html_css_as_file;
475 /// generate output usable for reverse/forward search
477 /// custom LaTeX macro from user instead our own
478 std::string output_sync_macro;
479 /// use refstyle? or prettyref?
482 /// Return true if language could be set to lang,
483 /// otherwise return false and do not change language
484 bool setLanguage(std::string const & lang);
488 void readPreamble(Lexer &);
490 void readLocalLayout(Lexer &, bool);
492 void readLanguage(Lexer &);
494 void readGraphicsDriver(Lexer &);
496 void readBullets(Lexer &);
498 void readBulletsLaTeX(Lexer &);
500 void readModules(Lexer &);
502 void readRemovedModules(Lexer &);
504 void readIncludeonly(Lexer &);
505 /// A cache for the default flavors
506 typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
508 mutable DefaultFlavorCache default_flavors_;
509 /// the cite engine modules
510 LayoutModuleList cite_engine_;
511 /// the type of cite engine (authoryear or numerical)
512 CiteEngineType cite_engine_type_;
514 DocumentClassPtr doc_class_;
516 LayoutModuleList layout_modules_;
517 /// this is for modules that are required by the document class but that
518 /// the user has chosen not to use
519 std::list<std::string> removed_modules_;
520 /// The local layouts without the forced ones
521 std::string local_layout_;
522 /// Forced local layouts only for reading (use getLocalLayout() instead)
523 std::string forced_local_layout_;
525 /// the list of included children (for includeonly)
526 std::list<std::string> included_children_;
528 typedef std::map<std::string, Package> PackageMap;
529 /** Whether and how to load packages like amsmath, esint, mhchem,
530 * mathdots, stackrel, stmaryrd and undertilde.
532 PackageMap use_packages;
534 /** Use the Pimpl idiom to hide those member variables that would otherwise
535 * drag in other header files.
540 static Impl * clone(Impl const *);
541 static void destroy(Impl *);
543 support::copied_ptr<Impl, MemoryTraits> pimpl_;