]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
a09366bb3c8744470080c07f43b705ffaa7c3762
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "Author.h"
19 #include "Citation.h"
20 #include "DocumentClassPtr.h"
21 #include "Format.h"
22 #include "LayoutModuleList.h"
23 #include "OutputParams.h"
24 #include "paper.h"
25
26 #include "insets/InsetQuotes.h"
27
28 #include "support/copied_ptr.h"
29
30 #include <map>
31 #include <vector>
32
33 namespace lyx {
34
35 namespace support { class FileName; }
36
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class Font;
42 class HSpace;
43 class IndicesList;
44 class Language;
45 class LayoutFile;
46 class LayoutFileIndex;
47 class Lexer;
48 class PDFOptions;
49 class Spacing;
50 class VSpace;
51
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
55  *  is in public.
56  */
57 class BufferParams {
58 public:
59         ///
60         enum ParagraphSeparation {
61                 ///
62                 ParagraphIndentSeparation,
63                 ///
64                 ParagraphSkipSeparation
65         };
66         ///
67         BufferParams();
68
69         /// get l10n translated to the buffers language
70         docstring B_(std::string const & l10n) const;
71
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);
76
77         ///
78         void writeFile(std::ostream &, Buffer const *) const;
79
80         /// check what features are implied by the buffer parameters.
81         void validate(LaTeXFeatures &) const;
82
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...
86          */
87         bool writeLaTeX(otexstream &, LaTeXFeatures &,
88                         support::FileName const &) const;
89
90         ///
91         void useClassDefaults();
92         ///
93         bool hasClassDefaults() const;
94
95         ///
96         HSpace const & getIndentation() const;
97         ///
98         void setIndentation(HSpace const & indent);
99         ///
100         VSpace const & getDefSkip() const;
101         ///
102         void setDefSkip(VSpace const & vs);
103
104         /** Whether paragraphs are separated by using a indent like in
105          *  articles or by using a little skip like in letters.
106          */
107         ParagraphSeparation paragraph_separation;
108         ///
109         InsetQuotesParams::QuoteStyle quotes_style;
110         ///
111         bool dynamic_quotes;
112         ///
113         std::string fontsize;
114         /// Get the LayoutFile this document is using.
115         LayoutFile const * baseClass() const;
116         ///
117         LayoutFileIndex const & baseClassID() const;
118         /// Set the LyX layout file this document is using.
119         /// NOTE: This does not call makeDocumentClass() to update the local
120         /// DocumentClass. That needs to be done manually.
121         /// \param classname: the name of the layout file
122         bool setBaseClass(std::string const & classname);
123         /// Adds the module information to the baseClass information to
124         /// create our local DocumentClass.
125         /// NOTE: This should NEVER be called externally unless one immediately goes
126         /// on to class BufferView::updateDocumentClass(). The exception, of course,
127         /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
128         /// the parameters from the active Buffer.
129         void makeDocumentClass(bool const clone = false);
130         /// Returns the DocumentClass currently in use: the BaseClass as modified
131         /// by modules.
132         DocumentClass const & documentClass() const;
133         /// \return A pointer to the DocumentClass currently in use: the BaseClass
134         /// as modified by modules.
135         DocumentClassConstPtr documentClassPtr() const;
136         /// This bypasses the baseClass and sets the textClass directly.
137         /// Should be called with care and would be better not being here,
138         /// but it seems to be needed by CutAndPaste::putClipboard().
139         void setDocumentClass(DocumentClassConstPtr);
140         /// List of modules in use
141         LayoutModuleList const & getModules() const { return layout_modules_; }
142         /// List of default modules the user has removed
143         std::list<std::string> const & getRemovedModules() const
144                         { return removed_modules_; }
145         ///
146         /// Add a module to the list of modules in use. This checks only that the
147         /// module is not already in the list, so use layoutModuleCanBeAdeed first 
148         /// if you want to check for compatibility.
149         /// \return true if module was successfully added.
150         bool addLayoutModule(std::string const & modName);
151         /// checks to make sure module's requriements are satisfied, that it does
152         /// not conflict with already-present modules, isn't already loaded, etc.
153         bool layoutModuleCanBeAdded(std::string const & modName) const;
154         /// same, but for citaton modules.
155         bool citationModuleCanBeAdded(std::string const & modName) const;
156         ///
157         void addRemovedModule(std::string const & modName)
158                         { removed_modules_.push_back(modName); }
159         /// Clear the list
160         void clearLayoutModules() { layout_modules_.clear(); }
161         /// Clear the removed module list
162         void clearRemovedModules() { removed_modules_.clear(); }
163         /// Get the local layouts
164         docstring getLocalLayout(bool forced) const;
165         /// Set the local layouts
166         void setLocalLayout(docstring const & layout, bool forced);
167
168         /// returns \c true if the buffer contains a LaTeX document
169         bool isLatex() const;
170         /// returns \c true if the buffer contains a DocBook document
171         bool isDocBook() const;
172         /// returns \c true if the buffer contains a Wed document
173         bool isLiterate() const;
174
175         /// return the format of the buffer on a string
176         std::string bufferFormat() const;
177         /// return the default output format of the current backend
178         std::string getDefaultOutputFormat() const;
179         /// return the output flavor of \p format or the default
180         OutputParams::FLAVOR getOutputFlavor(
181                   std::string const & format = std::string()) const;
182         ///
183         bool isExportable(std::string const & format, bool need_viewable) const;
184         ///
185         std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
186         /// the backends appropriate for use with this document.
187         /// so, e.g., latex is excluded , if we're using non-TeX fonts
188         std::vector<std::string> backends() const;
189
190         /// List of included children (for includeonly)
191         std::list<std::string> const & getIncludedChildren() const
192                         { return included_children_; }
193         ///
194         void addIncludedChildren(std::string const & child)
195                         { included_children_.push_back(child); }
196         /// Clear the list of included children
197         void clearIncludedChildren() { included_children_.clear(); }
198
199         /// update aux files of unincluded children (with \includeonly)
200         bool maintain_unincluded_children;
201
202         /// returns the main font for the buffer (document)
203         Font const getFont() const;
204
205         /// translate quote style string to enum value
206         InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
207
208         /* these are for the PaperLayout */
209         /// the papersize
210         PAPER_SIZE papersize;
211         ///
212         PAPER_ORIENTATION orientation;
213         /// use custom margins
214         bool use_geometry;
215         ///
216         std::string paperwidth;
217         ///
218         std::string paperheight;
219         ///
220         std::string leftmargin;
221         ///
222         std::string topmargin;
223         ///
224         std::string rightmargin;
225         ///
226         std::string bottommargin;
227         ///
228         std::string headheight;
229         ///
230         std::string headsep;
231         ///
232         std::string footskip;
233         ///
234         std::string columnsep;
235
236         /* some LaTeX options */
237         /// The graphics driver
238         std::string graphics_driver;
239         /// The default output format
240         std::string default_output_format;
241         /// customized bibliography processor
242         std::string bibtex_command;
243         /// customized index processor
244         std::string index_command;
245         /// font encoding(s) requested for this document
246         std::string fontenc;
247         /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
248         std::string fonts_roman[2];
249         /// the rm font
250         std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
251         /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
252         std::string fonts_sans[2];
253         /// the sf font
254         std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
255         /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
256         std::string fonts_typewriter[2];
257         /// the tt font
258         std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
259         /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
260         std::string fonts_math[2];
261         /// the math font
262         std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
263         /// the default family (rm, sf, tt)
264         std::string fonts_default_family;
265         /// use the fonts of the OS (OpenType, True Type) directly
266         bool useNonTeXFonts;
267         /// use expert Small Caps
268         bool fonts_expert_sc;
269         /// use Old Style Figures
270         bool fonts_old_figures;
271         /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
272         int fonts_sans_scale[2];
273         /// the scale factor of the sf font
274         int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
275         /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
276         int fonts_typewriter_scale[2];
277         /// the scale factor of the tt font
278         int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
279         /// the font used by the CJK command
280         std::string fonts_cjk;
281         /// use LaTeX microtype package
282         bool use_microtype;
283         ///
284         Spacing & spacing();
285         Spacing const & spacing() const;
286         ///
287         int secnumdepth;
288         ///
289         int tocdepth;
290         ///
291         Language const * language;
292         /// language package
293         std::string lang_package;
294         /// BranchList:
295         BranchList & branchlist();
296         BranchList const & branchlist() const;
297         /// IndicesList:
298         IndicesList & indiceslist();
299         IndicesList const & indiceslist() const;
300         /**
301          * The LyX name of the input encoding for LaTeX. This can be one of
302          * - \c auto: find out the input encoding from the used languages
303          * - \c default: ditto
304          * - any encoding defined in the file lib/encodings
305          * The encoding of the LyX file is always utf8 and has nothing to
306          * do with this setting.
307          * The difference between \c auto and \c default is that \c auto also
308          * causes loading of the inputenc package, while \c default does not.
309          * \c default will not work unless the user takes additional measures
310          * (such as using special environments like the CJK environment from
311          * CJK.sty).
312          * \c default can be seen as an unspecified 8bit encoding, since LyX
313          * does not interpret it in any way apart from display on screen.
314          */
315         std::string inputenc;
316         /// The main encoding used by this buffer for LaTeX output.
317         /// Individual pieces of text can use different encodings.
318         /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
319         /// instead of the value returned by this function.
320         Encoding const & encoding() const;
321         ///
322         std::string origin;
323         ///
324         docstring preamble;
325         ///
326         std::string options;
327         /// use the class options defined in the layout?
328         bool use_default_options;
329         ///
330         std::string master;
331         ///
332         bool suppress_date;
333         ///
334         std::string float_placement;
335         ///
336         unsigned int columns;
337         ///
338         bool justification;
339         /// parameters for the listings package
340         std::string listings_params;
341         ///
342         PageSides sides;
343         ///
344         std::string pagestyle;
345         ///
346         RGBColor backgroundcolor;
347         ///
348         bool isbackgroundcolor;
349         ///
350         RGBColor fontcolor;
351         ///
352         bool isfontcolor;
353         ///
354         RGBColor notefontcolor;
355         ///
356         RGBColor boxbgcolor;
357         /// \param index should lie in the range 0 <= \c index <= 3.
358         Bullet & temp_bullet(size_type index);
359         Bullet const & temp_bullet(size_type index) const;
360         /// \param index should lie in the range 0 <= \c index <= 3.
361         Bullet & user_defined_bullet(size_type index);
362         Bullet const & user_defined_bullet(size_type index) const;
363
364         /// Whether to load a package such as amsmath or esint.
365         /// The enum values must not be changed (file format!)
366         enum Package {
367                 /// Don't load the package. For experts only.
368                 package_off = 0,
369                 /// Load the package if needed (recommended)
370                 package_auto = 1,
371                 /// Always load the package (e.g. if the document contains
372                 /// some ERT that needs the package)
373                 package_on = 2
374         };
375         /// Whether to load a package such as amsmath or esint.
376         Package use_package(std::string const & p) const;
377         /// Set whether to load a package such as amsmath or esint.
378         void use_package(std::string const & p, Package u);
379         /// All packages that can be switched on or off
380         static std::map<std::string, std::string> const & auto_packages();
381         /// Split bibliography?
382         bool useBibtopic() const { return use_bibtopic && !useBiblatex(); }
383         /// Set split bibliography
384         void bibtopic(bool const b) { use_bibtopic = b; }
385         /// Split the index?
386         bool use_indices;
387         /// Save transient properties?
388         bool save_transient_properties;
389         /// revision tracking for this buffer ? (this is a transient property)
390         bool track_changes;
391         /** This param decides whether change tracking marks should be used
392          *  in output (irrespective of how these marks are actually defined;
393          *  for instance, they may differ for DVI and PDF generation)
394          *  This is a transient property.
395          */
396         bool output_changes;
397         ///
398         bool compressed;
399
400         /// the author list for the document
401         AuthorList & authors();
402         AuthorList const & authors() const;
403         void addAuthor(Author a);
404
405         /// map of the file's author IDs to AuthorList indexes
406         typedef std::map<int, int> AuthorMap;
407         AuthorMap author_map_;
408
409         /// the buffer's active font encoding
410         std::string const font_encoding() const;
411         /// all font encodings requested by the prefs/document/main language.
412         /// This does NOT include font encodings required by secondary languages
413         std::vector<std::string> const font_encodings() const;
414
415         ///
416         std::string const dvips_options() const;
417         /** The return value of paperSizeName() depends on the
418          *  purpose for which the paper size is needed, since they
419          *  support different subsets of paper sizes.
420         */
421         enum PapersizePurpose {
422                 ///
423                 DVIPS,
424                 ///
425                 DVIPDFM,
426                 ///
427                 XDVI
428         };
429         ///
430         std::string paperSizeName(PapersizePurpose purpose) const;
431         /// set up if and how babel is called
432         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
433         /// return supported drivers for specific packages
434         docstring getGraphicsDriver(std::string const & package) const;
435         /// handle inputenc etc.
436         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
437         ///
438         std::string const parseFontName(std::string const & name) const;
439         /// set up the document fonts
440         std::string const loadFonts(LaTeXFeatures & features) const;
441
442         /// the cite engine modules
443         LayoutModuleList const & citeEngine() const
444                 { return cite_engine_; }
445         /// the type of cite engine (authoryear or numerical)
446         CiteEngineType const & citeEngineType() const
447                 { return cite_engine_type_; }
448         /// add the module to the cite engine modules
449         bool addCiteEngine(std::string const &);
450         /// add the modules to the cite engine modules
451         bool addCiteEngine(std::vector<std::string> const &);
452         /// clear the list of cite engine modules
453         void clearCiteEngine() { cite_engine_.clear(); }
454         /// set the cite engine module
455         void setCiteEngine(std::string const &);
456         /// set the cite engine modules
457         void setCiteEngine(std::vector<std::string> const &);
458         /// set the cite engine type
459         void setCiteEngineType(CiteEngineType const & engine_type)
460                 { cite_engine_type_ = engine_type; }
461
462         /// the available citation commands
463         std::vector<std::string> citeCommands() const;
464         /// the available citation styles
465         std::vector<CitationStyle> citeStyles() const;
466
467         /// Return the actual bibtex command (lyxrc or buffer param)
468         std::string const bibtexCommand() const;
469
470         /// Are we using biblatex?
471         bool useBiblatex() const;
472
473         /// Set the default BibTeX style file for the document
474         void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
475         /// Get the default BibTeX style file from the TextClass
476         std::string const & defaultBiblioStyle() const;
477         /// whether the BibTeX style supports full author lists
478         bool const & fullAuthorList() const;
479         /// Check if a citation style is an alias to another style
480         std::string getCiteAlias(std::string const & s) const;
481
482         /// Options of the bibiography package
483         std::string biblio_opts;
484         /// The biblatex bibliography style
485         std::string biblatex_bibstyle;
486         /// The biblatex citation style
487         std::string biblatex_citestyle;
488
489         /// options for pdf output
490         PDFOptions & pdfoptions();
491         PDFOptions const & pdfoptions() const;
492
493         // do not change these values. we rely upon them.
494         enum MathOutput {
495                 MathML = 0,
496                 HTML = 1,
497                 Images = 2,
498                 LaTeX = 3
499         };
500         /// what to use for math output. present choices are above
501         MathOutput html_math_output;
502         /// whether to attempt to be XHTML 1.1 compliant or instead be
503         /// a little more mellow
504         bool html_be_strict;
505         ///
506         double html_math_img_scale;
507         ///
508         double display_pixel_ratio;
509         ///
510         std::string html_latex_start;
511         ///
512         std::string html_latex_end;
513         ///
514         bool html_css_as_file;
515         /// generate output usable for reverse/forward search
516         bool output_sync;
517         /// custom LaTeX macro from user instead our own
518         std::string output_sync_macro;
519         /// use refstyle? or prettyref?
520         bool use_refstyle;
521
522         /// Return true if language could be set to lang,
523         /// otherwise return false and do not change language
524         bool setLanguage(std::string const & lang);
525         ///
526         void invalidateConverterCache() const;
527
528 private:
529         ///
530         void readPreamble(Lexer &);
531         ///
532         void readLocalLayout(Lexer &, bool);
533         ///
534         void readLanguage(Lexer &);
535         ///
536         void readGraphicsDriver(Lexer &);
537         ///
538         void readBullets(Lexer &);
539         ///
540         void readBulletsLaTeX(Lexer &);
541         ///
542         void readModules(Lexer &);
543         ///
544         void readRemovedModules(Lexer &);
545         ///
546         void readIncludeonly(Lexer &);
547         /// A cache for the default flavors
548         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
549         ///
550         mutable DefaultFlavorCache default_flavors_;
551         /// the cite engine modules
552         LayoutModuleList cite_engine_;
553         /// the type of cite engine (authoryear or numerical)
554         CiteEngineType cite_engine_type_;
555         /// the default BibTeX style file for the document
556         std::string biblio_style;
557         /// Split bibliography?
558         bool use_bibtopic;
559         ///
560         DocumentClassPtr doc_class_;
561         ///
562         LayoutModuleList layout_modules_;
563         /// this is for modules that are required by the document class but that
564         /// the user has chosen not to use
565         std::list<std::string> removed_modules_;
566         /// The local layouts without the forced ones
567         docstring local_layout_;
568         /// Forced local layouts only for reading (use getLocalLayout() instead)
569         docstring forced_local_layout_;
570
571         /// the list of included children (for includeonly)
572         std::list<std::string> included_children_;
573
574         typedef std::map<std::string, Package> PackageMap;
575         /** Whether and how to load packages like amsmath, esint, mhchem,
576          *  mathdots, stackrel, stmaryrd and undertilde.
577          */
578         PackageMap use_packages;
579
580         /** Use the Pimpl idiom to hide those member variables that would otherwise
581          *  drag in other header files.
582          */
583         class Impl;
584         class MemoryTraits {
585         public:
586                 static Impl * clone(Impl const *);
587                 static void destroy(Impl *);
588         };
589         support::copied_ptr<Impl, MemoryTraits> pimpl_;
590
591 };
592
593 } // namespace lyx
594
595 #endif