]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
f4f9bef8e0ea068db854a26bda9eaa950b99df1f
[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 &) 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         InsetQuotes::QuoteTimes quotes_times;
114         ///
115         std::string fontsize;
116         /// Get the LayoutFile this document is using.
117         LayoutFile const * baseClass() const;
118         ///
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         void makeDocumentClass();
128         /// Returns the DocumentClass currently in use: the BaseClass as modified
129         /// by modules.
130         DocumentClass const & documentClass() const;
131         /// \return A pointer to the DocumentClass currently in use: the BaseClass
132         /// as modified by modules.
133         DocumentClassConstPtr  documentClassPtr() const;
134         /// This bypasses the baseClass and sets the textClass directly.
135         /// Should be called with care and would be better not being here,
136         /// but it seems to be needed by CutAndPaste::putClipboard().
137         void setDocumentClass(DocumentClassConstPtr);
138         /// List of modules in use
139         LayoutModuleList const & getModules() const { return layout_modules_; }
140         /// List of default modules the user has removed
141         std::list<std::string> const & getRemovedModules() const
142                         { return removed_modules_; }
143         ///
144         /// Add a module to the list of modules in use. This checks only that the
145         /// module is not already in the list, so use moduleIsCompatible first if
146         /// you want to check for compatibility.
147         /// \return true if module was successfully added.
148         bool addLayoutModule(std::string const & modName);
149         /// checks to make sure module's requriements are satisfied, that it does
150         /// not conflict with already-present modules, isn't already loaded, etc.
151         bool moduleCanBeAdded(std::string const & modName) const;
152         ///
153         void addRemovedModule(std::string const & modName)
154                         { removed_modules_.push_back(modName); }
155         /// Clear the list
156         void clearLayoutModules() { layout_modules_.clear(); }
157         /// Clear the removed module list
158         void clearRemovedModules() { removed_modules_.clear(); }
159
160         /// returns \c true if the buffer contains a LaTeX document
161         bool isLatex() const;
162         /// returns \c true if the buffer contains a DocBook document
163         bool isDocBook() const;
164         /// returns \c true if the buffer contains a Wed document
165         bool isLiterate() const;
166
167         /// return the format of the buffer on a string
168         std::string bufferFormat() const;
169         /// return the default output format of the current backend
170         std::string getDefaultOutputFormat() const;
171         /// return the output flavor of \p format or the default
172         OutputParams::FLAVOR getOutputFlavor(
173                   std::string const format = std::string()) const;
174         ///
175         bool isExportable(std::string const & format) const;
176         ///
177         std::vector<Format const *> exportableFormats(bool only_viewable) const;
178         ///
179         bool isExportableFormat(std::string const & format) const;
180         /// the backends appropriate for use with this document.
181         /// so, e.g., latex is excluded , if we're using non-TeX fonts
182         std::vector<std::string> backends() const;
183
184         /// List of included children (for includeonly)
185         std::list<std::string> const & getIncludedChildren() const
186                         { return included_children_; }
187         ///
188         void addIncludedChildren(std::string const & child)
189                         { included_children_.push_back(child); }
190         /// Clear the list of included children
191         void clearIncludedChildren() { included_children_.clear(); }
192
193         /// update aux files of unincluded children (with \includeonly)
194         bool maintain_unincluded_children;
195
196         /// returns the main font for the buffer (document)
197         Font const getFont() const;
198
199         /* these are for the PaperLayout */
200         /// the papersize
201         PAPER_SIZE papersize;
202         ///
203         PAPER_ORIENTATION orientation;
204         /// use custom margins
205         bool use_geometry;
206         ///
207         std::string paperwidth;
208         ///
209         std::string paperheight;
210         ///
211         std::string leftmargin;
212         ///
213         std::string topmargin;
214         ///
215         std::string rightmargin;
216         ///
217         std::string bottommargin;
218         ///
219         std::string headheight;
220         ///
221         std::string headsep;
222         ///
223         std::string footskip;
224         ///
225         std::string columnsep;
226
227         /* some LaTeX options */
228         /// The graphics driver
229         std::string graphics_driver;
230         /// The default output format
231         std::string default_output_format;
232         /// customized bibliography processor
233         std::string bibtex_command;
234         /// customized index processor
235         std::string index_command;
236         /// font encoding
237         std::string fontenc;
238         /// the rm font
239         std::string fonts_roman;
240         /// the sf font
241         std::string fonts_sans;
242         /// the tt font
243         std::string fonts_typewriter;
244         /// the default family (rm, sf, tt)
245         std::string fonts_default_family;
246         /// use the fonts of the OS (OpenType, True Type) directly
247         bool useNonTeXFonts;
248         /// use expert Small Caps
249         bool fonts_expert_sc;
250         /// use Old Style Figures
251         bool fonts_old_figures;
252         /// the scale factor of the sf font
253         int fonts_sans_scale;
254         /// the scale factor of the tt font
255         int fonts_typewriter_scale;
256         /// the font used by the CJK command
257         std::string fonts_cjk;
258         ///
259         Spacing & spacing();
260         Spacing const & spacing() const;
261         ///
262         int secnumdepth;
263         ///
264         int tocdepth;
265         ///
266         Language const * language;
267         /// language package
268         std::string lang_package;
269         /// BranchList:
270         BranchList & branchlist();
271         BranchList const & branchlist() const;
272         /// IndicesList:
273         IndicesList & indiceslist();
274         IndicesList const & indiceslist() const;
275         /**
276          * The input encoding for LaTeX. This can be one of
277          * - \c auto: find out the input encoding from the used languages
278          * - \c default: ditto
279          * - any encoding supported by the inputenc package
280          * The encoding of the LyX file is always utf8 and has nothing to
281          * do with this setting.
282          * The difference between \c auto and \c default is that \c auto also
283          * causes loading of the inputenc package, while \c default does not.
284          * \c default will not work unless the user takes additional measures
285          * (such as using special environments like the CJK environment from
286          * CJK.sty).
287          * \c default can be seen as an unspecified 8bit encoding, since LyX
288          * does not interpret it in any way apart from display on screen.
289          */
290         std::string inputenc;
291         /// The main encoding used by this buffer for LaTeX output.
292         /// Individual pieces of text can use different encodings.
293         Encoding const & encoding() const;
294         ///
295         std::string preamble;
296         ///
297         std::string local_layout;
298         ///
299         std::string options;
300         /// use the class options defined in the layout?
301         bool use_default_options;
302         ///
303         std::string master;
304         ///
305         bool suppress_date;
306         ///
307         std::string float_placement;
308         ///
309         unsigned int columns;
310         ///
311         bool justification;
312         /// parameters for the listings package
313         std::string listings_params;
314         ///
315         PageSides sides;
316         ///
317         std::string pagestyle;
318         ///
319         RGBColor backgroundcolor;
320         ///
321         bool isbackgroundcolor;
322         ///
323         RGBColor fontcolor;
324         ///
325         bool isfontcolor;
326         ///
327         RGBColor notefontcolor;
328         ///
329         RGBColor boxbgcolor;
330         /// \param index should lie in the range 0 <= \c index <= 3.
331         Bullet & temp_bullet(size_type index);
332         Bullet const & temp_bullet(size_type index) const;
333         /// \param index should lie in the range 0 <= \c index <= 3.
334         Bullet & user_defined_bullet(size_type index);
335         Bullet const & user_defined_bullet(size_type index) const;
336
337         /// Whether to load a package such as amsmath or esint.
338         /// The enum values must not be changed (file format!)
339         enum Package {
340                 /// Don't load the package. For experts only.
341                 package_off = 0,
342                 /// Load the package if needed (recommended)
343                 package_auto = 1,
344                 /// Always load the package (e.g. if the document contains
345                 /// some ERT that needs the package)
346                 package_on = 2
347         };
348         /// Whether to load a package such as amsmath or esint.
349         Package use_package(std::string const & p) const;
350         /// Set whether to load a package such as amsmath or esint.
351         void use_package(std::string const & p, Package u);
352         /// All packages that can be switched on or off
353         static std::vector<std::string> const & auto_packages();
354         /// Split bibliography?
355         bool use_bibtopic;
356         /// Split the index?
357         bool use_indices;
358         /// revision tracking for this buffer ?
359         bool trackChanges;
360         /** This param decides whether change tracking marks should be used
361          *  in output (irrespective of how these marks are actually defined;
362          *  for instance, they may differ for DVI and PDF generation)
363          */
364         bool outputChanges;
365         ///
366         bool compressed;
367
368         /// the author list for the document
369         AuthorList & authors();
370         AuthorList const & authors() const;
371
372         /// map of the file's author IDs to AuthorList indexes
373         typedef std::map<int, int> AuthorMap;
374         AuthorMap author_map;
375         /// the buffer's font encoding
376         std::string const font_encoding() const;
377         ///
378         std::string const dvips_options() const;
379         /** The return value of paperSizeName() depends on the
380          *  purpose for which the paper size is needed, since they
381          *  support different subsets of paper sizes.
382         */
383         enum PapersizePurpose {
384                 ///
385                 DVIPS,
386                 ///
387                 DVIPDFM,
388                 ///
389                 XDVI
390         };
391         ///
392         std::string paperSizeName(PapersizePurpose purpose) const;
393         /// set up if and how babel is called
394         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
395         /// return supported drivers for specific packages
396         docstring getGraphicsDriver(std::string const & package) const;
397         /// handle inputenc etc.
398         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
399         ///
400         std::string const parseFontName(std::string const & name) const;
401         /// set up the document fonts
402         std::string const loadFonts(std::string const & rm,
403                                      std::string const & sf, std::string const & tt,
404                                      bool const & sc, bool const & osf,
405                                      int const & sfscale, int const & ttscale,
406                                      bool const & use_nonlatexfonts,
407                                      LaTeXFeatures & features) const;
408
409         /// the cite engine modules
410         LayoutModuleList const & citeEngine() const
411                 { return cite_engine_; }
412         /// the type of cite engine (authoryear or numerical)
413         CiteEngineType const & citeEngineType() const
414                 { return cite_engine_type_; }
415         /// add the module to the cite engine modules
416         bool addCiteEngine(std::string const &);
417         /// add the modules to the cite engine modules
418         bool addCiteEngine(std::vector<std::string> const &);
419         /// clear the list of cite engine modules
420         void clearCiteEngine() { cite_engine_.clear(); }
421         /// set the cite engine module
422         void setCiteEngine(std::string const &);
423         /// set the cite engine modules
424         void setCiteEngine(std::vector<std::string> const &);
425         /// set the cite engine type
426         void setCiteEngineType(CiteEngineType const & engine_type)
427                 { cite_engine_type_ = engine_type; }
428
429         /// the available citation commands
430         std::vector<std::string> citeCommands() const;
431         /// the available citation styles
432         std::vector<CitationStyle> citeStyles() const;
433
434         /// the default BibTeX style file for the document
435         std::string biblio_style;
436         /// the default BibTeX style file from the TextClass
437         std::string const & defaultBiblioStyle() const;
438         /// whether the BibTeX style supports full author lists
439         bool const & fullAuthorList() const;
440
441         /// options for pdf output
442         PDFOptions & pdfoptions();
443         PDFOptions const & pdfoptions() const;
444
445         // do not change these values. we rely upon them.
446         enum MathOutput {
447                 MathML = 0,
448                 HTML = 1,
449                 Images = 2,
450                 LaTeX = 3
451         };
452         /// what to use for math output. present choices are above
453         MathOutput html_math_output;
454         /// whether to attempt to be XHTML 1.1 compliant or instead be
455         /// a little more mellow
456         bool html_be_strict;
457         ///
458         double html_math_img_scale;
459         ///
460         std::string html_latex_start;
461         ///
462         std::string html_latex_end;
463         ///
464         bool html_css_as_file;
465         /// generate output usable for reverse/forward search
466         bool output_sync;
467         /// custom LaTeX macro from user instead our own
468         std::string output_sync_macro;
469         /// use refstyle? or prettyref?
470         bool use_refstyle;
471
472         /// Return true if language could be set to lang,
473         /// otherwise return false and do not change language
474         bool setLanguage(std::string const & lang);
475
476 private:
477         ///
478         void readPreamble(Lexer &);
479         ///
480         void readLocalLayout(Lexer &);
481         ///
482         void readLanguage(Lexer &);
483         ///
484         void readGraphicsDriver(Lexer &);
485         ///
486         void readBullets(Lexer &);
487         ///
488         void readBulletsLaTeX(Lexer &);
489         ///
490         void readModules(Lexer &);
491         ///
492         void readRemovedModules(Lexer &);
493         ///
494         void readIncludeonly(Lexer &);
495         /// A cache for the default flavors
496         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
497         ///
498         mutable DefaultFlavorCache default_flavors_;
499         /// the cite engine modules
500         LayoutModuleList cite_engine_;
501         /// the type of cite engine (authoryear or numerical)
502         CiteEngineType cite_engine_type_;
503         ///
504         DocumentClassPtr doc_class_;
505         ///
506         LayoutModuleList layout_modules_;
507         /// this is for modules that are required by the document class but that
508         /// the user has chosen not to use
509         std::list<std::string> removed_modules_;
510
511         /// the list of included children (for includeonly)
512         std::list<std::string> included_children_;
513
514         typedef std::map<std::string, Package> PackageMap;
515         /** Whether and how to load packages like amsmath, esint, mhchem,
516          *  mathdots and undertilde.
517          */
518         PackageMap use_packages;
519
520         /** Use the Pimpl idiom to hide those member variables that would otherwise
521          *  drag in other header files.
522          */
523         class Impl;
524         class MemoryTraits {
525         public:
526                 static Impl * clone(Impl const *);
527                 static void destroy(Impl *);
528         };
529         support::copied_ptr<Impl, MemoryTraits> pimpl_;
530
531 };
532
533 } // namespace lyx
534
535 #endif