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