]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Cmake export tests: Handle attic files with now missing references to png graphics
[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         /// revision tracking for this buffer ?
385         bool track_changes;
386         /** This param decides whether change tracking marks should be used
387          *  in output (irrespective of how these marks are actually defined;
388          *  for instance, they may differ for DVI and PDF generation)
389          */
390         bool output_changes;
391         ///
392         bool compressed;
393
394         /// the author list for the document
395         AuthorList & authors();
396         AuthorList const & authors() const;
397         void addAuthor(Author a);
398
399         /// map of the file's author IDs to AuthorList indexes
400         typedef std::map<int, int> AuthorMap;
401         AuthorMap author_map_;
402
403         /// the buffer's active font encoding
404         std::string const font_encoding() const;
405         /// all font encodings requested by the prefs/document/main language.
406         /// This does NOT include font encodings required by secondary languages
407         std::vector<std::string> const font_encodings() const;
408
409         ///
410         std::string const dvips_options() const;
411         /** The return value of paperSizeName() depends on the
412          *  purpose for which the paper size is needed, since they
413          *  support different subsets of paper sizes.
414         */
415         enum PapersizePurpose {
416                 ///
417                 DVIPS,
418                 ///
419                 DVIPDFM,
420                 ///
421                 XDVI
422         };
423         ///
424         std::string paperSizeName(PapersizePurpose purpose) const;
425         /// set up if and how babel is called
426         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
427         /// return supported drivers for specific packages
428         docstring getGraphicsDriver(std::string const & package) const;
429         /// handle inputenc etc.
430         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
431         ///
432         std::string const parseFontName(std::string const & name) const;
433         /// set up the document fonts
434         std::string const loadFonts(LaTeXFeatures & features) const;
435
436         /// the cite engine modules
437         LayoutModuleList const & citeEngine() const
438                 { return cite_engine_; }
439         /// the type of cite engine (authoryear or numerical)
440         CiteEngineType const & citeEngineType() const
441                 { return cite_engine_type_; }
442         /// add the module to the cite engine modules
443         bool addCiteEngine(std::string const &);
444         /// add the modules to the cite engine modules
445         bool addCiteEngine(std::vector<std::string> const &);
446         /// clear the list of cite engine modules
447         void clearCiteEngine() { cite_engine_.clear(); }
448         /// set the cite engine module
449         void setCiteEngine(std::string const &);
450         /// set the cite engine modules
451         void setCiteEngine(std::vector<std::string> const &);
452         /// set the cite engine type
453         void setCiteEngineType(CiteEngineType const & engine_type)
454                 { cite_engine_type_ = engine_type; }
455
456         /// the available citation commands
457         std::vector<std::string> citeCommands() const;
458         /// the available citation styles
459         std::vector<CitationStyle> citeStyles() const;
460
461         /// the default BibTeX style file for the document
462         std::string biblio_style;
463         /// the default BibTeX style file from the TextClass
464         std::string const & defaultBiblioStyle() const;
465         /// whether the BibTeX style supports full author lists
466         bool const & fullAuthorList() const;
467
468         /// options for pdf output
469         PDFOptions & pdfoptions();
470         PDFOptions const & pdfoptions() const;
471
472         // do not change these values. we rely upon them.
473         enum MathOutput {
474                 MathML = 0,
475                 HTML = 1,
476                 Images = 2,
477                 LaTeX = 3
478         };
479         /// what to use for math output. present choices are above
480         MathOutput html_math_output;
481         /// whether to attempt to be XHTML 1.1 compliant or instead be
482         /// a little more mellow
483         bool html_be_strict;
484         ///
485         double html_math_img_scale;
486         ///
487         double display_pixel_ratio;
488         ///
489         std::string html_latex_start;
490         ///
491         std::string html_latex_end;
492         ///
493         bool html_css_as_file;
494         /// generate output usable for reverse/forward search
495         bool output_sync;
496         /// custom LaTeX macro from user instead our own
497         std::string output_sync_macro;
498         /// use refstyle? or prettyref?
499         bool use_refstyle;
500
501         /// Return true if language could be set to lang,
502         /// otherwise return false and do not change language
503         bool setLanguage(std::string const & lang);
504
505 private:
506         ///
507         void readPreamble(Lexer &);
508         ///
509         void readLocalLayout(Lexer &, bool);
510         ///
511         void readLanguage(Lexer &);
512         ///
513         void readGraphicsDriver(Lexer &);
514         ///
515         void readBullets(Lexer &);
516         ///
517         void readBulletsLaTeX(Lexer &);
518         ///
519         void readModules(Lexer &);
520         ///
521         void readRemovedModules(Lexer &);
522         ///
523         void readIncludeonly(Lexer &);
524         /// A cache for the default flavors
525         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
526         ///
527         mutable DefaultFlavorCache default_flavors_;
528         /// the cite engine modules
529         LayoutModuleList cite_engine_;
530         /// the type of cite engine (authoryear or numerical)
531         CiteEngineType cite_engine_type_;
532         ///
533         DocumentClassPtr doc_class_;
534         ///
535         LayoutModuleList layout_modules_;
536         /// this is for modules that are required by the document class but that
537         /// the user has chosen not to use
538         std::list<std::string> removed_modules_;
539         /// The local layouts without the forced ones
540         std::string local_layout_;
541         /// Forced local layouts only for reading (use getLocalLayout() instead)
542         std::string forced_local_layout_;
543
544         /// the list of included children (for includeonly)
545         std::list<std::string> included_children_;
546
547         typedef std::map<std::string, Package> PackageMap;
548         /** Whether and how to load packages like amsmath, esint, mhchem,
549          *  mathdots, stackrel, stmaryrd and undertilde.
550          */
551         PackageMap use_packages;
552
553         /** Use the Pimpl idiom to hide those member variables that would otherwise
554          *  drag in other header files.
555          */
556         class Impl;
557         class MemoryTraits {
558         public:
559                 static Impl * clone(Impl const *);
560                 static void destroy(Impl *);
561         };
562         support::copied_ptr<Impl, MemoryTraits> pimpl_;
563
564 };
565
566 } // namespace lyx
567
568 #endif