]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Update my email and status.
[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         /// 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
133         /// by modules.
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_; }
147         ///
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;
158         ///
159         void addRemovedModule(std::string const & modName)
160                         { removed_modules_.push_back(modName); }
161         /// Clear the list
162         void clearLayoutModules() { layout_modules_.clear(); }
163         /// Clear the removed module list
164         void clearRemovedModules() { removed_modules_.clear(); }
165
166         /// returns \c true if the buffer contains a LaTeX document
167         bool isLatex() const;
168         /// returns \c true if the buffer contains a DocBook document
169         bool isDocBook() const;
170         /// returns \c true if the buffer contains a Wed document
171         bool isLiterate() const;
172
173         /// return the format of the buffer on a string
174         std::string bufferFormat() const;
175         /// return the default output format of the current backend
176         std::string getDefaultOutputFormat() const;
177         /// return the output flavor of \p format or the default
178         OutputParams::FLAVOR getOutputFlavor(
179                   std::string const format = std::string()) const;
180         ///
181         bool isExportable(std::string const & format) const;
182         ///
183         std::vector<Format const *> exportableFormats(bool only_viewable) const;
184         ///
185         bool isExportableFormat(std::string const & format) 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         InsetQuotes::QuoteLanguage 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
246         std::string fontenc;
247         /// the rm font
248         std::string fonts_roman;
249         /// the sf font
250         std::string fonts_sans;
251         /// the tt font
252         std::string fonts_typewriter;
253         /// the math font
254         std::string fonts_math;
255         /// the default family (rm, sf, tt)
256         std::string fonts_default_family;
257         /// use the fonts of the OS (OpenType, True Type) directly
258         bool useNonTeXFonts;
259         /// use expert Small Caps
260         bool fonts_expert_sc;
261         /// use Old Style Figures
262         bool fonts_old_figures;
263         /// the scale factor of the sf font
264         int fonts_sans_scale;
265         /// the scale factor of the tt font
266         int fonts_typewriter_scale;
267         /// the font used by the CJK command
268         std::string fonts_cjk;
269         ///
270         Spacing & spacing();
271         Spacing const & spacing() const;
272         ///
273         int secnumdepth;
274         ///
275         int tocdepth;
276         ///
277         Language const * language;
278         /// language package
279         std::string lang_package;
280         /// BranchList:
281         BranchList & branchlist();
282         BranchList const & branchlist() const;
283         /// IndicesList:
284         IndicesList & indiceslist();
285         IndicesList const & indiceslist() const;
286         /**
287          * The input encoding for LaTeX. This can be one of
288          * - \c auto: find out the input encoding from the used languages
289          * - \c default: ditto
290          * - any encoding supported by the inputenc package
291          * The encoding of the LyX file is always utf8 and has nothing to
292          * do with this setting.
293          * The difference between \c auto and \c default is that \c auto also
294          * causes loading of the inputenc package, while \c default does not.
295          * \c default will not work unless the user takes additional measures
296          * (such as using special environments like the CJK environment from
297          * CJK.sty).
298          * \c default can be seen as an unspecified 8bit encoding, since LyX
299          * does not interpret it in any way apart from display on screen.
300          */
301         std::string inputenc;
302         /// The main encoding used by this buffer for LaTeX output.
303         /// Individual pieces of text can use different encodings.
304         Encoding const & encoding() const;
305         ///
306         std::string preamble;
307         ///
308         std::string local_layout;
309         ///
310         std::string options;
311         /// use the class options defined in the layout?
312         bool use_default_options;
313         ///
314         std::string master;
315         ///
316         bool suppress_date;
317         ///
318         std::string float_placement;
319         ///
320         unsigned int columns;
321         ///
322         bool justification;
323         /// parameters for the listings package
324         std::string listings_params;
325         ///
326         PageSides sides;
327         ///
328         std::string pagestyle;
329         ///
330         RGBColor backgroundcolor;
331         ///
332         bool isbackgroundcolor;
333         ///
334         RGBColor fontcolor;
335         ///
336         bool isfontcolor;
337         ///
338         RGBColor notefontcolor;
339         ///
340         RGBColor boxbgcolor;
341         /// \param index should lie in the range 0 <= \c index <= 3.
342         Bullet & temp_bullet(size_type index);
343         Bullet const & temp_bullet(size_type index) const;
344         /// \param index should lie in the range 0 <= \c index <= 3.
345         Bullet & user_defined_bullet(size_type index);
346         Bullet const & user_defined_bullet(size_type index) const;
347
348         /// Whether to load a package such as amsmath or esint.
349         /// The enum values must not be changed (file format!)
350         enum Package {
351                 /// Don't load the package. For experts only.
352                 package_off = 0,
353                 /// Load the package if needed (recommended)
354                 package_auto = 1,
355                 /// Always load the package (e.g. if the document contains
356                 /// some ERT that needs the package)
357                 package_on = 2
358         };
359         /// Whether to load a package such as amsmath or esint.
360         Package use_package(std::string const & p) const;
361         /// Set whether to load a package such as amsmath or esint.
362         void use_package(std::string const & p, Package u);
363         /// All packages that can be switched on or off
364         static std::vector<std::string> const & auto_packages();
365         /// Split bibliography?
366         bool use_bibtopic;
367         /// Split the index?
368         bool use_indices;
369         /// revision tracking for this buffer ?
370         bool trackChanges;
371         /** This param decides whether change tracking marks should be used
372          *  in output (irrespective of how these marks are actually defined;
373          *  for instance, they may differ for DVI and PDF generation)
374          */
375         bool outputChanges;
376         ///
377         bool compressed;
378
379         /// the author list for the document
380         AuthorList & authors();
381         AuthorList const & authors() const;
382
383         /// map of the file's author IDs to AuthorList indexes
384         typedef std::map<int, int> AuthorMap;
385         AuthorMap author_map;
386         /// the buffer's font encoding
387         std::string const font_encoding() const;
388         ///
389         std::string const dvips_options() const;
390         /** The return value of paperSizeName() depends on the
391          *  purpose for which the paper size is needed, since they
392          *  support different subsets of paper sizes.
393         */
394         enum PapersizePurpose {
395                 ///
396                 DVIPS,
397                 ///
398                 DVIPDFM,
399                 ///
400                 XDVI
401         };
402         ///
403         std::string paperSizeName(PapersizePurpose purpose) const;
404         /// set up if and how babel is called
405         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
406         /// return supported drivers for specific packages
407         docstring getGraphicsDriver(std::string const & package) const;
408         /// handle inputenc etc.
409         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
410         ///
411         std::string const parseFontName(std::string const & name) const;
412         /// set up the document fonts
413         std::string const loadFonts(LaTeXFeatures & features) const;
414
415         /// the cite engine modules
416         LayoutModuleList const & citeEngine() const
417                 { return cite_engine_; }
418         /// the type of cite engine (authoryear or numerical)
419         CiteEngineType const & citeEngineType() const
420                 { return cite_engine_type_; }
421         /// add the module to the cite engine modules
422         bool addCiteEngine(std::string const &);
423         /// add the modules to the cite engine modules
424         bool addCiteEngine(std::vector<std::string> const &);
425         /// clear the list of cite engine modules
426         void clearCiteEngine() { cite_engine_.clear(); }
427         /// set the cite engine module
428         void setCiteEngine(std::string const &);
429         /// set the cite engine modules
430         void setCiteEngine(std::vector<std::string> const &);
431         /// set the cite engine type
432         void setCiteEngineType(CiteEngineType const & engine_type)
433                 { cite_engine_type_ = engine_type; }
434
435         /// the available citation commands
436         std::vector<std::string> citeCommands() const;
437         /// the available citation styles
438         std::vector<CitationStyle> citeStyles() const;
439
440         /// the default BibTeX style file for the document
441         std::string biblio_style;
442         /// the default BibTeX style file from the TextClass
443         std::string const & defaultBiblioStyle() const;
444         /// whether the BibTeX style supports full author lists
445         bool const & fullAuthorList() const;
446
447         /// options for pdf output
448         PDFOptions & pdfoptions();
449         PDFOptions const & pdfoptions() const;
450
451         // do not change these values. we rely upon them.
452         enum MathOutput {
453                 MathML = 0,
454                 HTML = 1,
455                 Images = 2,
456                 LaTeX = 3
457         };
458         /// what to use for math output. present choices are above
459         MathOutput html_math_output;
460         /// whether to attempt to be XHTML 1.1 compliant or instead be
461         /// a little more mellow
462         bool html_be_strict;
463         ///
464         double html_math_img_scale;
465         ///
466         std::string html_latex_start;
467         ///
468         std::string html_latex_end;
469         ///
470         bool html_css_as_file;
471         /// generate output usable for reverse/forward search
472         bool output_sync;
473         /// custom LaTeX macro from user instead our own
474         std::string output_sync_macro;
475         /// use refstyle? or prettyref?
476         bool use_refstyle;
477
478         /// Return true if language could be set to lang,
479         /// otherwise return false and do not change language
480         bool setLanguage(std::string const & lang);
481
482 private:
483         ///
484         void readPreamble(Lexer &);
485         ///
486         void readLocalLayout(Lexer &);
487         ///
488         void readLanguage(Lexer &);
489         ///
490         void readGraphicsDriver(Lexer &);
491         ///
492         void readBullets(Lexer &);
493         ///
494         void readBulletsLaTeX(Lexer &);
495         ///
496         void readModules(Lexer &);
497         ///
498         void readRemovedModules(Lexer &);
499         ///
500         void readIncludeonly(Lexer &);
501         /// A cache for the default flavors
502         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
503         ///
504         mutable DefaultFlavorCache default_flavors_;
505         /// the cite engine modules
506         LayoutModuleList cite_engine_;
507         /// the type of cite engine (authoryear or numerical)
508         CiteEngineType cite_engine_type_;
509         ///
510         DocumentClassPtr doc_class_;
511         ///
512         LayoutModuleList layout_modules_;
513         /// this is for modules that are required by the document class but that
514         /// the user has chosen not to use
515         std::list<std::string> removed_modules_;
516
517         /// the list of included children (for includeonly)
518         std::list<std::string> included_children_;
519
520         typedef std::map<std::string, Package> PackageMap;
521         /** Whether and how to load packages like amsmath, esint, mhchem,
522          *  mathdots, stackrel, stmaryrd and undertilde.
523          */
524         PackageMap use_packages;
525
526         /** Use the Pimpl idiom to hide those member variables that would otherwise
527          *  drag in other header files.
528          */
529         class Impl;
530         class MemoryTraits {
531         public:
532                 static Impl * clone(Impl const *);
533                 static void destroy(Impl *);
534         };
535         support::copied_ptr<Impl, MemoryTraits> pimpl_;
536
537 };
538
539 } // namespace lyx
540
541 #endif