]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Add Qt's Svg module to the list of used modules. This is required to allow the use...
[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 "Citation.h"
19 #include "DocumentClassPtr.h"
20 #include "Format.h"
21 #include "LayoutModuleList.h"
22 #include "OutputParams.h"
23 #include "paper.h"
24
25 #include "insets/InsetQuotes.h"
26
27 #include "support/copied_ptr.h"
28
29 #include <map>
30 #include <vector>
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class AuthorList;
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 LatexFeatures;
46 class LayoutFile;
47 class LayoutFileIndex;
48 class Lexer;
49 class PDFOptions;
50 class Spacing;
51 class TexRow;
52 class VSpace;
53
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
57  *  is in public.
58  */
59 class BufferParams {
60 public:
61         ///
62         enum ParagraphSeparation {
63                 ///
64                 ParagraphIndentSeparation,
65                 ///
66                 ParagraphSkipSeparation
67         };
68         ///
69         BufferParams();
70
71         /// get l10n translated to the buffers language
72         docstring B_(std::string const & l10n) const;
73
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);
78
79         ///
80         void writeFile(std::ostream &, Buffer const *) const;
81
82         /// check what features are implied by the buffer parameters.
83         void validate(LaTeXFeatures &) const;
84
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...
88          */
89         bool writeLaTeX(otexstream &, LaTeXFeatures &,
90                         support::FileName const &) const;
91
92         ///
93         void useClassDefaults();
94         ///
95         bool hasClassDefaults() const;
96
97         ///
98         HSpace const & getIndentation() const;
99         ///
100         void setIndentation(HSpace const & indent);
101         ///
102         VSpace const & getDefSkip() const;
103         ///
104         void setDefSkip(VSpace const & vs);
105
106         /** Whether paragraphs are separated by using a indent like in
107          *  articles or by using a little skip like in letters.
108          */
109         ParagraphSeparation paragraph_separation;
110         ///
111         InsetQuotes::QuoteLanguage quotes_language;
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         std::string getLocalLayout(bool) const;
165         /// Set the local layouts
166         void setLocalLayout(std::string const &, bool);
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) const;
184         ///
185         std::vector<Format const *> exportableFormats(bool only_viewable) const;
186         ///
187         bool isExportableFormat(std::string const & format) const;
188         /// the backends appropriate for use with this document.
189         /// so, e.g., latex is excluded , if we're using non-TeX fonts
190         std::vector<std::string> backends() const;
191
192         /// List of included children (for includeonly)
193         std::list<std::string> const & getIncludedChildren() const
194                         { return included_children_; }
195         ///
196         void addIncludedChildren(std::string const & child)
197                         { included_children_.push_back(child); }
198         /// Clear the list of included children
199         void clearIncludedChildren() { included_children_.clear(); }
200
201         /// update aux files of unincluded children (with \includeonly)
202         bool maintain_unincluded_children;
203
204         /// returns the main font for the buffer (document)
205         Font const getFont() const;
206
207         /// translate quote style string to enum value
208         InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const;
209
210         /* these are for the PaperLayout */
211         /// the papersize
212         PAPER_SIZE papersize;
213         ///
214         PAPER_ORIENTATION orientation;
215         /// use custom margins
216         bool use_geometry;
217         ///
218         std::string paperwidth;
219         ///
220         std::string paperheight;
221         ///
222         std::string leftmargin;
223         ///
224         std::string topmargin;
225         ///
226         std::string rightmargin;
227         ///
228         std::string bottommargin;
229         ///
230         std::string headheight;
231         ///
232         std::string headsep;
233         ///
234         std::string footskip;
235         ///
236         std::string columnsep;
237
238         /* some LaTeX options */
239         /// The graphics driver
240         std::string graphics_driver;
241         /// The default output format
242         std::string default_output_format;
243         /// customized bibliography processor
244         std::string bibtex_command;
245         /// customized index processor
246         std::string index_command;
247         /// font encoding(s) requested for this document
248         std::string fontenc;
249         /// the rm font
250         std::string fonts_roman;
251         /// the sf font
252         std::string fonts_sans;
253         /// the tt font
254         std::string fonts_typewriter;
255         /// the math font
256         std::string fonts_math;
257         /// the default family (rm, sf, tt)
258         std::string fonts_default_family;
259         /// use the fonts of the OS (OpenType, True Type) directly
260         bool useNonTeXFonts;
261         /// use expert Small Caps
262         bool fonts_expert_sc;
263         /// use Old Style Figures
264         bool fonts_old_figures;
265         /// the scale factor of the sf font
266         int fonts_sans_scale;
267         /// the scale factor of the tt font
268         int fonts_typewriter_scale;
269         /// the font used by the CJK command
270         std::string fonts_cjk;
271         ///
272         Spacing & spacing();
273         Spacing const & spacing() const;
274         ///
275         int secnumdepth;
276         ///
277         int tocdepth;
278         ///
279         Language const * language;
280         /// language package
281         std::string lang_package;
282         /// BranchList:
283         BranchList & branchlist();
284         BranchList const & branchlist() const;
285         /// IndicesList:
286         IndicesList & indiceslist();
287         IndicesList const & indiceslist() const;
288         /**
289          * The LyX name of the input encoding for LaTeX. This can be one of
290          * - \c auto: find out the input encoding from the used languages
291          * - \c default: ditto
292          * - any encoding defined in the file lib/encodings
293          * The encoding of the LyX file is always utf8 and has nothing to
294          * do with this setting.
295          * The difference between \c auto and \c default is that \c auto also
296          * causes loading of the inputenc package, while \c default does not.
297          * \c default will not work unless the user takes additional measures
298          * (such as using special environments like the CJK environment from
299          * CJK.sty).
300          * \c default can be seen as an unspecified 8bit encoding, since LyX
301          * does not interpret it in any way apart from display on screen.
302          */
303         std::string inputenc;
304         /// The main encoding used by this buffer for LaTeX output.
305         /// Individual pieces of text can use different encodings.
306         Encoding const & encoding() const;
307         ///
308         std::string origin;
309         ///
310         std::string preamble;
311         ///
312         std::string options;
313         /// use the class options defined in the layout?
314         bool use_default_options;
315         ///
316         std::string master;
317         ///
318         bool suppress_date;
319         ///
320         std::string float_placement;
321         ///
322         unsigned int columns;
323         ///
324         bool justification;
325         /// parameters for the listings package
326         std::string listings_params;
327         ///
328         PageSides sides;
329         ///
330         std::string pagestyle;
331         ///
332         RGBColor backgroundcolor;
333         ///
334         bool isbackgroundcolor;
335         ///
336         RGBColor fontcolor;
337         ///
338         bool isfontcolor;
339         ///
340         RGBColor notefontcolor;
341         ///
342         RGBColor boxbgcolor;
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;
349
350         /// Whether to load a package such as amsmath or esint.
351         /// The enum values must not be changed (file format!)
352         enum Package {
353                 /// Don't load the package. For experts only.
354                 package_off = 0,
355                 /// Load the package if needed (recommended)
356                 package_auto = 1,
357                 /// Always load the package (e.g. if the document contains
358                 /// some ERT that needs the package)
359                 package_on = 2
360         };
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?
368         bool use_bibtopic;
369         /// Split the index?
370         bool use_indices;
371         /// revision tracking for this buffer ?
372         bool track_changes;
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)
376          */
377         bool output_changes;
378         ///
379         bool compressed;
380
381         /// the author list for the document
382         AuthorList & authors();
383         AuthorList const & authors() const;
384
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 active font encoding
389         std::string const font_encoding() const;
390         /// all font encodings requested by the prefs/document/main language.
391         /// This does NOT include font encodings required by secondary languages
392         std::vector<std::string> const font_encodings() const;
393
394         ///
395         std::string const dvips_options() const;
396         /** The return value of paperSizeName() depends on the
397          *  purpose for which the paper size is needed, since they
398          *  support different subsets of paper sizes.
399         */
400         enum PapersizePurpose {
401                 ///
402                 DVIPS,
403                 ///
404                 DVIPDFM,
405                 ///
406                 XDVI
407         };
408         ///
409         std::string paperSizeName(PapersizePurpose purpose) const;
410         /// set up if and how babel is called
411         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
412         /// return supported drivers for specific packages
413         docstring getGraphicsDriver(std::string const & package) const;
414         /// handle inputenc etc.
415         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
416         ///
417         std::string const parseFontName(std::string const & name) const;
418         /// set up the document fonts
419         std::string const loadFonts(LaTeXFeatures & features) const;
420
421         /// the cite engine modules
422         LayoutModuleList const & citeEngine() const
423                 { return cite_engine_; }
424         /// the type of cite engine (authoryear or numerical)
425         CiteEngineType const & citeEngineType() const
426                 { return cite_engine_type_; }
427         /// add the module to the cite engine modules
428         bool addCiteEngine(std::string const &);
429         /// add the modules to the cite engine modules
430         bool addCiteEngine(std::vector<std::string> const &);
431         /// clear the list of cite engine modules
432         void clearCiteEngine() { cite_engine_.clear(); }
433         /// set the cite engine module
434         void setCiteEngine(std::string const &);
435         /// set the cite engine modules
436         void setCiteEngine(std::vector<std::string> const &);
437         /// set the cite engine type
438         void setCiteEngineType(CiteEngineType const & engine_type)
439                 { cite_engine_type_ = engine_type; }
440
441         /// the available citation commands
442         std::vector<std::string> citeCommands() const;
443         /// the available citation styles
444         std::vector<CitationStyle> citeStyles() const;
445
446         /// the default BibTeX style file for the document
447         std::string biblio_style;
448         /// the default BibTeX style file from the TextClass
449         std::string const & defaultBiblioStyle() const;
450         /// whether the BibTeX style supports full author lists
451         bool const & fullAuthorList() const;
452
453         /// options for pdf output
454         PDFOptions & pdfoptions();
455         PDFOptions const & pdfoptions() const;
456
457         // do not change these values. we rely upon them.
458         enum MathOutput {
459                 MathML = 0,
460                 HTML = 1,
461                 Images = 2,
462                 LaTeX = 3
463         };
464         /// what to use for math output. present choices are above
465         MathOutput html_math_output;
466         /// whether to attempt to be XHTML 1.1 compliant or instead be
467         /// a little more mellow
468         bool html_be_strict;
469         ///
470         double html_math_img_scale;
471         ///
472         double display_pixel_ratio;
473         ///
474         std::string html_latex_start;
475         ///
476         std::string html_latex_end;
477         ///
478         bool html_css_as_file;
479         /// generate output usable for reverse/forward search
480         bool output_sync;
481         /// custom LaTeX macro from user instead our own
482         std::string output_sync_macro;
483         /// use refstyle? or prettyref?
484         bool use_refstyle;
485
486         /// Return true if language could be set to lang,
487         /// otherwise return false and do not change language
488         bool setLanguage(std::string const & lang);
489
490 private:
491         ///
492         void readPreamble(Lexer &);
493         ///
494         void readLocalLayout(Lexer &, bool);
495         ///
496         void readLanguage(Lexer &);
497         ///
498         void readGraphicsDriver(Lexer &);
499         ///
500         void readBullets(Lexer &);
501         ///
502         void readBulletsLaTeX(Lexer &);
503         ///
504         void readModules(Lexer &);
505         ///
506         void readRemovedModules(Lexer &);
507         ///
508         void readIncludeonly(Lexer &);
509         /// A cache for the default flavors
510         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
511         ///
512         mutable DefaultFlavorCache default_flavors_;
513         /// the cite engine modules
514         LayoutModuleList cite_engine_;
515         /// the type of cite engine (authoryear or numerical)
516         CiteEngineType cite_engine_type_;
517         ///
518         DocumentClassPtr doc_class_;
519         ///
520         LayoutModuleList layout_modules_;
521         /// this is for modules that are required by the document class but that
522         /// the user has chosen not to use
523         std::list<std::string> removed_modules_;
524         /// The local layouts without the forced ones
525         std::string local_layout_;
526         /// Forced local layouts only for reading (use getLocalLayout() instead)
527         std::string forced_local_layout_;
528
529         /// the list of included children (for includeonly)
530         std::list<std::string> included_children_;
531
532         typedef std::map<std::string, Package> PackageMap;
533         /** Whether and how to load packages like amsmath, esint, mhchem,
534          *  mathdots, stackrel, stmaryrd and undertilde.
535          */
536         PackageMap use_packages;
537
538         /** Use the Pimpl idiom to hide those member variables that would otherwise
539          *  drag in other header files.
540          */
541         class Impl;
542         class MemoryTraits {
543         public:
544                 static Impl * clone(Impl const *);
545                 static void destroy(Impl *);
546         };
547         support::copied_ptr<Impl, MemoryTraits> pimpl_;
548
549 };
550
551 } // namespace lyx
552
553 #endif