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