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