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