]> git.lyx.org Git - lyx.git/blob - src/OutputParams.h
Introduce NeedCProtect -1 layout option
[lyx.git] / src / OutputParams.h
1 // -*- C++ -*-
2 /**
3  * \file OutputParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  *  \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef OUTPUTPARAMS_H
13 #define OUTPUTPARAMS_H
14
15
16 #include "Changes.h"
17
18 #include <memory>
19 #include <set>
20
21
22 namespace lyx {
23
24
25 class Encoding;
26 class ExportData;
27 class Font;
28 class Language;
29 class InsetArgument;
30
31
32 enum class Flavor : int {
33         DviLuaTeX,
34         LaTeX,
35         LuaTeX,
36         PdfLaTeX,
37         XeTeX,
38         DocBook5,
39         Html,
40         Text,
41         LyX
42 };
43
44 enum class CtObject : int {
45         Normal,
46         Object,
47         DisplayObject,
48         UDisplayObject,
49         OmitObject
50 };
51
52
53 class OutputParams {
54 public:
55         enum MathFlavor {
56                 NotApplicable,
57                 MathAsMathML,
58                 MathAsHTML,
59                 MathAsImages,
60                 MathAsLaTeX
61         };
62
63         enum TableCell {
64                 NO,
65                 PLAIN,
66                 ALIGNED
67         };
68
69         enum Float {
70                 NONFLOAT,
71                 MAINFLOAT,
72                 SUBFLOAT
73         };
74
75         OutputParams(Encoding const *);
76         ~OutputParams();
77
78         /** The file that we export depends occasionally on what is to
79             compile the file.
80         */
81         Flavor flavor = Flavor::LaTeX;
82         /// is it some flavor of LaTeX?
83         bool isLaTeX() const;
84         /// does this flavour support full unicode?
85         bool isFullUnicode() const;
86
87         /// Same, but for math output, which only matter is XHTML output.
88         MathFlavor math_flavor = NotApplicable;
89
90         /** Are we to write a 'nice' LaTeX file or not.
91             This essentially seems to mean whether InsetInclude, InsetGraphics
92             and InsetExternal should add the absolute path to any external
93             files or not.
94             Non-nice LaTeX also includes additional safe line breaks in order to
95             increase the precision of forward/reverse search and error reporting.
96         */
97         bool nice = false;
98
99         /** Is this a real child (i.e., compiled as a child)?
100             This depends on wherefrom we export the buffer. Even children
101             that have a master can be compiled standalone.
102         */
103         mutable bool is_child = false;
104
105         /** moving_arg == true means that the environment in which the inset
106             is typeset is a moving argument. The inset should take care about
107             fragile commands by preceding the latex with \\protect.
108         */
109         bool moving_arg = false;
110
111         /** no_cprotect == true means that the layout in which this is
112          *  does not allow \cprotect'ing.
113         */
114         bool no_cprotect = false;
115
116         /** intitle == true means that the environment in which the
117             inset is typeset is part of a title (before a \\maketitle).
118             Footnotes in such environments have moving arguments.
119         */
120         bool intitle = false;
121
122         /** need_maketitle == true means that the last layout was a title layout
123          * this is to track when \maketitle needs to be output.
124         */
125         mutable bool need_maketitle = false;
126
127         /** have_maketitle == true means that \maketitle already has been output.
128         */
129         mutable bool have_maketitle = false;
130
131         /** inbranch == true means that the environment being typeset
132             is inside an active branch inset.
133         */
134         bool inbranch = false;
135
136         /** inulemcmd > 0 means that the environment in which the
137             inset is typeset is part of a ulem or soul command (e.g., \uline,
138             \uuline, \uwave, \sout or \xout). Insets that output latex commands
139             relying on local assignments (such as \cite) should enclose such
140             commands in \mbox{} in order to avoid breakage.
141         */
142         mutable int inulemcmd = 0;
143
144         /** the font at the point where the inset is
145          *
146          * Note from lasgouttes: I have doubts on the semantics of this
147          * variable. Until this is sorted out, here are some notes on the
148          * history of local_font.
149          *
150          * A research that excludes test and assignment [*] shows that
151          * this is only used to remember language, which is a different
152          * story (and not changed by this patch). The only exception being
153          * in InsetMathHull::getCtObject and InsetMathNest::latex to
154          * support change tracking in insets, but I am not 100% sure that
155          * this is required. And historically [**] local_font used to be
156          * local_lang; it may be good to return to this simpler variable
157          * later.
158          *
159          *  [*] git grep local_font src|grep -v 'local_font [!=]*='
160          *
161          * [**] before afed118a, which improved support for InsetLine;
162          * however, since 0e7ab29f, InsetLine does not depend on the
163          * current font anymore.
164         */
165         Font const * local_font = nullptr;
166
167         /** Document language lyx name
168          */
169         std::string document_language;
170
171         /// main font encoding of the document
172         std::string main_fontenc;
173
174         /** The master language. Non-null only for child documents.
175             Note that this is not the language of the top level master, but
176             of the direct parent for nested includes.
177          */
178         mutable Language const * master_language = nullptr;
179
180         /// Active characters
181         std::string active_chars;
182
183         /** Current stream encoding. Only used for LaTeX.
184             This must be set to the document encoding (via the constructor)
185             before output starts. Afterwards it must be kept up to date for
186             each single character (\sa Paragraph::latex).
187             This does also mean that you need to set it back if you use a
188             copy (e.g. in insets): \code
189             int InsetFoo::latex(..., OutputParams const & runparams_in) const
190             {
191                 OutputParams runparams(runparams_in);
192                 runparams.inComment = true;
193                 ...
194                 InsetBla::latex(..., runparams);
195                 ...
196                 runparams_in.encoding = runparams.encoding;
197             }
198             \endcode
199          */
200         mutable Encoding const * encoding;
201
202         /** free_spacing == true means that the inset is in a free-spacing
203             paragraph.
204         */
205         bool free_spacing = false;
206
207         /** This var is set by the return value from BufferParams::writeLaTeX
208         */
209         bool use_babel = false;
210
211         /** Do we use polyglossia (instead of babel)?
212         */
213         bool use_polyglossia = false;
214
215         /** Do we use hyperref?
216         */
217         bool use_hyperref = false;
218
219         /// Do we use the CJK package?
220         bool use_CJK = false;
221
222         /** Are we generating multiple indices?
223         */
224         bool use_indices = false;
225
226         /** Are we using japanese (pLaTeX)?
227         */
228         bool use_japanese = false;
229
230         /** Customized bibtex_command
231         */
232         std::string bibtex_command;
233
234         /** Customized index_command
235         */
236         std::string index_command;
237
238         /** Hyperref driver
239         */
240         std::string hyperref_driver;
241
242         /** Line length to use with plaintext or LaTeX export.
243         */
244         size_type linelen = 0;
245
246         /** The depth of the current paragraph, set for plaintext
247          *  export and used by InsetTabular
248          */
249         int depth = 0;
250
251         /** Export data filled in by the latex(), docbook(), etc. methods.
252             This is a hack: Make it possible to add stuff to constant
253             OutputParams instances.
254         */
255         std::shared_ptr<ExportData> exportdata;
256
257         /** Store labels, index entries, etc. (in \ref post_macro)
258          *  and output them later. This is used in particular to get
259          *  labels and index entries (and potentially other fragile commands)
260          *  outside of moving arguments (bug 2154)
261          */
262         bool postpone_fragile_stuff = false;
263
264         /** Stuff to be postponed and output after the current macro
265          *  (if \ref postpone_fragile_stuff is true). Used for labels and index
266          *  entries in commands with moving arguments (\\section, \\caption etc.)
267          */
268         mutable docstring post_macro;
269
270         /** Whether we in a command that is not \\long (i.e. cannot have multiple
271          *  paragraphs)
272          */
273         mutable bool isNonLong = false;
274
275         /** Whether we are entering a display math inset.
276          *  Needed to correctly strike out deleted math in change tracking.
277          */
278         mutable bool inDisplayMath = false;
279
280         /** Whether we are leaving a display math inset.
281          *  Needed to correctly track nested ulem commands in change tracking.
282          */
283         mutable bool wasDisplayMath = false;
284
285         /** Whether we are inside a comment inset. Insets that are including
286          *  external files like InsetGraphics, InsetInclude and InsetExternal
287          *  may only write the usual output and must not attempt to do
288          *  something with the included files (e.g. copying, converting)
289          *  if this flag is true, since they may not exist.
290          */
291         bool inComment = false;
292
293         /** Whether we are inside an include inset. 
294          */
295         bool inInclude = false;
296
297         /** Whether we are inside a footnote. 
298          */
299         mutable bool inFootnote = false;
300
301         /** Whether a btUnit (for multiple biblographies) is open.
302          */
303         mutable bool openbtUnit = false;
304
305         /** Process only the children's aux files with BibTeX.
306          *  This is necessary with chapterbib.
307          */
308         bool only_childbibs = false;
309
310         /** Whether we are in a table cell.
311          *  For newline, it matters whether its content is aligned or not.
312         */
313         TableCell inTableCell = NO;
314
315         /** Whether we are inside a float or subfloat.
316          *  Needed for subfloat detection on the command line.
317          */
318         Float inFloat = NONFLOAT;
319
320         /** Whether we are inside an index inset.
321          *  ERT needs to know this, due to the active chars.
322          */
323         bool inIndexEntry = false;
324
325         /** Whether we are inside an IPA inset.
326          *  Needed for proper IPA output.
327          */
328         bool inIPA = false;
329
330         /** Whether we are inside an inset that is logically deleted.
331          *  A value > 0 indicates a deleted inset.
332         */
333         int inDeletedInset = 0;
334
335         /** The change information of the outermost logically deleted inset.
336          *  changeOfDeletedInset shall only be evaluated if inDeletedInset > 0.
337         */
338         Change changeOfDeletedInset {Change::UNCHANGED};
339
340         /** What kind of change tracking object is this?
341          * Relevant for strikeout method in output
342          */
343         mutable CtObject ctObject = CtObject::Normal;
344
345         /** allow output of only part of the top-level paragraphs
346          *  par_begin: beginning paragraph
347          */
348         mutable pit_type par_begin = 0;
349
350         /** allow output of only part of the top-level paragraphs
351          *  par_end: par_end-1 is the ending paragraph
352          *  if par_begin=par_end, output all paragraphs
353          */
354         mutable pit_type par_end = 0;
355
356         /// Id of the last paragraph before an inset
357         mutable int lastid = -1;
358
359         /// Last position in the last paragraph before an inset
360         mutable pos_type lastpos = 0;
361
362         /// is this the last paragraph in the current buffer/inset?
363         bool isLastPar = false;
364
365
366         /** whether or not to do actual file copying and image conversion
367          *  This mode will be used to preview the source code
368          */
369         bool dryrun = false;
370
371         /// whether to display output errors or not
372         bool silent = false;
373
374         /// Should we output verbatim or escape LaTeX's special chars?
375         bool pass_thru = false;
376
377         /// Should we output verbatim specific chars?
378         docstring pass_thru_chars;
379
380         /// A specific newline macro
381         std::string newlinecmd;
382
383         /// Should we output captions?
384         bool html_disable_captions = false;
385
386         /// Are we already in a paragraph?
387         bool html_in_par = false;
388
389         /// Does the present context even permit paragraphs?
390         bool html_make_pars = true;
391
392         /// Are we already in a paragraph?
393         bool docbook_in_par = false;
394
395         /// Is this element's allowMultiPar useable or not?
396         bool docbook_consider_allow_multi_par = true;
397
398         /// Does the present context even permit paragraphs?
399         bool docbook_make_pars = true;
400
401         /// Are paragraphs mandatory in this context?
402         bool docbook_force_pars = false;
403
404         /// Anchors that should not be output (LyX-side identifier, not DocBook-side).
405         std::set<docstring> docbook_anchors_to_ignore;
406
407         /// Is the current context a float (such as a table or a figure)?
408         bool docbook_in_float = false;
409
410         /// Is the current context a listing?
411         bool docbook_in_listing = false;
412
413         /// Is the current context a table?
414         bool docbook_in_table = false;
415
416         /// Should the layouts that should/must go into <info> be generated?
417         bool docbook_generate_info = true;
418
419         /// Should wrappers be ignored? Mostly useful to avoid generation of <abstract>.
420         bool docbook_ignore_wrapper = false;
421
422         /// Some parameters are output before the rest of the paragraph, they should not be generated a second time.
423         std::set<InsetArgument const *> docbook_prepended_arguments = {};
424
425         /// Some parameters are output after the rest of the paragraph, they should not be generated a second time.
426         std::set<InsetArgument const *> docbook_appended_arguments = {};
427
428         /// Are we generating this material for inclusion in a TOC-like entity?
429         bool for_toc = false;
430
431         /// Are we generating this material for inclusion in a tooltip?
432         bool for_tooltip = false;
433
434         /// Are we generating this material for use by advanced search?
435         enum Search {
436                 NoSearch = 0,
437                 SearchWithDeleted = 1,
438                 SearchWithoutDeleted = 2,
439                 SearchQuick = 4,
440                 SearchNonOutput = 8
441         };
442                 
443         inline bool find_effective(void) const { return (for_search != OutputParams::NoSearch); }
444         inline bool find_with_non_output() const { return ((for_search & OutputParams::SearchNonOutput) != 0); }
445         inline bool find_with_deleted() const { return ((for_search & OutputParams::SearchWithDeleted) != 0); }
446         inline void find_set_feature(enum Search set_) { for_search = set_; }
447         inline void find_add_feature(enum Search add_) { for_search |= add_; }
448         inline void find_clean_features(void) { for_search = OutputParams::NoSearch; }
449
450         /// Are we generating this material for instant preview?
451         bool for_preview = false;
452
453         /// Include all children notwithstanding the use of \includeonly
454         bool includeall = false;
455
456         /// Explicit output folder, if any is desired
457         std::string export_folder;
458
459         /// A postponed \\noindent (after VSpace)
460         mutable bool need_noindent = false;
461 private:
462         int for_search = NoSearch;
463 };
464
465
466 } // namespace lyx
467
468 #endif // NOT OUTPUTPARAMS_H