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