]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/preamble.cpp
fix #4758
[lyx.git] / src / tex2lyx / preamble.cpp
1 /**
2  * \file preamble.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 // {[(
13
14 #include <config.h>
15
16 #include "tex2lyx.h"
17
18 #include "LayoutFile.h"
19 #include "Layout.h"
20 #include "Lexer.h"
21 #include "TextClass.h"
22
23 #include "support/convert.h"
24 #include "support/FileName.h"
25 #include "support/filetools.h"
26 #include "support/lstrings.h"
27
28 #include <algorithm>
29 #include <iostream>
30 #include <sstream>
31 #include <string>
32 #include <vector>
33 #include <map>
34
35 using namespace std;
36 using namespace lyx::support;
37
38 namespace lyx {
39
40 // special columntypes
41 extern map<char, int> special_columns;
42
43 map<string, vector<string> > used_packages;
44
45 // needed to handle encodings with babel
46 bool one_language = true;
47
48 // to avoid that the babel options overwrite the documentclass options
49 bool documentclass_language;
50
51 namespace {
52
53 const char * const known_languages[] = { "afrikaans", "american", "arabic",
54 "austrian", "bahasa", "basque", "belarusian", "brazil", "breton", "british",
55 "bulgarian", "canadian", "canadien", "catalan", "croatian", "czech", "danish",
56 "dutch", "english", "esperanto", "estonian", "finnish", "francais", "french",
57 "frenchb", "frenchle", "frenchpro", "galician", "german", "germanb", "greek",
58 "hebrew", "icelandic", "irish", "italian", "lsorbian", "magyar", "naustrian",
59 "ngerman", "ngermanb", "norsk", "nynorsk", "polish", "portuges", "romanian",
60 "russian", "russianb", "scottish", "serbian", "slovak", "slovene", "spanish",
61 "swedish", "thai", "turkish", "ukraineb", "ukrainian", "usorbian", "welsh", 0};
62
63 //note this when updating to lyxformat 305:
64 //bahasai, indonesian, and indon = equal to bahasa
65 //malay, and meyalu = equal to bahasam
66
67 const char * const known_french_languages[] = {"french", "frenchb", "francais",
68                                                 "frenchle", "frenchpro", 0};
69 const char * const known_german_languages[] = {"german", "germanb", 0};
70 const char * const known_ngerman_languages[] = {"ngerman", "ngermanb", 0};
71 const char * const known_russian_languages[] = {"russian", "russianb", 0};
72 const char * const known_ukrainian_languages[] = {"ukrainian", "ukraineb", 0};
73
74 char const * const known_fontsizes[] = { "10pt", "11pt", "12pt", 0 };
75
76 const char * const known_roman_fonts[] = { "ae", "bookman", "charter",
77 "cmr", "fourier", "lmodern", "mathpazo", "mathptmx", "newcent", 0};
78
79 const char * const known_sans_fonts[] = { "avant", "berasans", "cmbr", "cmss",
80 "helvet", "lmss", 0};
81
82 const char * const known_typewriter_fonts[] = { "beramono", "cmtl", "cmtt",
83 "courier", "lmtt", "luximono", "fourier", "lmodern", "mathpazo", "mathptmx",
84 "newcent", 0};
85
86 // some ugly stuff
87 ostringstream h_preamble;
88 string h_textclass               = "article";
89 string h_options                 = string();
90 string h_language                = "english";
91 string h_inputencoding           = "auto";
92 string h_font_roman              = "default";
93 string h_font_sans               = "default";
94 string h_font_typewriter         = "default";
95 string h_font_default_family     = "default";
96 string h_font_sc                 = "false";
97 string h_font_osf                = "false";
98 string h_font_sf_scale           = "100";
99 string h_font_tt_scale           = "100";
100 string h_graphics                = "default";
101 string h_paperfontsize           = "default";
102 string h_spacing                 = "single";
103 string h_papersize               = "default";
104 string h_use_geometry            = "false";
105 string h_use_amsmath             = "0";
106 string h_cite_engine             = "basic";
107 string h_use_bibtopic            = "false";
108 string h_paperorientation        = "portrait";
109 string h_secnumdepth             = "3";
110 string h_tocdepth                = "3";
111 string h_paragraph_separation    = "indent";
112 string h_defskip                 = "medskip";
113 string h_quotes_language         = "english";
114 string h_papercolumns            = "1";
115 string h_papersides              = string();
116 string h_paperpagestyle          = "default";
117 string h_tracking_changes        = "false";
118 string h_output_changes          = "false";
119
120
121 void handle_opt(vector<string> & opts, char const * const * what, string & target)
122 {
123         if (opts.empty())
124                 return;
125
126         // the last language option is the document language (for babel and LyX)
127         // the last size option is the document font size
128         vector<string>::iterator it;
129         vector<string>::iterator position = opts.begin();
130         for (; *what; ++what) {
131                 it = find(opts.begin(), opts.end(), *what);
132                 if (it != opts.end()) {
133                         documentclass_language = true;
134                         if (it >= position) {
135                                 target = *what;
136                                 position = it;
137                         }
138                 }
139         }
140 }
141
142
143 void delete_opt(vector<string> & opts, char const * const * what)
144 {
145         if (opts.empty())
146                 return;
147
148         // remove found options from the list
149         // do this after handle_opt to avoid potential memory leaks and to be able
150         // to find in every case the last language option
151         vector<string>::iterator it;
152         for (; *what; ++what) {
153                 it = find(opts.begin(), opts.end(), *what);
154                 if (it != opts.end())
155                         opts.erase(it);
156         }
157 }
158
159
160 /*!
161  * Split a package options string (keyval format) into a vector.
162  * Example input:
163  *   authorformat=smallcaps,
164  *   commabeforerest,
165  *   titleformat=colonsep,
166  *   bibformat={tabular,ibidem,numbered}
167  */
168 vector<string> split_options(string const & input)
169 {
170         vector<string> options;
171         string option;
172         Parser p(input);
173         while (p.good()) {
174                 Token const & t = p.get_token();
175                 if (t.asInput() == ",") {
176                         options.push_back(trim(option));
177                         option.erase();
178                 } else if (t.asInput() == "=") {
179                         option += '=';
180                         p.skip_spaces(true);
181                         if (p.next_token().asInput() == "{")
182                                 option += '{' + p.getArg('{', '}') + '}';
183                 } else if (t.cat() != catSpace)
184                         option += t.asInput();
185         }
186
187         if (!option.empty())
188                 options.push_back(trim(option));
189
190         return options;
191 }
192
193
194 /*!
195  * Add package \p name with options \p options to used_packages.
196  * Remove options from \p options that we don't want to output.
197  */
198 void add_package(string const & name, vector<string> & options)
199 {
200         // every package inherits the global options
201         if (used_packages.find(name) == used_packages.end())
202                 used_packages[name] = split_options(h_options);
203
204         vector<string> & v = used_packages[name];
205         v.insert(v.end(), options.begin(), options.end());
206         if (name == "jurabib") {
207                 // Don't output the order argument (see the cite command
208                 // handling code in text.cpp).
209                 vector<string>::iterator end =
210                         remove(options.begin(), options.end(), "natbiborder");
211                 end = remove(options.begin(), end, "jurabiborder");
212                 options.erase(end, options.end());
213         }
214 }
215
216
217 // Given is a string like "scaled=0.9", return 0.9 * 100
218 string const scale_as_percentage(string const & scale)
219 {
220         string::size_type pos = scale.find('=');
221         if (pos != string::npos) {
222                 string value = scale.substr(pos + 1);
223                 if (isStrDbl(value))
224                         return convert<string>(100 * convert<double>(value));
225         }
226         // If the input string didn't match our expectations.
227         // return the default value "100"
228         return "100";
229 }
230
231
232 void handle_package(string const & name, string const & opts)
233 {
234         vector<string> options = split_options(opts);
235         add_package(name, options);
236         string scale;
237
238         // roman fonts
239         if (is_known(name, known_roman_fonts))
240                 h_font_roman = name;
241
242         if (name == "fourier") {
243                 h_font_roman = "utopia";
244                 // when font uses real small capitals
245                 if (opts == "expert")
246                         h_font_sc = "true";
247         }
248         if (name == "mathpazo")
249                 h_font_roman = "palatino";
250
251         if (name == "mathptmx")
252                 h_font_roman = "times";
253
254         // sansserif fonts
255         if (is_known(name, known_sans_fonts)) {
256                 h_font_sans = name;
257                 if (!opts.empty()) {
258                         scale = opts;
259                         h_font_sf_scale = scale_as_percentage(scale);
260                 }
261         }
262         // typewriter fonts
263         if (is_known(name, known_typewriter_fonts)) {
264                 h_font_typewriter = name;
265                 if (!opts.empty()) {
266                         scale = opts;
267                         h_font_tt_scale = scale_as_percentage(scale);
268                 }
269         }
270         // font uses old-style figure
271         if (name == "eco")
272                 h_font_osf = "true";
273
274         else if (name == "amsmath" || name == "amssymb")
275                 h_use_amsmath = "1";
276
277         else if (name == "babel" && !opts.empty()) {
278                 // check if more than one option was used - used later for inputenc
279                 // in case inputenc is parsed before babel, set the encoding to auto
280                 if (options.begin() != options.end() - 1) {
281                         one_language = false;
282                         h_inputencoding = "auto";
283                 }
284                 // only set the document language when there was not already one set
285                 // via the documentclass options
286                 // babel takes the the last language given in the documentclass options
287                 // as document language. If there is no such language option, the last
288                 // option of its \usepackage call is used.
289                 if (documentclass_language == false) {
290                         handle_opt(options, known_languages, h_language);
291                         delete_opt(options, known_languages);
292                         if (is_known(h_language, known_french_languages))
293                                 h_language = "french";
294                         else if (is_known(h_language, known_german_languages))
295                                 h_language = "german";
296                         else if (is_known(h_language, known_ngerman_languages))
297                                 h_language = "ngerman";
298                         else if (is_known(h_language, known_russian_languages))
299                                 h_language = "russian";
300                         else if (is_known(h_language, known_ukrainian_languages))
301                                 h_language = "ukrainian";
302                         h_quotes_language = h_language;
303                 }
304         }
305
306         else if (name == "fontenc")
307                 ; // ignore this
308
309         else if (name == "inputenc") {
310                 // only set when there is not more than one inputenc option
311                 // therefore check for the "," character
312                 // also only set when there is not more then one babel language option
313                 if (opts.find(",") == string::npos && one_language == true)
314                         if (opts == "ascii")
315                                 //change ascii to auto to be in the unicode range, see
316                                 //http://bugzilla.lyx.org/show_bug.cgi?id=4719
317                                 h_inputencoding = "auto";
318                         else
319                                 h_inputencoding = opts;
320                 options.clear();
321
322         } else if (name == "makeidx")
323                 ; // ignore this
324
325         else if (name == "verbatim")
326                 ; // ignore this
327
328         else if (name == "color")
329                 // with the following command this package is only loaded when needed for
330                 // undefined colors, since we only support the predefined colors
331                 h_preamble << "\\@ifundefined{definecolor}\n {\\usepackage{color}}{}\n";
332
333         else if (name == "graphicx")
334                 ; // ignore this
335         else if (name == "setspace")
336                 ; // ignore this
337         else if (is_known(name, known_languages)) {
338                 if (is_known(name, known_french_languages))
339                         h_language = "french";
340                 else if (is_known(name, known_german_languages))
341                         h_language = "german";
342                 else if (is_known(name, known_ngerman_languages))
343                         h_language = "ngerman";
344                 else if (is_known(name, known_russian_languages))
345                         h_language = "russian";
346                 else if (is_known(name, known_ukrainian_languages))
347                         h_language = "ukrainian";
348                 else
349                         h_language = name;
350                 h_quotes_language = h_language;
351
352         } else if (name == "natbib") {
353                 h_cite_engine = "natbib_authoryear";
354                 vector<string>::iterator it =
355                         find(options.begin(), options.end(), "authoryear");
356                 if (it != options.end())
357                         options.erase(it);
358                 else {
359                         it = find(options.begin(), options.end(), "numbers");
360                         if (it != options.end()) {
361                                 h_cite_engine = "natbib_numerical";
362                                 options.erase(it);
363                         }
364                 }
365         } else if (name == "jurabib") {
366                 h_cite_engine = "jurabib";
367
368         } else if (options.empty())
369                 h_preamble << "\\usepackage{" << name << "}\n";
370         else {
371                 h_preamble << "\\usepackage[" << opts << "]{" << name << "}\n";
372                 options.clear();
373         }
374
375         // We need to do something with the options...
376         if (!options.empty())
377                 cerr << "Ignoring options '" << join(options, ",")
378                      << "' of package " << name << '.' << endl;
379 }
380
381
382
383 void end_preamble(ostream & os, TextClass const & /*textclass*/)
384 {
385         os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
386            << "\\lyxformat 247\n"
387            << "\\begin_document\n"
388            << "\\begin_header\n"
389            << "\\textclass " << h_textclass << "\n";
390         if (!h_preamble.str().empty())
391                 os << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
392         if (!h_options.empty())
393                 os << "\\options " << h_options << "\n";
394         os << "\\language " << h_language << "\n"
395            << "\\inputencoding " << h_inputencoding << "\n"
396            << "\\font_roman " << h_font_roman << "\n"
397            << "\\font_sans " << h_font_sans << "\n"
398            << "\\font_typewriter " << h_font_typewriter << "\n"
399            << "\\font_default_family " << h_font_default_family << "\n"
400            << "\\font_sc " << h_font_sc << "\n"
401            << "\\font_osf " << h_font_osf << "\n"
402            << "\\font_sf_scale " << h_font_sf_scale << "\n"
403            << "\\font_tt_scale " << h_font_tt_scale << "\n"
404            << "\\graphics " << h_graphics << "\n"
405            << "\\paperfontsize " << h_paperfontsize << "\n"
406            << "\\spacing " << h_spacing << "\n"
407            << "\\papersize " << h_papersize << "\n"
408            << "\\use_geometry " << h_use_geometry << "\n"
409            << "\\use_amsmath " << h_use_amsmath << "\n"
410            << "\\cite_engine " << h_cite_engine << "\n"
411            << "\\use_bibtopic " << h_use_bibtopic << "\n"
412            << "\\paperorientation " << h_paperorientation << "\n"
413            << "\\secnumdepth " << h_secnumdepth << "\n"
414            << "\\tocdepth " << h_tocdepth << "\n"
415            << "\\paragraph_separation " << h_paragraph_separation << "\n"
416            << "\\defskip " << h_defskip << "\n"
417            << "\\quotes_language " << h_quotes_language << "\n"
418            << "\\papercolumns " << h_papercolumns << "\n"
419            << "\\papersides " << h_papersides << "\n"
420            << "\\paperpagestyle " << h_paperpagestyle << "\n"
421            << "\\tracking_changes " << h_tracking_changes << "\n"
422            << "\\output_changes " << h_output_changes << "\n"
423            << "\\end_header\n\n"
424            << "\\begin_body\n";
425         // clear preamble for subdocuments
426         h_preamble.str("");
427 }
428
429 } // anonymous namespace
430
431 void parse_preamble(Parser & p, ostream & os, 
432         string const & forceclass, TeX2LyXDocClass & tc)
433 {
434         // initialize fixed types
435         special_columns['D'] = 3;
436         bool is_full_document = false;
437
438         // determine whether this is a full document or a fragment for inclusion
439         while (p.good()) {
440                 Token const & t = p.get_token();
441
442                 if (t.cat() == catEscape && t.cs() == "documentclass") {
443                         is_full_document = true;
444                         break;
445                 }
446         }
447         p.reset();
448
449         while (is_full_document && p.good()) {
450                 Token const & t = p.get_token();
451
452 #ifdef FILEDEBUG
453                 cerr << "t: " << t << "\n";
454 #endif
455
456                 //
457                 // cat codes
458                 //
459                 if (t.cat() == catLetter ||
460                           t.cat() == catSuper ||
461                           t.cat() == catSub ||
462                           t.cat() == catOther ||
463                           t.cat() == catMath ||
464                           t.cat() == catActive ||
465                           t.cat() == catBegin ||
466                           t.cat() == catEnd ||
467                           t.cat() == catAlign ||
468                           t.cat() == catParameter)
469                 h_preamble << t.character();
470
471                 else if (t.cat() == catSpace || t.cat() == catNewline)
472                         h_preamble << t.asInput();
473
474                 else if (t.cat() == catComment)
475                         h_preamble << t.asInput();
476
477                 else if (t.cs() == "pagestyle")
478                         h_paperpagestyle = p.verbatim_item();
479
480                 else if (t.cs() == "makeatletter") {
481                         p.setCatCode('@', catLetter);
482                 }
483
484                 else if (t.cs() == "makeatother") {
485                         p.setCatCode('@', catOther);
486                 }
487
488                 else if (t.cs() == "newcommand" 
489                          || t.cs() == "renewcommand"
490                          || t.cs() == "providecommand"
491                          || t.cs() == "newlyxcommand") {
492                         bool star = false;
493                         if (p.next_token().character() == '*') {
494                                 p.get_token();
495                                 star = true;
496                         }
497                         string const name = p.verbatim_item();
498                         string const opt1 = p.getOpt();
499                         string const opt2 = p.getFullOpt();
500                         string const body = p.verbatim_item();
501                         // font settings
502                         if (name == "\\rmdefault")
503                                 if (is_known(body, known_roman_fonts))
504                                         h_font_roman = body;
505
506                         if (name == "\\sfdefault")
507                                 if (is_known(body, known_sans_fonts))
508                                         h_font_sans = body;
509
510                         if (name == "\\ttdefault")
511                                 if (is_known(body, known_typewriter_fonts))
512                                         h_font_typewriter = body;
513
514                         if (name == "\\familydefault") {
515                                 string family = body;
516                                 // remove leading "\"
517                                 h_font_default_family = family.erase(0,1);
518                         }
519                         // only non-lyxspecific stuff
520                         if (   name != "\\noun"
521                             && name != "\\tabularnewline"
522                             && name != "\\LyX"
523                             && name != "\\lyxline"
524                             && name != "\\lyxaddress"
525                             && name != "\\lyxrightaddress"
526                             && name != "\\lyxdot"
527                             && name != "\\boldsymbol"
528                             && name != "\\lyxarrow"
529                             && name != "\\rmdefault"
530                             && name != "\\sfdefault"
531                             && name != "\\ttdefault"
532                             && name != "\\familydefault") {
533                                 ostringstream ss;
534                                 ss << '\\' << t.cs();
535                                 if (star)
536                                         ss << '*';
537                                 ss << '{' << name << '}' << opt1 << opt2
538                                    << '{' << body << "}";
539                                 h_preamble << ss.str();
540
541                                 // Add the command to the known commands
542                                 add_known_command(name, opt1, !opt2.empty());
543 /*
544                                 ostream & out = in_preamble ? h_preamble : os;
545                                 out << "\\" << t.cs() << "{" << name << "}"
546                                     << opts << "{" << body << "}";
547 */
548                         }
549                 }
550
551                 else if (t.cs() == "documentclass") {
552                         vector<string> opts = split_options(p.getArg('[', ']'));
553                         handle_opt(opts, known_fontsizes, h_paperfontsize);
554                         delete_opt(opts, known_fontsizes);
555                         // delete "pt" at the end
556                         string::size_type i = h_paperfontsize.find("pt");
557                         if (i != string::npos)
558                                 h_paperfontsize.erase(i);
559                         // to avoid that the babel options overwrite the documentclass options
560                         documentclass_language = false;
561                         handle_opt(opts, known_languages, h_language);
562                         delete_opt(opts, known_languages);
563                         if (is_known(h_language, known_french_languages))
564                                 h_language = "french";
565                         else if (is_known(h_language, known_german_languages))
566                                 h_language = "german";
567                         else if (is_known(h_language, known_ngerman_languages))
568                                 h_language = "ngerman";
569                         else if (is_known(h_language, known_russian_languages))
570                                 h_language = "russian";
571                         else if (is_known(h_language, known_ukrainian_languages))
572                                 h_language = "ukrainian";
573                         h_quotes_language = h_language;
574                         h_options = join(opts, ",");
575                         h_textclass = p.getArg('{', '}');
576                 }
577
578                 else if (t.cs() == "usepackage") {
579                         string const options = p.getArg('[', ']');
580                         string const name = p.getArg('{', '}');
581                         if (options.empty() && name.find(',')) {
582                                 vector<string> vecnames;
583                                 split(name, vecnames, ',');
584                                 vector<string>::const_iterator it  = vecnames.begin();
585                                 vector<string>::const_iterator end = vecnames.end();
586                                 for (; it != end; ++it)
587                                         handle_package(trim(*it), string());
588                         } else {
589                                 handle_package(name, options);
590                         }
591                 }
592
593                 else if (t.cs() == "newenvironment") {
594                         string const name = p.getArg('{', '}');
595                         ostringstream ss;
596                         ss << "\\newenvironment{" << name << "}";
597                         ss << p.getOpt();
598                         ss << p.getOpt();
599                         ss << '{' << p.verbatim_item() << '}';
600                         ss << '{' << p.verbatim_item() << '}';
601                         if (name != "lyxcode" && name != "lyxlist" &&
602                             name != "lyxrightadress" &&
603                             name != "lyxaddress" && name != "lyxgreyedout")
604                                 h_preamble << ss.str();
605                 }
606
607                 else if (t.cs() == "def") {
608                         string name = p.get_token().cs();
609                         while (p.next_token().cat() != catBegin)
610                                 name += p.get_token().asString();
611                         h_preamble << "\\def\\" << name << '{'
612                                    << p.verbatim_item() << "}";
613                 }
614
615                 else if (t.cs() == "newcolumntype") {
616                         string const name = p.getArg('{', '}');
617                         trim(name);
618                         int nargs = 0;
619                         string opts = p.getOpt();
620                         if (!opts.empty()) {
621                                 istringstream is(string(opts, 1));
622                                 is >> nargs;
623                         }
624                         special_columns[name[0]] = nargs;
625                         h_preamble << "\\newcolumntype{" << name << "}";
626                         if (nargs)
627                                 h_preamble << "[" << nargs << "]";
628                         h_preamble << "{" << p.verbatim_item() << "}";
629                 }
630
631                 else if (t.cs() == "setcounter") {
632                         string const name = p.getArg('{', '}');
633                         string const content = p.getArg('{', '}');
634                         if (name == "secnumdepth")
635                                 h_secnumdepth = content;
636                         else if (name == "tocdepth")
637                                 h_tocdepth = content;
638                         else
639                                 h_preamble << "\\setcounter{" << name << "}{" << content << "}";
640                 }
641
642                 else if (t.cs() == "setlength") {
643                         string const name = p.verbatim_item();
644                         string const content = p.verbatim_item();
645                         // the paragraphs are only not indented when \parindent is set to zero
646                         if (name == "\\parindent" && content != "") {
647                                 if (content[0] == '0')
648                                         h_paragraph_separation = "skip";
649                         } else if (name == "\\parskip") {
650                                 if (content == "\\smallskipamount")
651                                         h_defskip = "smallskip";
652                                 else if (content == "\\medskipamount")
653                                         h_defskip = "medskip";
654                                 else if (content == "\\bigskipamount")
655                                         h_defskip = "bigskip";
656                                 else
657                                         h_defskip = content;
658                         } else
659                                 h_preamble << "\\setlength{" << name << "}{" << content << "}";
660                 }
661
662                 else if (t.cs() =="onehalfspacing")
663                         h_spacing = "onehalf";
664
665                 else if (t.cs() =="doublespacing")
666                         h_spacing = "double";
667
668                 else if (t.cs() =="setstretch")
669                         h_spacing = "other " + p.verbatim_item();
670
671                 else if (t.cs() == "begin") {
672                         string const name = p.getArg('{', '}');
673                         if (name == "document")
674                                 break;
675                         h_preamble << "\\begin{" << name << "}";
676                 }
677
678                 else if (t.cs() == "jurabibsetup") {
679                         vector<string> jurabibsetup =
680                                 split_options(p.getArg('{', '}'));
681                         // add jurabibsetup to the jurabib package options
682                         add_package("jurabib", jurabibsetup);
683                         if (!jurabibsetup.empty()) {
684                                 h_preamble << "\\jurabibsetup{"
685                                            << join(jurabibsetup, ",") << '}';
686                         }
687                 }
688
689                 else if (!t.cs().empty())
690                         h_preamble << '\\' << t.cs();
691         }
692         p.skip_spaces();
693
694         // Force textclass if the user wanted it
695         if (!forceclass.empty())
696                 h_textclass = forceclass;
697         if (noweb_mode && !prefixIs(h_textclass, "literate-"))
698                 h_textclass.insert(0, "literate-");
699         FileName layoutfilename = libFileSearch("layouts", h_textclass, "layout");
700         if (layoutfilename.empty()) {
701                 cerr << "Error: Could not find layout file for textclass \"" << h_textclass << "\"." << endl;
702                 exit(1);
703         }
704         tc.read(layoutfilename);
705         if (h_papersides.empty()) {
706                 ostringstream ss;
707                 ss << tc.sides();
708                 h_papersides = ss.str();
709         }
710         end_preamble(os, tc);
711 }
712
713 // }])
714
715
716 } // namespace lyx