1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
24 #include <sys/types.h>
34 #pragma implementation "buffer.h"
38 #include "bufferlist.h"
40 #include "lyx_gui_misc.h"
41 #include "LyXAction.h"
44 #include "tex-strings.h"
46 #include "bufferview_funcs.h"
47 #include "minibuffer.h"
50 #include "mathed/formulamacro.h"
51 #include "insets/lyxinset.h"
52 #include "insets/inseterror.h"
53 #include "insets/insetlabel.h"
54 #include "insets/insetref.h"
55 #include "insets/inseturl.h"
56 #include "insets/insetinfo.h"
57 #include "insets/insetquotes.h"
58 #include "insets/insetlatexaccent.h"
59 #include "insets/insetbib.h"
60 #include "insets/insetcite.h"
61 #include "insets/insetexternal.h"
62 #include "insets/insetindex.h"
63 #include "insets/insetinclude.h"
64 #include "insets/insettoc.h"
65 #include "insets/insetparent.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/figinset.h"
68 #include "insets/insettext.h"
69 #include "insets/insetert.h"
70 #include "insets/insetgraphics.h"
71 #include "insets/insetfoot.h"
72 #include "insets/insetmarginal.h"
73 #include "insets/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insetlist.h"
76 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetcaption.h"
79 #include "support/filetools.h"
80 #include "support/path.h"
85 #include "LaTeXFeatures.h"
86 #include "support/syscall.h"
87 #include "support/lyxlib.h"
88 #include "support/FileInfo.h"
89 #include "support/lyxmanip.h"
93 #include "lyx_gui_misc.h" // WarnReadonly()
94 #include "frontends/Dialogs.h"
98 #include "converter.h"
100 using std::stringstream;
109 using std::make_pair;
115 // all these externs should eventually be removed.
116 extern BufferList bufferlist;
118 extern LyXAction lyxaction;
121 static const int LYX_FORMAT = 218;
123 extern int tex_code_break_column;
126 Buffer::Buffer(string const & file, bool ronly)
128 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
130 filepath = OnlyPath(file);
139 if (read_only || (lyxrc.use_tempdir)) {
140 tmppath = CreateBufferTmpDir();
141 } else tmppath.erase();
147 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
148 // here the buffer should take care that it is
149 // saved properly, before it goes into the void.
151 // make sure that views using this buffer
156 if (!tmppath.empty()) {
157 DestroyBufferTmpDir(tmppath);
160 LyXParagraph * par = paragraph;
161 LyXParagraph * tmppar;
170 tmppar = par->next();
179 string const Buffer::getLatexName(bool no_path) const
182 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
185 return ChangeExtension(MakeLatexName(filename),
190 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
192 string const filename = getLatexName(false);
194 if (filename.empty())
195 return make_pair(Buffer::latexlog, string());
197 string path = OnlyPath(filename);
199 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1))
202 string const fname = AddName(path,
203 OnlyFilename(ChangeExtension(filename,
206 AddName(path, OnlyFilename(
207 ChangeExtension(filename,
208 formats.Extension("literate") + ".out")));
210 // If no Latex log or Build log is newer, show Build log
212 FileInfo const f_fi(fname);
213 FileInfo const b_fi(bname);
216 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
217 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
218 return make_pair(Buffer::buildlog, bname);
220 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
221 return make_pair(Buffer::latexlog, fname);
225 void Buffer::setReadonly(bool flag)
227 if (read_only != flag) {
230 users->owner()->getDialogs()->updateBufferDependent(false);
233 WarnReadonly(filename);
238 bool Buffer::saveParamsAsDefaults() // const
240 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
242 Buffer defaults = Buffer(fname);
244 // Use the current buffer's parameters as default
245 defaults.params = params;
247 // add an empty paragraph. Is this enough?
248 defaults.paragraph = new LyXParagraph;
250 return defaults.writeFile(defaults.filename, false);
254 /// Update window titles of all users
255 // Should work on a list
256 void Buffer::updateTitles() const
258 if (users) users->owner()->updateWindowTitle();
262 /// Reset autosave timer of all users
263 // Should work on a list
264 void Buffer::resetAutosaveTimers() const
266 if (users) users->owner()->resetAutosaveTimer();
270 void Buffer::setFileName(string const & newfile)
272 filename = MakeAbsPath(newfile);
273 filepath = OnlyPath(filename);
274 setReadonly(IsFileWriteable(filename) == 0);
279 // candidate for move to BufferView
280 // (at least some parts in the beginning of the func)
283 // changed to be public and have one parameter
284 // if par = 0 normal behavior
285 // else insert behavior
286 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
287 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
290 char depth = 0; // signed or unsigned?
292 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
293 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
295 bool the_end_read = false;
297 LyXParagraph * return_par = 0;
298 LyXFont font(LyXFont::ALL_INHERIT, params.language);
299 if (file_format < 216 && params.language->lang() == "hebrew")
300 font.setLanguage(default_language);
301 // If we are inserting, we cheat and get a token in advance
302 bool has_token = false;
306 par = new LyXParagraph;
308 users->text->BreakParagraph(users);
309 return_par = users->text->FirstParagraph();
312 // We don't want to adopt the parameters from the
313 // document we insert, so we skip until the text begins:
316 pretoken = lex.GetString();
317 if (pretoken == "\\layout") {
329 pretoken = lex.GetString();
332 if (pretoken.empty()) continue;
335 parseSingleLyXformat2Token(lex, par, return_par,
336 pretoken, pos, depth,
348 paragraph = return_par;
354 // We'll remove this later. (Lgb)
355 static string last_inset_read;
359 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
360 LyXParagraph *& return_par,
361 string const & token, int & pos,
362 char & depth, LyXFont & font
364 , LyXParagraph::footnote_flag & footnoteflag,
365 LyXParagraph::footnote_kind & footnotekind
370 // This is super temporary but is needed to get the compability
371 // mode for minipages work correctly together with new tabulars.
372 static int call_depth = 0;
375 bool the_end_read = false;
377 if (token[0] != '\\') {
378 for (string::const_iterator cit = token.begin();
379 cit != token.end(); ++cit) {
380 par->InsertChar(pos, (*cit), font);
383 } else if (token == "\\i") {
384 Inset * inset = new InsetLatexAccent;
385 inset->Read(this, lex);
386 par->InsertInset(pos, inset, font);
388 } else if (token == "\\layout") {
394 par = new LyXParagraph(par);
398 string const layoutname = lex.GetString();
399 pair<bool, LyXTextClass::LayoutList::size_type> pp
400 = textclasslist.NumberOfLayout(params.textclass,
403 par->layout = pp.second;
404 } else { // layout not found
405 // use default layout "Standard" (0)
408 // Test whether the layout is obsolete.
409 LyXLayout const & layout =
410 textclasslist.Style(params.textclass,
412 if (!layout.obsoleted_by().empty())
414 textclasslist.NumberOfLayout(params.textclass,
415 layout.obsoleted_by()).second;
416 par->footnoteflag = footnoteflag;
417 par->footnotekind = footnotekind;
418 par->params.depth(depth);
419 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
420 if (file_format < 216 && params.language->lang() == "hebrew")
421 font.setLanguage(default_language);
424 string const layoutname = lex.GetString();
425 pair<bool, LyXTextClass::LayoutList::size_type> pp
426 = textclasslist.NumberOfLayout(params.textclass,
430 // The is the compability reading of layout caption.
431 // It can be removed in LyX version 1.3.0. (Lgb)
432 if (compare_no_case(layoutname, "caption") == 0) {
433 // We expect that the par we are now working on is
434 // really inside a InsetText inside a InsetFloat.
435 // We also know that captions can only be
436 // one paragraph. (Lgb)
438 // We should now read until the next "\layout"
440 // This is probably not good enough, what if the
441 // caption is the last par in the document (Lgb)
442 istream & ist = lex.getStream();
448 if (prefixIs(line, "\\layout")) {
452 if (prefixIs(line, "\\begin_inset"))
454 if (prefixIs(line, "\\end_inset")) {
465 // Now we should have the whole layout in ss
466 // we should now be able to give this to the
468 ss << "\\end_inset\n";
470 // This seems like a bug in stringstream.
471 // We really should be able to use ss
473 istringstream is(ss.str());
475 tmplex.setStream(is);
476 Inset * inset = new InsetCaption;
477 inset->Read(this, tmplex);
478 par->InsertInset(pos, inset, font);
482 // BEGIN pextra_minipage compability
483 // This should be removed in 1.3.x (Lgb)
485 // This compability code is not perfect. In a couple
486 // of rand cases it fails. When the minipage par is
487 // the first par in the document, and when there are
488 // none or only one regular paragraphs after the
489 // minipage. Currently I am not investing any effort
490 // in fixing those cases.
491 static LyXParagraph * minipar = 0;
492 //lyxerr << "Call depth: " << call_depth << endl;
493 if (call_depth == 1) {
496 && par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
497 lyxerr << "minipages in a row" << endl;
498 if (par->params.pextraStartMinipage()) {
499 lyxerr << "start new minipage" << endl;
500 // minipages in a row
501 par->previous()->next(0);
502 par->previous(minipar->previous());
503 minipar->previous()->next(par);
504 minipar->previous(0);
506 // Before we insert the list of
507 // minipages into the inset we have
508 // to clean up a bit.
509 // This is not quite correct yet since
510 // we do want to use some of these
511 // parameters to set options in the
513 InsetMinipage::Position imp = static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment());
514 LyXParagraph * tmp = minipar;
516 tmp->params.pextraType(0);
517 tmp->params.pextraWidth(string());
518 tmp->params.pextraWidthp(string());
519 tmp->params.pextraAlignment(0);
520 tmp->params.pextraHfill(false);
521 tmp->params.pextraStartMinipage(false);
525 InsetMinipage * mini = new InsetMinipage;
527 mini->inset->par = minipar;
528 // Insert the minipage last in the
529 // previous paragraph.
530 par->previous()->InsertInset(par->previous()->size(), mini);
533 lyxerr << "new minipage par" << endl;
534 //nothing to do just continue reading
537 } else if (minipar) {
538 lyxerr << "last minipage par read" << endl;
539 // The last paragraph read was not part of a
540 // minipage but the par linked list is...
541 // So we need to remove the last par from the
542 // rest, insert the rest of the paragraphs into
543 // a InsetMinipage, insert this minipage into
544 // prevpar, append the current par to prevpar
547 LyXParagraph * lp = minipar;
553 lyxerr << "Minipar count: " << pcount << endl;
554 lyxerr << "Par: " << (void*)par << endl;
555 lyxerr << "Par->prev: " << (void*)par->previous() << endl;
558 par->previous()->next(0);
559 par->previous(minipar->previous());
560 minipar->previous()->next(par);
561 minipar->previous(0);
563 // Before we insert the list of
564 // minipages into the inset we have
565 // to clean up a bit.
566 // This is not quite correct yet since we
567 // do want to use some of these parameters
568 // to set options in the minipage inset.
569 InsetMinipage::Position imp = static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment());
570 LyXParagraph * tmp = minipar;
572 tmp->params.pextraType(0);
573 tmp->params.pextraWidth(string());
574 tmp->params.pextraWidthp(string());
575 tmp->params.pextraAlignment(0);
576 tmp->params.pextraHfill(false);
577 tmp->params.pextraStartMinipage(false);
581 InsetMinipage * mini = new InsetMinipage;
583 mini->inset->par = minipar;
584 par->previous()->InsertInset(par->previous()->size(), mini);
586 } else if (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
588 // par is the first paragraph in a minipage
589 lyxerr << "begin minipage" << endl;
595 // End of pextra_minipage compability
601 par = new LyXParagraph(par);
605 par->layout = pp.second;
608 // use default layout "Standard" (0)
611 // Test whether the layout is obsolete.
612 LyXLayout const & layout =
613 textclasslist.Style(params.textclass,
615 if (!layout.obsoleted_by().empty())
616 par->layout = textclasslist
617 .NumberOfLayout(params.textclass,
618 layout.obsoleted_by())
620 par->params.depth(depth);
621 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
622 if (file_format < 216
623 && params.language->lang() == "hebrew")
624 font.setLanguage(default_language);
630 } else if (token == "\\end_float") {
635 par = new LyXParagraph(par);
637 footnotekind = LyXParagraph::FOOTNOTE;
638 footnoteflag = LyXParagraph::NO_FOOTNOTE;
641 par->layout = LYX_DUMMY_LAYOUT;
642 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
643 if (file_format < 216 && params.language->lang() == "hebrew")
644 font.setLanguage(default_language);
645 } else if (token == "\\begin_float") {
646 int tmpret = lex.FindToken(string_footnotekinds);
647 if (tmpret == -1) ++tmpret;
648 if (tmpret != LYX_LAYOUT_DEFAULT)
649 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
650 if (footnotekind == LyXParagraph::FOOTNOTE
651 || footnotekind == LyXParagraph::MARGIN)
652 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
654 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
656 } else if (token == "\\begin_float") {
657 // This is the compability reader. It can be removed in
658 // LyX version 1.3.0. (Lgb)
660 string const tmptok = lex.GetString();
661 //lyxerr << "old float: " << tmptok << endl;
664 stringstream old_float;
666 if (tmptok == "footnote") {
667 inset = new InsetFoot;
668 } else if (tmptok == "margin") {
669 inset = new InsetMarginal;
670 } else if (tmptok == "fig") {
671 inset = new InsetFloat("figure");
672 old_float << "placement htbp\n";
673 } else if (tmptok == "tab") {
674 inset = new InsetFloat("table");
675 old_float << "placement htbp\n";
676 } else if (tmptok == "alg") {
677 inset = new InsetFloat("algorithm");
678 old_float << "placement htbp\n";
679 } else if (tmptok == "wide-fig") {
680 InsetFloat * tmp = new InsetFloat("figure");
683 old_float << "placement htbp\n";
684 } else if (tmptok == "wide-tab") {
685 InsetFloat * tmp = new InsetFloat("table");
688 old_float << "placement htbp\n";
693 return false; // no end read yet
696 old_float << "collapsed true\n";
698 // Here we need to check for \end_deeper and handle that
699 // before we do the footnote parsing.
700 // This _is_ a hack! (Lgb)
703 string const tmp = lex.GetString();
704 if (tmp == "\\end_deeper") {
705 //lyxerr << "\\end_deeper caught!" << endl;
707 lex.printError("\\end_deeper: "
708 "depth is already null");
713 old_float << tmp << ' ';
718 old_float << lex.getLongString("\\end_float")
719 << "\n\\end_inset\n";
720 //lyxerr << "Float Body:\n" << old_float.str() << endl;
721 // That this does not work seems like a bug
722 // in stringstream. (Lgb)
723 istringstream istr(old_float.str());
725 nylex.setStream(istr);
726 inset->Read(this, nylex);
727 par->InsertInset(pos, inset, font);
730 } else if (token == "\\begin_deeper") {
732 } else if (token == "\\end_deeper") {
734 lex.printError("\\end_deeper: "
735 "depth is already null");
739 } else if (token == "\\begin_preamble") {
740 params.readPreamble(lex);
741 } else if (token == "\\textclass") {
743 pair<bool, LyXTextClassList::size_type> pp =
744 textclasslist.NumberOfClass(lex.GetString());
746 params.textclass = pp.second;
748 WriteAlert(string(_("Textclass error")),
749 string(_("The document uses an unknown textclass \"")) +
750 lex.GetString() + string("\"."),
751 string(_("LyX will not be able to produce output correctly.")));
752 params.textclass = 0;
754 if (!textclasslist.Load(params.textclass)) {
755 // if the textclass wasn't loaded properly
756 // we need to either substitute another
757 // or stop loading the file.
758 // I can substitute but I don't see how I can
759 // stop loading... ideas?? ARRae980418
760 WriteAlert(_("Textclass Loading Error!"),
761 string(_("Can't load textclass ")) +
762 textclasslist.NameOfClass(params.textclass),
763 _("-- substituting default"));
764 params.textclass = 0;
766 } else if (token == "\\options") {
768 params.options = lex.GetString();
769 } else if (token == "\\language") {
770 params.readLanguage(lex);
771 } else if (token == "\\fontencoding") {
773 } else if (token == "\\inputencoding") {
775 params.inputenc = lex.GetString();
776 } else if (token == "\\graphics") {
777 params.readGraphicsDriver(lex);
778 } else if (token == "\\fontscheme") {
780 params.fonts = lex.GetString();
781 } else if (token == "\\noindent") {
782 par->params.noindent(true);
783 } else if (token == "\\fill_top") {
784 par->params.spaceTop(VSpace(VSpace::VFILL));
785 } else if (token == "\\fill_bottom") {
786 par->params.spaceBottom(VSpace(VSpace::VFILL));
787 } else if (token == "\\line_top") {
788 par->params.lineTop(true);
789 } else if (token == "\\line_bottom") {
790 par->params.lineBottom(true);
791 } else if (token == "\\pagebreak_top") {
792 par->params.pagebreakTop(true);
793 } else if (token == "\\pagebreak_bottom") {
794 par->params.pagebreakBottom(true);
795 } else if (token == "\\start_of_appendix") {
796 par->params.startOfAppendix(true);
797 } else if (token == "\\paragraph_separation") {
798 int tmpret = lex.FindToken(string_paragraph_separation);
799 if (tmpret == -1) ++tmpret;
800 if (tmpret != LYX_LAYOUT_DEFAULT)
801 params.paragraph_separation =
802 static_cast<BufferParams::PARSEP>(tmpret);
803 } else if (token == "\\defskip") {
805 params.defskip = VSpace(lex.GetString());
806 } else if (token == "\\epsfig") { // obsolete
807 // Indeed it is obsolete, but we HAVE to be backwards
808 // compatible until 0.14, because otherwise all figures
809 // in existing documents are irretrivably lost. (Asger)
810 params.readGraphicsDriver(lex);
811 } else if (token == "\\quotes_language") {
812 int tmpret = lex.FindToken(string_quotes_language);
813 if (tmpret == -1) ++tmpret;
814 if (tmpret != LYX_LAYOUT_DEFAULT) {
815 InsetQuotes::quote_language tmpl =
816 InsetQuotes::EnglishQ;
819 tmpl = InsetQuotes::EnglishQ;
822 tmpl = InsetQuotes::SwedishQ;
825 tmpl = InsetQuotes::GermanQ;
828 tmpl = InsetQuotes::PolishQ;
831 tmpl = InsetQuotes::FrenchQ;
834 tmpl = InsetQuotes::DanishQ;
837 params.quotes_language = tmpl;
839 } else if (token == "\\quotes_times") {
841 switch (lex.GetInteger()) {
843 params.quotes_times = InsetQuotes::SingleQ;
846 params.quotes_times = InsetQuotes::DoubleQ;
849 } else if (token == "\\papersize") {
850 int tmpret = lex.FindToken(string_papersize);
854 params.papersize2 = tmpret;
855 } else if (token == "\\paperpackage") {
856 int tmpret = lex.FindToken(string_paperpackages);
859 params.paperpackage = BufferParams::PACKAGE_NONE;
861 params.paperpackage = tmpret;
862 } else if (token == "\\use_geometry") {
864 params.use_geometry = lex.GetInteger();
865 } else if (token == "\\use_amsmath") {
867 params.use_amsmath = lex.GetInteger();
868 } else if (token == "\\paperorientation") {
869 int tmpret = lex.FindToken(string_orientation);
870 if (tmpret == -1) ++tmpret;
871 if (tmpret != LYX_LAYOUT_DEFAULT)
872 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
873 } else if (token == "\\paperwidth") {
875 params.paperwidth = lex.GetString();
876 } else if (token == "\\paperheight") {
878 params.paperheight = lex.GetString();
879 } else if (token == "\\leftmargin") {
881 params.leftmargin = lex.GetString();
882 } else if (token == "\\topmargin") {
884 params.topmargin = lex.GetString();
885 } else if (token == "\\rightmargin") {
887 params.rightmargin = lex.GetString();
888 } else if (token == "\\bottommargin") {
890 params.bottommargin = lex.GetString();
891 } else if (token == "\\headheight") {
893 params.headheight = lex.GetString();
894 } else if (token == "\\headsep") {
896 params.headsep = lex.GetString();
897 } else if (token == "\\footskip") {
899 params.footskip = lex.GetString();
900 } else if (token == "\\paperfontsize") {
902 params.fontsize = strip(lex.GetString());
903 } else if (token == "\\papercolumns") {
905 params.columns = lex.GetInteger();
906 } else if (token == "\\papersides") {
908 switch (lex.GetInteger()) {
910 case 1: params.sides = LyXTextClass::OneSide; break;
911 case 2: params.sides = LyXTextClass::TwoSides; break;
913 } else if (token == "\\paperpagestyle") {
915 params.pagestyle = strip(lex.GetString());
916 } else if (token == "\\bullet") {
918 int const index = lex.GetInteger();
920 int temp_int = lex.GetInteger();
921 params.user_defined_bullets[index].setFont(temp_int);
922 params.temp_bullets[index].setFont(temp_int);
924 temp_int = lex.GetInteger();
925 params.user_defined_bullets[index].setCharacter(temp_int);
926 params.temp_bullets[index].setCharacter(temp_int);
928 temp_int = lex.GetInteger();
929 params.user_defined_bullets[index].setSize(temp_int);
930 params.temp_bullets[index].setSize(temp_int);
932 string const temp_str = lex.GetString();
933 if (temp_str != "\\end_bullet") {
934 // this element isn't really necessary for
935 // parsing but is easier for humans
936 // to understand bullets. Put it back and
937 // set a debug message?
938 lex.printError("\\end_bullet expected, got" + temp_str);
939 //how can I put it back?
941 } else if (token == "\\bulletLaTeX") {
943 int const index = lex.GetInteger();
945 string temp_str = lex.GetString();
947 while (temp_str != "\\end_bullet") {
948 // this loop structure is needed when user
949 // enters an empty string since the first
950 // thing returned will be the \\end_bullet
952 // if the LaTeX entry has spaces. Each element
953 // therefore needs to be read in turn
956 temp_str = lex.GetString();
958 params.user_defined_bullets[index].setText(sum_str);
959 params.temp_bullets[index].setText(sum_str);
960 } else if (token == "\\secnumdepth") {
962 params.secnumdepth = lex.GetInteger();
963 } else if (token == "\\tocdepth") {
965 params.tocdepth = lex.GetInteger();
966 } else if (token == "\\spacing") {
968 string const tmp = strip(lex.GetString());
969 Spacing::Space tmp_space = Spacing::Default;
971 if (tmp == "single") {
972 tmp_space = Spacing::Single;
973 } else if (tmp == "onehalf") {
974 tmp_space = Spacing::Onehalf;
975 } else if (tmp == "double") {
976 tmp_space = Spacing::Double;
977 } else if (tmp == "other") {
979 tmp_space = Spacing::Other;
980 tmp_val = lex.GetFloat();
982 lex.printError("Unknown spacing token: '$$Token'");
984 // Small hack so that files written with klyx will be
987 par->params.spacing(Spacing(tmp_space, tmp_val));
989 params.spacing.set(tmp_space, tmp_val);
991 } else if (token == "\\paragraph_spacing") {
993 string const tmp = strip(lex.GetString());
994 if (tmp == "single") {
995 par->params.spacing(Spacing(Spacing::Single));
996 } else if (tmp == "onehalf") {
997 par->params.spacing(Spacing(Spacing::Onehalf));
998 } else if (tmp == "double") {
999 par->params.spacing(Spacing(Spacing::Double));
1000 } else if (tmp == "other") {
1002 par->params.spacing(Spacing(Spacing::Other,
1005 lex.printError("Unknown spacing token: '$$Token'");
1007 } else if (token == "\\float_placement") {
1009 params.float_placement = lex.GetString();
1010 } else if (token == "\\family") {
1012 font.setLyXFamily(lex.GetString());
1013 } else if (token == "\\series") {
1015 font.setLyXSeries(lex.GetString());
1016 } else if (token == "\\shape") {
1018 font.setLyXShape(lex.GetString());
1019 } else if (token == "\\size") {
1021 font.setLyXSize(lex.GetString());
1022 } else if (token == "\\latex") {
1024 string const tok = lex.GetString();
1025 // This is dirty, but gone with LyX3. (Asger)
1026 if (tok == "no_latex")
1027 font.setLatex(LyXFont::OFF);
1028 else if (tok == "latex")
1029 font.setLatex(LyXFont::ON);
1030 else if (tok == "default")
1031 font.setLatex(LyXFont::INHERIT);
1033 lex.printError("Unknown LaTeX font flag "
1035 } else if (token == "\\lang") {
1037 string const tok = lex.GetString();
1038 Language const * lang = languages.getLanguage(tok);
1040 font.setLanguage(lang);
1042 font.setLanguage(params.language);
1043 lex.printError("Unknown language `$$Token'");
1045 } else if (token == "\\numeric") {
1047 font.setNumber(font.setLyXMisc(lex.GetString()));
1048 } else if (token == "\\emph") {
1050 font.setEmph(font.setLyXMisc(lex.GetString()));
1051 } else if (token == "\\bar") {
1053 string const tok = lex.GetString();
1054 // This is dirty, but gone with LyX3. (Asger)
1056 font.setUnderbar(LyXFont::ON);
1057 else if (tok == "no")
1058 font.setUnderbar(LyXFont::OFF);
1059 else if (tok == "default")
1060 font.setUnderbar(LyXFont::INHERIT);
1062 lex.printError("Unknown bar font flag "
1064 } else if (token == "\\noun") {
1066 font.setNoun(font.setLyXMisc(lex.GetString()));
1067 } else if (token == "\\color") {
1069 font.setLyXColor(lex.GetString());
1070 } else if (token == "\\align") {
1071 int tmpret = lex.FindToken(string_align);
1072 if (tmpret == -1) ++tmpret;
1073 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1074 int const tmpret2 = int(pow(2.0, tmpret));
1075 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1076 par->params.align(LyXAlignment(tmpret2));
1078 } else if (token == "\\added_space_top") {
1080 par->params.spaceTop(VSpace(lex.GetString()));
1081 } else if (token == "\\added_space_bottom") {
1083 par->params.spaceBottom(VSpace(lex.GetString()));
1084 } else if (token == "\\pextra_type") {
1086 par->params.pextraType(lex.GetInteger());
1087 } else if (token == "\\pextra_width") {
1089 par->params.pextraWidth(lex.GetString());
1090 } else if (token == "\\pextra_widthp") {
1092 par->params.pextraWidthp(lex.GetString());
1093 } else if (token == "\\pextra_alignment") {
1095 par->params.pextraAlignment(lex.GetInteger());
1096 } else if (token == "\\pextra_hfill") {
1098 par->params.pextraHfill(lex.GetInteger());
1099 } else if (token == "\\pextra_start_minipage") {
1101 par->params.pextraStartMinipage(lex.GetInteger());
1102 } else if (token == "\\labelwidthstring") {
1104 par->params.labelWidthString(lex.GetString());
1105 // do not delete this token, it is still needed!
1106 } else if (token == "\\end_inset") {
1107 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1108 << "Last inset read was: " << last_inset_read
1110 // Simply ignore this. The insets do not have
1112 // But insets should read it, it is a part of
1113 // the inset isn't it? Lgb.
1114 } else if (token == "\\begin_inset") {
1115 readInset(lex, par, pos, font);
1116 } else if (token == "\\SpecialChar") {
1117 LyXLayout const & layout =
1118 textclasslist.Style(params.textclass,
1121 // Insets don't make sense in a free-spacing context! ---Kayvan
1122 if (layout.free_spacing) {
1125 string next_token = lex.GetString();
1126 if (next_token == "\\-") {
1127 par->InsertChar(pos, '-', font);
1128 } else if (next_token == "\\protected_separator"
1129 || next_token == "~") {
1130 par->InsertChar(pos, ' ', font);
1132 lex.printError("Token `$$Token' "
1134 "paragraph layout!");
1139 Inset * inset = new InsetSpecialChar;
1140 inset->Read(this, lex);
1141 par->InsertInset(pos, inset, font);
1144 } else if (token == "\\newline") {
1145 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1147 } else if (token == "\\LyXTable") {
1148 Inset * inset = new InsetTabular(*this);
1149 inset->Read(this, lex);
1150 par->InsertInset(pos, inset, font);
1152 } else if (token == "\\hfill") {
1153 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1155 } else if (token == "\\protected_separator") { // obsolete
1156 // This is a backward compability thingie. (Lgb)
1157 // Remove it later some time...introduced with fileformat
1159 LyXLayout const & layout =
1160 textclasslist.Style(params.textclass,
1163 if (layout.free_spacing) {
1164 par->InsertChar(pos, ' ', font);
1166 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1167 par->InsertInset(pos, inset, font);
1170 } else if (token == "\\bibitem") { // ale970302
1172 InsetCommandParams p("bibitem", "dummy");
1173 par->bibkey = new InsetBibKey(p);
1175 par->bibkey->Read(this, lex);
1176 } else if (token == "\\backslash") {
1177 par->InsertChar(pos, '\\', font);
1179 } else if (token == "\\the_end") {
1180 the_end_read = true;
1182 // This should be insurance for the future: (Asger)
1183 lex.printError("Unknown token `$$Token'. "
1184 "Inserting as text.");
1185 string::const_iterator cit = token.begin();
1186 string::const_iterator end = token.end();
1187 for (; cit != end; ++cit) {
1188 par->InsertChar(pos, (*cit), font);
1193 return the_end_read;
1197 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1198 int & pos, LyXFont & font)
1200 // consistency check
1201 if (lex.GetString() != "\\begin_inset") {
1202 lyxerr << "Buffer::readInset: Consistency check failed."
1209 string const tmptok = lex.GetString();
1210 last_inset_read = tmptok;
1212 // test the different insets
1213 if (tmptok == "LatexCommand") {
1214 InsetCommandParams inscmd;
1217 if (inscmd.getCmdName() == "cite") {
1218 inset = new InsetCitation(inscmd);
1219 } else if (inscmd.getCmdName() == "bibitem") {
1220 lex.printError("Wrong place for bibitem");
1221 inset = new InsetBibKey(inscmd);
1222 } else if (inscmd.getCmdName() == "BibTeX") {
1223 inset = new InsetBibtex(inscmd);
1224 } else if (inscmd.getCmdName() == "index") {
1225 inset = new InsetIndex(inscmd);
1226 } else if (inscmd.getCmdName() == "include") {
1227 inset = new InsetInclude(inscmd, *this);
1228 } else if (inscmd.getCmdName() == "label") {
1229 inset = new InsetLabel(inscmd);
1230 } else if (inscmd.getCmdName() == "url"
1231 || inscmd.getCmdName() == "htmlurl") {
1232 inset = new InsetUrl(inscmd);
1233 } else if (inscmd.getCmdName() == "ref"
1234 || inscmd.getCmdName() == "pageref"
1235 || inscmd.getCmdName() == "vref"
1236 || inscmd.getCmdName() == "vpageref"
1237 || inscmd.getCmdName() == "prettyref") {
1238 if (!inscmd.getOptions().empty()
1239 || !inscmd.getContents().empty()) {
1240 inset = new InsetRef(inscmd, *this);
1242 } else if (inscmd.getCmdName() == "tableofcontents"
1243 || inscmd.getCmdName() == "listofalgorithms"
1244 || inscmd.getCmdName() == "listoffigures"
1245 || inscmd.getCmdName() == "listoftables") {
1246 inset = new InsetTOC(inscmd);
1247 } else if (inscmd.getCmdName() == "printindex") {
1248 inset = new InsetPrintIndex(inscmd);
1249 } else if (inscmd.getCmdName() == "lyxparent") {
1250 inset = new InsetParent(inscmd, *this);
1253 if (tmptok == "Quotes") {
1254 inset = new InsetQuotes;
1255 } else if (tmptok == "External") {
1256 inset = new InsetExternal;
1257 } else if (tmptok == "FormulaMacro") {
1258 inset = new InsetFormulaMacro;
1259 } else if (tmptok == "Formula") {
1260 inset = new InsetFormula;
1261 } else if (tmptok == "Figure") {
1262 inset = new InsetFig(100, 100, *this);
1263 } else if (tmptok == "Info") {
1264 inset = new InsetInfo;
1265 } else if (tmptok == "Include") {
1266 InsetCommandParams p( "Include" );
1267 inset = new InsetInclude(p, *this);
1268 } else if (tmptok == "ERT") {
1269 inset = new InsetERT;
1270 } else if (tmptok == "Tabular") {
1271 inset = new InsetTabular(*this);
1272 } else if (tmptok == "Text") {
1273 inset = new InsetText;
1274 } else if (tmptok == "Foot") {
1275 inset = new InsetFoot;
1276 } else if (tmptok == "Marginal") {
1277 inset = new InsetMarginal;
1278 } else if (tmptok == "Minipage") {
1279 inset = new InsetMinipage;
1280 } else if (tmptok == "Float") {
1282 string tmptok = lex.GetString();
1283 inset = new InsetFloat(tmptok);
1284 } else if (tmptok == "List") {
1285 inset = new InsetList;
1286 } else if (tmptok == "Theorem") {
1287 inset = new InsetList;
1288 } else if (tmptok == "Caption") {
1289 inset = new InsetCaption;
1290 } else if (tmptok == "GRAPHICS") {
1291 inset = new InsetGraphics;
1294 if (inset) inset->Read(this, lex);
1298 par->InsertInset(pos, inset, font);
1304 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1308 string const token(lex.GetString());
1309 if (token == "\\lyxformat") { // the first token _must_ be...
1311 string tmp_format = lex.GetString();
1312 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1313 // if present remove ".," from string.
1314 string::size_type dot = tmp_format.find_first_of(".,");
1315 //lyxerr << " dot found at " << dot << endl;
1316 if (dot != string::npos)
1317 tmp_format.erase(dot, 1);
1318 file_format = strToInt(tmp_format);
1319 if (file_format == LYX_FORMAT) {
1321 } else if (file_format > LYX_FORMAT) {
1323 WriteAlert(_("Warning!"),
1324 _("LyX file format is newer that what"),
1325 _("is supported in this LyX version. Expect some problems."));
1327 } else if (file_format < LYX_FORMAT) {
1329 if (file_format < 200) {
1330 WriteAlert(_("ERROR!"),
1331 _("Old LyX file format found. "
1332 "Use LyX 0.10.x to read this!"));
1336 bool the_end = readLyXformat2(lex, par);
1338 // the_end was added in 213
1339 if (file_format < 213)
1343 WriteAlert(_("Warning!"),
1344 _("Reading of document is not complete"),
1345 _("Maybe the document is truncated"));
1347 } else { // "\\lyxformat" not found
1348 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1351 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1357 // Should probably be moved to somewhere else: BufferView? LyXView?
1358 bool Buffer::save() const
1360 // We don't need autosaves in the immediate future. (Asger)
1361 resetAutosaveTimers();
1365 if (lyxrc.make_backup) {
1366 s = fileName() + '~';
1367 if (!lyxrc.backupdir_path.empty())
1368 s = AddName(lyxrc.backupdir_path,
1369 subst(CleanupPath(s),'/','!'));
1371 // Rename is the wrong way of making a backup,
1372 // this is the correct way.
1373 /* truss cp fil fil2:
1374 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1375 stat("LyXVC.lyx", 0xEFFFF688) = 0
1376 open("LyXVC.lyx", O_RDONLY) = 3
1377 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1378 fstat(4, 0xEFFFF508) = 0
1379 fstat(3, 0xEFFFF508) = 0
1380 read(3, " # T h i s f i l e w".., 8192) = 5579
1381 write(4, " # T h i s f i l e w".., 5579) = 5579
1382 read(3, 0xEFFFD4A0, 8192) = 0
1385 chmod("LyXVC3.lyx", 0100644) = 0
1386 lseek(0, 0, SEEK_CUR) = 46440
1390 // Should proabaly have some more error checking here.
1391 // Should be cleaned up in 0.13, at least a bit.
1392 // Doing it this way, also makes the inodes stay the same.
1393 // This is still not a very good solution, in particular we
1394 // might loose the owner of the backup.
1395 FileInfo finfo(fileName());
1396 if (finfo.exist()) {
1397 mode_t fmode = finfo.getMode();
1398 struct utimbuf times = {
1399 finfo.getAccessTime(),
1400 finfo.getModificationTime() };
1402 ifstream ifs(fileName().c_str());
1403 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1408 ::chmod(s.c_str(), fmode);
1410 if (::utime(s.c_str(), ×)) {
1411 lyxerr << "utime error." << endl;
1414 lyxerr << "LyX was not able to make "
1415 "backupcopy. Beware." << endl;
1420 if (writeFile(fileName(), false)) {
1422 removeAutosaveFile(fileName());
1424 // Saving failed, so backup is not backup
1425 if (lyxrc.make_backup) {
1426 lyx::rename(s, fileName());
1434 // Returns false if unsuccesful
1435 bool Buffer::writeFile(string const & fname, bool flag) const
1437 // if flag is false writeFile will not create any GUI
1438 // warnings, only cerr.
1439 // Needed for autosave in background or panic save (Matthias 120496)
1441 if (read_only && (fname == filename)) {
1442 // Here we should come with a question if we should
1443 // perform the write anyway.
1445 lyxerr << _("Error! Document is read-only: ")
1448 WriteAlert(_("Error! Document is read-only: "),
1453 FileInfo finfo(fname);
1454 if (finfo.exist() && !finfo.writable()) {
1455 // Here we should come with a question if we should
1456 // try to do the save anyway. (i.e. do a chmod first)
1458 lyxerr << _("Error! Cannot write file: ")
1461 WriteFSAlert(_("Error! Cannot write file: "),
1466 ofstream ofs(fname.c_str());
1469 lyxerr << _("Error! Cannot open file: ")
1472 WriteFSAlert(_("Error! Cannot open file: "),
1478 // Use the standard "C" locale for file output.
1479 ofs.imbue(std::locale::classic());
1482 // The top of the file should not be written by params.
1484 // write out a comment in the top of the file
1485 ofs << '#' << LYX_DOCVERSION
1486 << " created this file. For more info see http://www.lyx.org/\n"
1487 << "\\lyxformat " << LYX_FORMAT << "\n";
1489 // now write out the buffer paramters.
1490 params.writeFile(ofs);
1492 char footnoteflag = 0;
1495 // this will write out all the paragraphs
1496 // using recursive descent.
1497 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1499 // Write marker that shows file is complete
1500 ofs << "\n\\the_end" << endl;
1504 // how to check if close went ok?
1505 // Following is an attempt... (BE 20001011)
1507 // good() returns false if any error occured, including some
1508 // formatting error.
1509 // bad() returns true if something bad happened in the buffer,
1510 // which should include file system full errors.
1517 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1519 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1529 string const Buffer::asciiParagraph(LyXParagraph const * par,
1530 unsigned int linelen) const
1532 ostringstream buffer;
1535 Inset const * inset;
1538 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1542 int ltype_depth = 0;
1543 unsigned int currlinelen = 0;
1544 bool ref_printed = false;
1549 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1551 || par->previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1552 /* begins a footnote environment ? */
1553 if (footnoteflag != par->footnoteflag) {
1554 footnoteflag = par->footnoteflag;
1556 size_t const j = strlen(string_footnotekinds[par->footnotekind]) + 4;
1557 if ((linelen > 0) &&
1558 ((currlinelen + j) > linelen)) {
1563 << string_footnotekinds[par->footnotekind]
1569 if (!par->previous()) {
1571 /* begins or ends a deeper area ?*/
1572 if (depth != par->params.depth()) {
1573 if (par->params.depth() > depth) {
1574 while (par->params.depth() > depth) {
1578 while (par->params.depth() < depth) {
1584 /* First write the layout */
1585 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1586 if (tmp == "Itemize") {
1588 ltype_depth = depth + 1;
1589 } else if (tmp == "Enumerate") {
1591 ltype_depth = depth + 1;
1592 } else if (strstr(tmp.c_str(), "ection")) {
1594 ltype_depth = depth + 1;
1595 } else if (strstr(tmp.c_str(), "aragraph")) {
1597 ltype_depth = depth + 1;
1598 } else if (tmp == "Description") {
1600 ltype_depth = depth + 1;
1601 } else if (tmp == "Abstract") {
1604 } else if (tmp == "Bibliography") {
1612 /* maybe some vertical spaces */
1614 /* the labelwidthstring used in lists */
1618 /* some pagebreaks? */
1622 /* what about the alignment */
1625 /* dummy layout, that means a footnote ended */
1626 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1630 lyxerr << "Should this ever happen?" << endl;
1634 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
1635 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
1643 for (char j = 0; j < depth; ++j)
1645 currlinelen = depth * 2;
1647 case 0: /* Standard */
1648 case 4: /* (Sub)Paragraph */
1649 case 5: /* Description */
1651 case 6: /* Abstract */
1653 buffer << "Abstract\n\n";
1655 buffer << "Abstract: ";
1657 case 7: /* Bibliography */
1660 buffer << "References\n\n";
1662 buffer << "References: ";
1667 buffer << par->params.labelString() << " ";
1670 if (ltype_depth > depth) {
1671 for (char j = ltype_depth - 1; j > depth; --j)
1673 currlinelen += (ltype_depth-depth)*2;
1676 font2 = par->GetFontSettings(params, i);
1677 if (font1.latex() != font2.latex()) {
1678 if (font2.latex() == LyXFont::OFF)
1685 c = par->GetUChar(params, i);
1689 case LyXParagraph::META_INSET:
1690 if ((inset = par->GetInset(i))) {
1691 if (!inset->Ascii(this, buffer)) {
1693 string s = rsplit(buffer.str().c_str(),
1695 currlinelen += s.length();
1697 // to be sure it breaks paragraph
1698 currlinelen += linelen;
1702 case LyXParagraph::META_NEWLINE:
1705 for (char j = 0; j < depth; ++j)
1708 currlinelen = depth * 2;
1709 if (ltype_depth > depth) {
1710 for (char j = ltype_depth;
1713 currlinelen += (ltype_depth - depth) * 2;
1716 case LyXParagraph::META_HFILL:
1723 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1724 (c == ' ') && ((i + 2) < par->size()))
1727 for (char j = 0; j < depth; ++j)
1729 currlinelen = depth * 2;
1730 if (ltype_depth > depth) {
1731 for (char j = ltype_depth;
1734 currlinelen += (ltype_depth-depth)*2;
1736 } else if (c != '\0')
1739 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1744 return buffer.str().c_str();
1748 void Buffer::writeFileAscii(string const & fname, int linelen)
1750 ofstream ofs(fname.c_str());
1752 WriteFSAlert(_("Error: Cannot write file:"), fname);
1755 writeFileAscii(ofs, linelen);
1759 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1761 LyXParagraph * par = paragraph;
1763 ofs << asciiParagraph(par, linelen);
1771 void Buffer::makeLaTeXFile(string const & fname,
1772 string const & original_path,
1773 bool nice, bool only_body)
1775 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1777 niceFile = nice; // this will be used by Insetincludes.
1779 tex_code_break_column = lyxrc.ascii_linelen;
1781 LyXTextClass const & tclass =
1782 textclasslist.TextClass(params.textclass);
1784 ofstream ofs(fname.c_str());
1786 WriteFSAlert(_("Error: Cannot open file: "), fname);
1790 // validate the buffer.
1791 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1792 LaTeXFeatures features(params, tclass.numLayouts());
1794 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1797 // The starting paragraph of the coming rows is the
1798 // first paragraph of the document. (Asger)
1799 texrow.start(paragraph, 0);
1801 if (!only_body && nice) {
1802 ofs << "%% " LYX_DOCVERSION " created this file. "
1803 "For more info, see http://www.lyx.org/.\n"
1804 "%% Do not edit unless you really know what "
1809 lyxerr.debug() << "lyx header finished" << endl;
1810 // There are a few differences between nice LaTeX and usual files:
1811 // usual is \batchmode and has a
1812 // special input@path to allow the including of figures
1813 // with either \input or \includegraphics (what figinsets do).
1814 // batchmode is not set if there is a tex_code_break_column.
1815 // In this case somebody is interested in the generated LaTeX,
1816 // so this is OK. input@path is set when the actual parameter
1817 // original_path is set. This is done for usual tex-file, but not
1818 // for nice-latex-file. (Matthias 250696)
1821 // code for usual, NOT nice-latex-file
1822 ofs << "\\batchmode\n"; // changed
1823 // from \nonstopmode
1826 if (!original_path.empty()) {
1827 ofs << "\\makeatletter\n"
1828 << "\\def\\input@path{{"
1829 << original_path << "/}}\n"
1830 << "\\makeatother\n";
1836 ofs << "\\documentclass";
1838 string options; // the document class options.
1840 if (tokenPos(tclass.opt_fontsize(),
1841 '|', params.fontsize) >= 0) {
1842 // only write if existing in list (and not default)
1843 options += params.fontsize;
1848 if (!params.use_geometry &&
1849 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1850 switch (params.papersize) {
1851 case BufferParams::PAPER_A4PAPER:
1852 options += "a4paper,";
1854 case BufferParams::PAPER_USLETTER:
1855 options += "letterpaper,";
1857 case BufferParams::PAPER_A5PAPER:
1858 options += "a5paper,";
1860 case BufferParams::PAPER_B5PAPER:
1861 options += "b5paper,";
1863 case BufferParams::PAPER_EXECUTIVEPAPER:
1864 options += "executivepaper,";
1866 case BufferParams::PAPER_LEGALPAPER:
1867 options += "legalpaper,";
1873 if (params.sides != tclass.sides()) {
1874 switch (params.sides) {
1875 case LyXTextClass::OneSide:
1876 options += "oneside,";
1878 case LyXTextClass::TwoSides:
1879 options += "twoside,";
1886 if (params.columns != tclass.columns()) {
1887 if (params.columns == 2)
1888 options += "twocolumn,";
1890 options += "onecolumn,";
1893 if (!params.use_geometry
1894 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1895 options += "landscape,";
1897 // language should be a parameter to \documentclass
1899 string language_options;
1900 if (params.language->babel() == "hebrew"
1901 && default_language->babel() != "hebrew")
1902 // This seems necessary
1903 features.UsedLanguages.insert(default_language);
1905 if (lyxrc.language_use_babel ||
1906 params.language->lang() != lyxrc.default_language ||
1907 !features.UsedLanguages.empty()) {
1909 for (LaTeXFeatures::LanguageList::const_iterator cit =
1910 features.UsedLanguages.begin();
1911 cit != features.UsedLanguages.end(); ++cit)
1912 language_options += (*cit)->babel() + ',';
1913 language_options += params.language->babel();
1914 if (lyxrc.language_global_options)
1915 options += language_options + ',';
1918 // the user-defined options
1919 if (!params.options.empty()) {
1920 options += params.options + ',';
1923 if (!options.empty()){
1924 options = strip(options, ',');
1925 ofs << '[' << options << ']';
1929 << textclasslist.LatexnameOfClass(params.textclass)
1932 // end of \documentclass defs
1934 // font selection must be done before loading fontenc.sty
1935 // The ae package is not needed when using OT1 font encoding.
1936 if (params.fonts != "default" &&
1937 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
1938 ofs << "\\usepackage{" << params.fonts << "}\n";
1940 if (params.fonts == "ae") {
1941 ofs << "\\usepackage{aecompl}\n";
1945 // this one is not per buffer
1946 if (lyxrc.fontenc != "default") {
1947 ofs << "\\usepackage[" << lyxrc.fontenc
1952 if (params.inputenc == "auto") {
1953 string const doc_encoding =
1954 params.language->encoding()->LatexName();
1956 // Create a list with all the input encodings used
1958 set<string> encodings;
1959 for (LaTeXFeatures::LanguageList::const_iterator it =
1960 features.UsedLanguages.begin();
1961 it != features.UsedLanguages.end(); ++it)
1962 if ((*it)->encoding()->LatexName() != doc_encoding)
1963 encodings.insert((*it)->encoding()->LatexName());
1965 ofs << "\\usepackage[";
1966 std::copy(encodings.begin(), encodings.end(),
1967 std::ostream_iterator<string>(ofs, ","));
1968 ofs << doc_encoding << "]{inputenc}\n";
1970 } else if (params.inputenc != "default") {
1971 ofs << "\\usepackage[" << params.inputenc
1976 // At the very beginning the text parameters.
1977 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1978 switch (params.paperpackage) {
1979 case BufferParams::PACKAGE_A4:
1980 ofs << "\\usepackage{a4}\n";
1983 case BufferParams::PACKAGE_A4WIDE:
1984 ofs << "\\usepackage{a4wide}\n";
1987 case BufferParams::PACKAGE_WIDEMARGINSA4:
1988 ofs << "\\usepackage[widemargins]{a4}\n";
1993 if (params.use_geometry) {
1994 ofs << "\\usepackage{geometry}\n";
1996 ofs << "\\geometry{verbose";
1997 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1998 ofs << ",landscape";
1999 switch (params.papersize2) {
2000 case BufferParams::VM_PAPER_CUSTOM:
2001 if (!params.paperwidth.empty())
2002 ofs << ",paperwidth="
2003 << params.paperwidth;
2004 if (!params.paperheight.empty())
2005 ofs << ",paperheight="
2006 << params.paperheight;
2008 case BufferParams::VM_PAPER_USLETTER:
2009 ofs << ",letterpaper";
2011 case BufferParams::VM_PAPER_USLEGAL:
2012 ofs << ",legalpaper";
2014 case BufferParams::VM_PAPER_USEXECUTIVE:
2015 ofs << ",executivepaper";
2017 case BufferParams::VM_PAPER_A3:
2020 case BufferParams::VM_PAPER_A4:
2023 case BufferParams::VM_PAPER_A5:
2026 case BufferParams::VM_PAPER_B3:
2029 case BufferParams::VM_PAPER_B4:
2032 case BufferParams::VM_PAPER_B5:
2036 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2037 switch (lyxrc.default_papersize) {
2038 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2039 case BufferParams::PAPER_USLETTER:
2040 ofs << ",letterpaper";
2042 case BufferParams::PAPER_LEGALPAPER:
2043 ofs << ",legalpaper";
2045 case BufferParams::PAPER_EXECUTIVEPAPER:
2046 ofs << ",executivepaper";
2048 case BufferParams::PAPER_A3PAPER:
2051 case BufferParams::PAPER_A4PAPER:
2054 case BufferParams::PAPER_A5PAPER:
2057 case BufferParams::PAPER_B5PAPER:
2062 if (!params.topmargin.empty())
2063 ofs << ",tmargin=" << params.topmargin;
2064 if (!params.bottommargin.empty())
2065 ofs << ",bmargin=" << params.bottommargin;
2066 if (!params.leftmargin.empty())
2067 ofs << ",lmargin=" << params.leftmargin;
2068 if (!params.rightmargin.empty())
2069 ofs << ",rmargin=" << params.rightmargin;
2070 if (!params.headheight.empty())
2071 ofs << ",headheight=" << params.headheight;
2072 if (!params.headsep.empty())
2073 ofs << ",headsep=" << params.headsep;
2074 if (!params.footskip.empty())
2075 ofs << ",footskip=" << params.footskip;
2079 if (features.amsstyle
2080 && !tclass.provides(LyXTextClass::amsmath)) {
2081 ofs << "\\usepackage{amsmath}\n";
2085 if (tokenPos(tclass.opt_pagestyle(),
2086 '|', params.pagestyle) >= 0) {
2087 if (params.pagestyle == "fancy") {
2088 ofs << "\\usepackage{fancyhdr}\n";
2091 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2095 // We try to load babel late, in case it interferes
2096 // with other packages.
2098 string tmp = lyxrc.language_package;
2099 if (!lyxrc.language_global_options
2100 && tmp == "\\usepackage{babel}")
2101 tmp = "\\usepackage[" +
2102 language_options + "]{babel}";
2107 if (params.secnumdepth != tclass.secnumdepth()) {
2108 ofs << "\\setcounter{secnumdepth}{"
2109 << params.secnumdepth
2113 if (params.tocdepth != tclass.tocdepth()) {
2114 ofs << "\\setcounter{tocdepth}{"
2120 if (params.paragraph_separation) {
2121 switch (params.defskip.kind()) {
2122 case VSpace::SMALLSKIP:
2123 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2125 case VSpace::MEDSKIP:
2126 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2128 case VSpace::BIGSKIP:
2129 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2131 case VSpace::LENGTH:
2132 ofs << "\\setlength\\parskip{"
2133 << params.defskip.length().asLatexString()
2136 default: // should never happen // Then delete it.
2137 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2142 ofs << "\\setlength\\parindent{0pt}\n";
2146 // Now insert the LyX specific LaTeX commands...
2148 // The optional packages;
2149 string preamble(features.getPackages());
2151 // this might be useful...
2152 preamble += "\n\\makeatletter\n";
2154 // Some macros LyX will need
2155 string tmppreamble(features.getMacros());
2157 if (!tmppreamble.empty()) {
2158 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2159 "LyX specific LaTeX commands.\n"
2160 + tmppreamble + '\n';
2163 // the text class specific preamble
2164 tmppreamble = features.getTClassPreamble();
2165 if (!tmppreamble.empty()) {
2166 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2167 "Textclass specific LaTeX commands.\n"
2168 + tmppreamble + '\n';
2171 /* the user-defined preamble */
2172 if (!params.preamble.empty()) {
2173 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2174 "User specified LaTeX commands.\n"
2175 + params.preamble + '\n';
2178 preamble += "\\makeatother\n";
2180 // Itemize bullet settings need to be last in case the user
2181 // defines their own bullets that use a package included
2182 // in the user-defined preamble -- ARRae
2183 // Actually it has to be done much later than that
2184 // since some packages like frenchb make modifications
2185 // at \begin{document} time -- JMarc
2187 for (int i = 0; i < 4; ++i) {
2188 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2189 if (bullets_def.empty())
2190 bullets_def="\\AtBeginDocument{\n";
2191 bullets_def += " \\renewcommand{\\labelitemi";
2193 // `i' is one less than the item to modify
2200 bullets_def += "ii";
2206 bullets_def += "}{" +
2207 params.user_defined_bullets[i].getText()
2212 if (!bullets_def.empty())
2213 preamble += bullets_def + "}\n\n";
2215 for (int j = countChar(preamble, '\n'); j-- ;) {
2222 ofs << "\\begin{document}\n";
2225 lyxerr.debug() << "preamble finished, now the body." << endl;
2227 if (!lyxrc.language_auto_begin) {
2228 ofs << subst(lyxrc.language_command_begin, "$$lang",
2229 params.language->babel())
2234 latexParagraphs(ofs, paragraph, 0, texrow);
2236 // add this just in case after all the paragraphs
2240 if (!lyxrc.language_auto_end) {
2241 ofs << subst(lyxrc.language_command_end, "$$lang",
2242 params.language->babel())
2248 ofs << "\\end{document}\n";
2251 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2253 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2257 // Just to be sure. (Asger)
2260 // tex_code_break_column's value is used to decide
2261 // if we are in batchmode or not (within mathed_write()
2262 // in math_write.C) so we must set it to a non-zero
2263 // value when we leave otherwise we save incorrect .lyx files.
2264 tex_code_break_column = lyxrc.ascii_linelen;
2268 lyxerr << "File was not closed properly." << endl;
2271 lyxerr.debug() << "Finished making latex file." << endl;
2276 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2278 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2279 LyXParagraph * endpar, TexRow & texrow) const
2281 bool was_title = false;
2282 bool already_title = false;
2283 std::ostringstream ftnote;
2288 while (par != endpar) {
2291 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2294 LyXLayout const & layout =
2295 textclasslist.Style(params.textclass,
2298 if (layout.intitle) {
2299 if (already_title) {
2300 lyxerr <<"Error in latexParagraphs: You"
2301 " should not mix title layouts"
2302 " with normal ones." << endl;
2305 } else if (was_title && !already_title) {
2306 ofs << "\\maketitle\n";
2308 already_title = true;
2311 // We are at depth 0 so we can just use
2312 // ordinary \footnote{} generation
2313 // flag this with ftcount
2315 if (layout.isEnvironment()
2317 || par->params.pextraType() != LyXParagraph::PEXTRA_NONE
2320 par = par->TeXEnvironment(this, params, ofs, texrow
2322 ,ftnote, ft_texrow, ftcount
2326 par = par->TeXOnePar(this, params, ofs, texrow, false
2329 ftnote, ft_texrow, ftcount
2334 // Write out what we've generated...
2337 ofs << "\\addtocounter{footnote}{-"
2341 ofs << ftnote.str();
2342 texrow += ft_texrow;
2344 // The extra .c_str() is needed when we use
2345 // lyxstring instead of the STL string class.
2346 ftnote.str(string().c_str());
2351 // It might be that we only have a title in this document
2352 if (was_title && !already_title) {
2353 ofs << "\\maketitle\n";
2359 bool Buffer::isLatex() const
2361 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2365 bool Buffer::isLinuxDoc() const
2367 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2371 bool Buffer::isLiterate() const
2373 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2377 bool Buffer::isDocBook() const
2379 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2383 bool Buffer::isSGML() const
2385 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2386 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2390 void Buffer::sgmlOpenTag(ostream & os, int depth,
2391 string const & latexname) const
2393 if (latexname != "!-- --")
2394 os << string(depth, ' ') << "<" << latexname << ">\n";
2398 void Buffer::sgmlCloseTag(ostream & os, int depth,
2399 string const & latexname) const
2401 if (latexname != "!-- --")
2402 os << string(depth, ' ') << "</" << latexname << ">\n";
2406 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2408 LyXParagraph * par = paragraph;
2410 niceFile = nice; // this will be used by Insetincludes.
2412 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2413 string environment_stack[10];
2416 int depth = 0; // paragraph depth
2418 ofstream ofs(fname.c_str());
2421 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2425 LyXTextClass const & tclass =
2426 textclasslist.TextClass(params.textclass);
2428 LaTeXFeatures features(params, tclass.numLayouts());
2432 tex_code_break_column = lyxrc.ascii_linelen;
2434 //tex_code_break_column = 0;
2439 string sgml_includedfiles=features.getIncludedFiles(fname);
2441 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2442 ofs << "<!doctype linuxdoc system>\n\n";
2444 ofs << "<!doctype linuxdoc system [ "
2445 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2448 if (params.options.empty())
2449 sgmlOpenTag(ofs, 0, top_element);
2451 string top = top_element;
2453 top += params.options;
2454 sgmlOpenTag(ofs, 0, top);
2458 ofs << "<!-- " << LYX_DOCVERSION
2459 << " created this file. For more info see http://www.lyx.org/"
2463 int desc_on = 0; // description mode
2464 LyXLayout const & style =
2465 textclasslist.Style(params.textclass,
2468 // treat <toc> as a special case for compatibility with old code
2469 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2470 Inset * inset = par->GetInset(0);
2471 Inset::Code lyx_code = inset->LyxCode();
2472 if (lyx_code == Inset::TOC_CODE){
2473 string const temp = "toc";
2474 sgmlOpenTag(ofs, depth, temp);
2478 linuxDocHandleFootnote(ofs, par, depth);
2486 // environment tag closing
2487 for (; depth > par->params.depth(); --depth) {
2488 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2489 environment_stack[depth].erase();
2492 // write opening SGML tags
2493 switch (style.latextype) {
2494 case LATEX_PARAGRAPH:
2495 if (depth == par->params.depth()
2496 && !environment_stack[depth].empty()) {
2497 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2498 environment_stack[depth].erase();
2504 sgmlOpenTag(ofs, depth, style.latexname());
2509 LinuxDocError(par, 0,
2510 _("Error : Wrong depth for"
2511 " LatexType Command.\n"));
2513 if (!environment_stack[depth].empty()){
2514 sgmlCloseTag(ofs, depth,
2515 environment_stack[depth]);
2519 environment_stack[depth].erase();
2520 sgmlOpenTag(ofs, depth, style.latexname());
2523 case LATEX_ENVIRONMENT:
2524 case LATEX_ITEM_ENVIRONMENT:
2525 if (depth == par->params.depth()
2526 && environment_stack[depth] != style.latexname()
2527 && !environment_stack[depth].empty()) {
2529 sgmlCloseTag(ofs, depth,
2530 environment_stack[depth]);
2531 environment_stack[depth].erase();
2533 if (depth < par->params.depth()) {
2534 depth = par->params.depth();
2535 environment_stack[depth].erase();
2537 if (environment_stack[depth] != style.latexname()) {
2539 string const temp = "p";
2540 sgmlOpenTag(ofs, depth, temp);
2542 environment_stack[depth] = style.latexname();
2543 sgmlOpenTag(ofs, depth,
2544 environment_stack[depth]);
2546 if (style.latextype == LATEX_ENVIRONMENT) break;
2548 desc_on = (style.labeltype == LABEL_MANUAL);
2555 sgmlOpenTag(ofs, depth + 1, item_name);
2558 sgmlOpenTag(ofs, depth, style.latexname());
2564 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2567 linuxDocHandleFootnote(ofs, par, depth);
2569 while(par && par->IsDummy());
2571 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2577 // write closing SGML tags
2578 switch (style.latextype) {
2580 case LATEX_ENVIRONMENT:
2581 case LATEX_ITEM_ENVIRONMENT:
2584 sgmlCloseTag(ofs, depth, style.latexname());
2590 for (; depth > 0; --depth)
2591 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2593 if (!environment_stack[depth].empty())
2594 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2598 sgmlCloseTag(ofs, 0, top_element);
2602 // How to check for successful close
2607 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2610 string const tag = "footnote";
2612 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2613 sgmlOpenTag(os, depth + 1, tag);
2614 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2615 sgmlCloseTag(os, depth + 1, tag);
2622 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2623 int depth, int desc_on,
2624 LyXParagraph * & par)
2626 LyXParagraph * tpar = par;
2629 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2630 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2635 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2637 tpar = tpar->next();
2640 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2641 "Caption").second) {
2642 sgmlOpenTag(os, depth + 1, inner_tag);
2644 SimpleDocBookOnePar(os, extra_par, tpar,
2645 desc_on, depth + 2);
2646 sgmlCloseTag(os, depth+1, inner_tag);
2647 if (!extra_par.empty())
2654 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2657 string tag, inner_tag;
2658 string tmp_par, extra_par;
2659 bool inner_span = false;
2662 // Someone should give this enum a proper name (Lgb)
2670 SOME_ENUM last = NO_ONE;
2671 SOME_ENUM present = FOOTNOTE_LIKE;
2673 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2674 if (last == present) {
2676 if (!tmp_par.empty()) {
2679 sgmlCloseTag(os, depth + 1, inner_tag);
2680 sgmlOpenTag(os, depth + 1, inner_tag);
2687 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2689 if (!extra_par.empty()) os << extra_par;
2690 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2693 switch (par->footnotekind) {
2694 case LyXParagraph::FOOTNOTE:
2695 case LyXParagraph::ALGORITHM:
2698 present = FOOTNOTE_LIKE;
2701 case LyXParagraph::MARGIN:
2704 present = MARGIN_LIKE;
2707 case LyXParagraph::FIG:
2708 case LyXParagraph::WIDE_FIG:
2710 inner_tag = "title";
2714 case LyXParagraph::TAB:
2715 case LyXParagraph::WIDE_TAB:
2717 inner_tag = "title";
2722 sgmlOpenTag(os, depth, tag);
2723 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2724 DocBookHandleCaption(os, inner_tag, depth,
2728 sgmlOpenTag(os, depth + 1, inner_tag);
2731 // ignore all caption here, we processed them above!!!
2732 if (par->layout != textclasslist
2733 .NumberOfLayout(params.textclass,
2734 "Caption").second) {
2735 std::ostringstream ost;
2736 SimpleDocBookOnePar(ost, extra_par, par,
2737 desc_on, depth + 2);
2738 tmp_par += ost.str().c_str();
2740 tmp_par = frontStrip(strip(tmp_par));
2746 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2747 if (!extra_par.empty()) os << extra_par;
2748 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2753 // push a tag in a style stack
2754 void Buffer::push_tag(ostream & os, string const & tag,
2755 int & pos, char stack[5][3])
2757 #ifdef WITH_WARNINGS
2758 #warning Use a real stack! (Lgb)
2760 // pop all previous tags
2761 for (int j = pos; j >= 0; --j)
2762 os << "</" << stack[j] << ">";
2765 sprintf(stack[++pos], "%s", tag.c_str());
2768 for (int i = 0; i <= pos; ++i)
2769 os << "<" << stack[i] << ">";
2773 void Buffer::pop_tag(ostream & os, string const & tag,
2774 int & pos, char stack[5][3])
2776 #ifdef WITH_WARNINGS
2777 #warning Use a real stack! (Lgb)
2779 // Please, Lars, do not remove the global variable. I already
2780 // had to reintroduce it twice! (JMarc)
2781 // but...but... I'll remove it anyway. (well not quite) (Lgb)
2785 // pop all tags till specified one
2786 for (j = pos; (j >= 0) && tag != stack[j]; --j)
2787 os << "</" << stack[j] << ">";
2790 os << "</" << tag << ">";
2792 // push all tags, but the specified one
2793 for (j = j + 1; j <= pos; ++j) {
2794 os << "<" << stack[j] << ">";
2795 strcpy(stack[j - 1], stack[j]);
2799 // pop all tags till specified one
2801 for (int j = pos; (j >= 0) && tag != stack[j]; --j)
2802 os << "</" << stack[j] << ">";
2805 os << "</" << tag << ">";
2807 // push all tags, but the specified one
2808 for (int i = j + 1; i <= pos; ++i) {
2809 os << "<" << stack[i] << ">";
2810 strcpy(stack[i - 1], stack[i]);
2817 // Handle internal paragraph parsing -- layout already processed.
2819 // checks, if newcol chars should be put into this line
2820 // writes newline, if necessary.
2822 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2823 string::size_type newcol)
2826 if (colcount > lyxrc.ascii_linelen) {
2828 colcount = newcol; // assume write after this call
2833 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2834 int desc_on, int /*depth*/)
2839 LyXParagraph::size_type main_body;
2841 LyXLayout const & style = textclasslist.Style(params.textclass,
2844 char family_type = 0; // family font flag
2845 bool is_bold = false; // series font flag
2846 char shape_type = 0; // shape font flag
2847 bool is_em = false; // emphasis (italic) font flag
2849 int stack_num = -1; // style stack position
2850 // Can this be rewritten to use a std::stack, please. (Lgb)
2851 char stack[5][3]; // style stack
2852 string::size_type char_line_count = 5; // Heuristic choice ;-)
2854 if (style.labeltype != LABEL_MANUAL)
2857 main_body = par->BeginningOfMainBody();
2859 // gets paragraph main font
2861 font1 = style.labelfont;
2866 // parsing main loop
2867 for (LyXParagraph::size_type i = 0;
2868 i < par->size(); ++i) {
2880 LyXFont const font2 = par->getFont(params, i);
2882 if (font1.family() != font2.family()) {
2883 switch (family_type) {
2885 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2886 push_tag(os, "tt", stack_num, stack);
2889 else if (font2.family() == LyXFont::SANS_FAMILY) {
2890 push_tag(os, "sf", stack_num, stack);
2895 pop_tag(os, "tt", stack_num, stack);
2896 if (font2.family() == LyXFont::SANS_FAMILY) {
2897 push_tag(os, "sf", stack_num, stack);
2904 pop_tag(os, "sf", stack_num, stack);
2905 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2906 push_tag(os, "tt", stack_num, stack);
2915 if (font1.series() != font2.series()) {
2916 if (font2.series() == LyXFont::BOLD_SERIES) {
2917 push_tag(os, "bf", stack_num, stack);
2919 } else if (is_bold) {
2920 pop_tag(os, "bf", stack_num, stack);
2925 // handle italic and slanted fonts
2926 if (font1.shape() != font2.shape()) {
2927 switch (shape_type) {
2929 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2930 push_tag(os, "it", stack_num, stack);
2932 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2933 push_tag(os, "sl", stack_num, stack);
2938 pop_tag(os, "it", stack_num, stack);
2939 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2940 push_tag(os, "sl", stack_num, stack);
2947 pop_tag(os, "sl", stack_num, stack);
2948 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2949 push_tag(os, "it", stack_num, stack);
2957 if (font1.emph() != font2.emph()) {
2958 if (font2.emph() == LyXFont::ON) {
2959 push_tag(os, "em", stack_num, stack);
2962 pop_tag(os, "em", stack_num, stack);
2967 c = par->GetChar(i);
2969 if (c == LyXParagraph::META_INSET) {
2970 inset = par->GetInset(i);
2971 inset->Linuxdoc(this, os);
2974 if (font2.latex() == LyXFont::ON) {
2975 // "TeX"-Mode on == > SGML-Mode on.
2977 os << c; // see LaTeX-Generation...
2981 if (par->linuxDocConvertChar(c, sgml_string)
2982 && !style.free_spacing) { // in freespacing
2984 // non-breaking characters
2988 linux_doc_line_break(os, char_line_count, 6);
2992 linux_doc_line_break(os, char_line_count, 1);
2997 char_line_count += sgml_string.length();
3003 // needed if there is an optional argument but no contents
3004 if (main_body > 0 && main_body == par->size()) {
3008 // pop all defined Styles
3009 for (j = stack_num; j >= 0; --j) {
3010 linux_doc_line_break(os,
3012 3 + strlen(stack[j]));
3013 os << "</" << stack[j] << ">";
3016 // resets description flag correctly
3019 // <tag> not closed...
3020 linux_doc_line_break(os, char_line_count, 6);
3024 // fprintf(file, "</p>");
3030 // Print an error message.
3031 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3032 string const & message)
3034 // insert an error marker in text
3035 InsetError * new_inset = new InsetError(message);
3036 par->InsertInset(pos, new_inset);
3039 // This constant defines the maximum number of
3040 // environment layouts that can be nesteded.
3041 // The same applies for command layouts.
3042 // These values should be more than enough.
3043 // José Matos (1999/07/22)
3045 enum { MAX_NEST_LEVEL = 25};
3047 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3049 LyXParagraph * par = paragraph;
3051 niceFile = nice; // this will be used by Insetincludes.
3053 string top_element= textclasslist.LatexnameOfClass(params.textclass);
3054 // Please use a real stack.
3055 string environment_stack[MAX_NEST_LEVEL];
3056 string environment_inner[MAX_NEST_LEVEL];
3057 // Please use a real stack.
3058 string command_stack[MAX_NEST_LEVEL];
3059 bool command_flag= false;
3060 int command_depth= 0, command_base= 0, cmd_depth= 0;
3062 string item_name, command_name;
3063 string c_depth, c_params, tmps;
3065 int depth = 0; // paragraph depth
3066 LyXTextClass const & tclass =
3067 textclasslist.TextClass(params.textclass);
3069 LaTeXFeatures features(params, tclass.numLayouts());
3073 tex_code_break_column = lyxrc.ascii_linelen;
3075 //tex_code_break_column = 0;
3077 ofstream ofs(fname.c_str());
3079 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3086 string sgml_includedfiles=features.getIncludedFiles(fname);
3088 ofs << "<!doctype " << top_element
3089 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3091 if (params.preamble.empty() && sgml_includedfiles.empty())
3094 ofs << "\n [ " << params.preamble
3095 << sgml_includedfiles << " \n]>\n\n";
3098 string top = top_element;
3100 top += params.language->code();
3103 if (!params.options.empty()) {
3105 top += params.options;
3107 sgmlOpenTag(ofs, 0, top);
3109 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3110 << "\n See http://www.lyx.org/ for more information -->\n";
3113 int desc_on = 0; // description mode
3114 LyXLayout const & style =
3115 textclasslist.Style(params.textclass,
3118 // environment tag closing
3119 for (; depth > par->params.depth(); --depth) {
3120 if (environment_inner[depth] != "!-- --") {
3121 item_name= "listitem";
3122 sgmlCloseTag(ofs, command_depth + depth,
3124 if (environment_inner[depth] == "varlistentry")
3125 sgmlCloseTag(ofs, depth+command_depth,
3126 environment_inner[depth]);
3128 sgmlCloseTag(ofs, depth + command_depth,
3129 environment_stack[depth]);
3130 environment_stack[depth].erase();
3131 environment_inner[depth].erase();
3134 if (depth == par->params.depth()
3135 && environment_stack[depth] != style.latexname()
3136 && !environment_stack[depth].empty()) {
3137 if (environment_inner[depth] != "!-- --") {
3138 item_name= "listitem";
3139 sgmlCloseTag(ofs, command_depth+depth,
3141 if (environment_inner[depth] == "varlistentry")
3143 depth + command_depth,
3144 environment_inner[depth]);
3147 sgmlCloseTag(ofs, depth + command_depth,
3148 environment_stack[depth]);
3150 environment_stack[depth].erase();
3151 environment_inner[depth].erase();
3154 // Write opening SGML tags.
3155 switch (style.latextype) {
3156 case LATEX_PARAGRAPH:
3157 sgmlOpenTag(ofs, depth+command_depth, style.latexname());
3162 LinuxDocError(par, 0,
3163 _("Error : Wrong depth for "
3164 "LatexType Command.\n"));
3166 command_name = style.latexname();
3168 tmps = style.latexparam();
3169 c_params = split(tmps, c_depth,'|');
3171 cmd_depth= lyx::atoi(c_depth);
3174 if (cmd_depth<command_base) {
3175 for (int j = command_depth;
3176 j >= command_base; --j)
3177 if (!command_stack[j].empty())
3178 sgmlCloseTag(ofs, j, command_stack[j]);
3179 command_depth= command_base= cmd_depth;
3180 } else if (cmd_depth <= command_depth) {
3181 for (int j = command_depth;
3182 j >= cmd_depth; --j)
3184 if (!command_stack[j].empty())
3185 sgmlCloseTag(ofs, j, command_stack[j]);
3186 command_depth= cmd_depth;
3188 command_depth= cmd_depth;
3190 command_depth = command_base = cmd_depth;
3191 command_flag = true;
3193 command_stack[command_depth]= command_name;
3195 // treat label as a special case for
3196 // more WYSIWYM handling.
3197 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3198 Inset * inset = par->GetInset(0);
3199 Inset::Code lyx_code = inset->LyxCode();
3200 if (lyx_code == Inset::LABEL_CODE){
3201 command_name += " id=\"";
3202 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3203 command_name += "\"";
3208 sgmlOpenTag(ofs, depth + command_depth, command_name);
3209 if (c_params.empty())
3210 item_name = "title";
3212 item_name = c_params;
3213 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3216 case LATEX_ENVIRONMENT:
3217 case LATEX_ITEM_ENVIRONMENT:
3218 if (depth < par->params.depth()) {
3219 depth = par->params.depth();
3220 environment_stack[depth].erase();
3223 if (environment_stack[depth] != style.latexname()) {
3224 environment_stack[depth] = style.latexname();
3225 environment_inner[depth] = "!-- --";
3226 sgmlOpenTag(ofs, depth + command_depth,
3227 environment_stack[depth]);
3229 if (environment_inner[depth] != "!-- --") {
3230 item_name= "listitem";
3232 command_depth + depth,
3234 if (environment_inner[depth] == "varlistentry")
3236 depth + command_depth,
3237 environment_inner[depth]);
3241 if (style.latextype == LATEX_ENVIRONMENT) {
3242 if (!style.latexparam().empty()) {
3243 if(style.latexparam() == "CDATA")
3244 ofs << "<![ CDATA [";
3246 sgmlOpenTag(ofs, depth + command_depth,
3247 style.latexparam());
3252 desc_on = (style.labeltype == LABEL_MANUAL);
3255 environment_inner[depth]= "varlistentry";
3257 environment_inner[depth]= "listitem";
3259 sgmlOpenTag(ofs, depth + 1 + command_depth,
3260 environment_inner[depth]);
3264 sgmlOpenTag(ofs, depth + 1 + command_depth,
3268 sgmlOpenTag(ofs, depth + 1 + command_depth,
3273 sgmlOpenTag(ofs, depth + command_depth,
3281 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3282 depth + 1 + command_depth);
3284 DocBookHandleFootnote(ofs, par,
3285 depth + 1 + command_depth);
3286 } while(par && par->IsDummy());
3289 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3290 depth + 1 + command_depth);
3294 // write closing SGML tags
3295 switch (style.latextype) {
3297 if (c_params.empty())
3301 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3303 case LATEX_ENVIRONMENT:
3304 if (!style.latexparam().empty()) {
3305 if(style.latexparam() == "CDATA")
3308 sgmlCloseTag(ofs, depth + command_depth,
3309 style.latexparam());
3312 case LATEX_ITEM_ENVIRONMENT:
3313 if (desc_on == 1) break;
3315 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3317 case LATEX_PARAGRAPH:
3318 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3321 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3327 for (; depth >= 0; --depth) {
3328 if (!environment_stack[depth].empty()) {
3329 if (environment_inner[depth] != "!-- --") {
3330 item_name= "listitem";
3331 sgmlCloseTag(ofs, command_depth + depth,
3333 if (environment_inner[depth] == "varlistentry")
3334 sgmlCloseTag(ofs, depth + command_depth,
3335 environment_inner[depth]);
3338 sgmlCloseTag(ofs, depth + command_depth,
3339 environment_stack[depth]);
3343 for (int j = command_depth; j >= command_base; --j)
3344 if (!command_stack[j].empty())
3345 sgmlCloseTag(ofs, j, command_stack[j]);
3348 sgmlCloseTag(ofs, 0, top_element);
3351 // How to check for successful close
3355 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3356 LyXParagraph * par, int & desc_on,
3359 bool emph_flag = false;
3361 LyXLayout const & style = textclasslist.Style(params.textclass,
3364 LyXParagraph::size_type main_body;
3365 if (style.labeltype != LABEL_MANUAL)
3368 main_body = par->BeginningOfMainBody();
3370 // gets paragraph main font
3371 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3373 int char_line_count = depth;
3374 if (!style.free_spacing)
3375 for (int j = 0; j < depth; ++j)
3378 // parsing main loop
3379 for (LyXParagraph::size_type i = 0;
3380 i < par->size(); ++i) {
3381 LyXFont font2 = par->getFont(params, i);
3383 // handle <emphasis> tag
3384 if (font1.emph() != font2.emph() && i) {
3385 if (font2.emph() == LyXFont::ON) {
3389 os << "</emphasis>";
3394 char c = par->GetChar(i);
3396 if (c == LyXParagraph::META_INSET) {
3397 Inset * inset = par->GetInset(i);
3398 std::ostringstream ost;
3399 inset->DocBook(this, ost);
3400 string tmp_out = ost.str().c_str();
3403 // This code needs some explanation:
3404 // Two insets are treated specially
3405 // label if it is the first element in a command paragraph
3407 // graphics inside tables or figure floats can't go on
3408 // title (the equivalente in latex for this case is caption
3409 // and title should come first
3412 if (desc_on!= 3 || i!= 0) {
3413 if (!tmp_out.empty() && tmp_out[0] == '@') {
3415 extra += frontStrip(tmp_out, '@');
3417 os << frontStrip(tmp_out, '@');
3422 } else if (font2.latex() == LyXFont::ON) {
3423 // "TeX"-Mode on ==> SGML-Mode on.
3429 if (par->linuxDocConvertChar(c, sgml_string)
3430 && !style.free_spacing) { // in freespacing
3432 // non-breaking characters
3436 os << "\n</term><listitem><para>";
3448 // needed if there is an optional argument but no contents
3449 if (main_body > 0 && main_body == par->size()) {
3453 os << "</emphasis>";
3456 // resets description flag correctly
3459 // <term> not closed...
3467 // This should be enabled when the Chktex class is implemented. (Asger)
3468 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3469 // Other flags: -wall -v0 -x
3470 int Buffer::runChktex()
3472 if (!users->text) return 0;
3474 ProhibitInput(users);
3476 // get LaTeX-Filename
3477 string const name = getLatexName();
3478 string path = OnlyPath(filename);
3480 string const org_path = path;
3481 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3485 Path p(path); // path to LaTeX file
3486 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3488 // Remove all error insets
3489 bool const removedErrorInsets = users->removeAutoInsets();
3491 // Generate the LaTeX file if neccessary
3492 makeLaTeXFile(name, org_path, false);
3495 Chktex chktex(lyxrc.chktex_command, name, filepath);
3496 int res = chktex.run(terr); // run chktex
3499 WriteAlert(_("chktex did not work!"),
3500 _("Could not run with file:"), name);
3501 } else if (res > 0) {
3502 // Insert all errors as errors boxes
3503 users->insertErrors(terr);
3506 // if we removed error insets before we ran chktex or if we inserted
3507 // error insets after we ran chktex, this must be run:
3508 if (removedErrorInsets || res){
3510 users->fitCursor(users->text);
3518 void Buffer::validate(LaTeXFeatures & features) const
3520 LyXParagraph * par = paragraph;
3521 LyXTextClass const & tclass =
3522 textclasslist.TextClass(params.textclass);
3524 // AMS Style is at document level
3526 features.amsstyle = (params.use_amsmath ||
3527 tclass.provides(LyXTextClass::amsmath));
3530 // We don't use "lyxerr.debug" because of speed. (Asger)
3531 if (lyxerr.debugging(Debug::LATEX))
3532 lyxerr << "Paragraph: " << par << endl;
3534 // Now just follow the list of paragraphs and run
3535 // validate on each of them.
3536 par->validate(features);
3538 // and then the next paragraph
3546 // the bullet shapes are buffer level not paragraph level
3547 // so they are tested here
3548 for (int i = 0; i < 4; ++i) {
3549 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3550 int const font = params.user_defined_bullets[i].getFont();
3552 int const c = params
3553 .user_defined_bullets[i]
3560 features.latexsym = true;
3562 } else if (font == 1) {
3563 features.amssymb = true;
3564 } else if ((font >= 2 && font <= 5)) {
3565 features.pifont = true;
3570 if (lyxerr.debugging(Debug::LATEX)) {
3571 features.showStruct();
3576 void Buffer::setPaperStuff()
3578 params.papersize = BufferParams::PAPER_DEFAULT;
3579 char const c1 = params.paperpackage;
3580 if (c1 == BufferParams::PACKAGE_NONE) {
3581 char const c2 = params.papersize2;
3582 if (c2 == BufferParams::VM_PAPER_USLETTER)
3583 params.papersize = BufferParams::PAPER_USLETTER;
3584 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3585 params.papersize = BufferParams::PAPER_LEGALPAPER;
3586 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3587 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3588 else if (c2 == BufferParams::VM_PAPER_A3)
3589 params.papersize = BufferParams::PAPER_A3PAPER;
3590 else if (c2 == BufferParams::VM_PAPER_A4)
3591 params.papersize = BufferParams::PAPER_A4PAPER;
3592 else if (c2 == BufferParams::VM_PAPER_A5)
3593 params.papersize = BufferParams::PAPER_A5PAPER;
3594 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3595 (c2 == BufferParams::VM_PAPER_B5))
3596 params.papersize = BufferParams::PAPER_B5PAPER;
3597 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3598 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3599 params.papersize = BufferParams::PAPER_A4PAPER;
3603 // This function should be in Buffer because it's a buffer's property (ale)
3604 string const Buffer::getIncludeonlyList(char delim)
3607 for (inset_iterator it = inset_iterator_begin();
3608 it != inset_iterator_end(); ++it) {
3609 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3610 InsetInclude * insetinc =
3611 static_cast<InsetInclude *>(*it);
3612 if (insetinc->isIncludeOnly()) {
3615 lst += insetinc->getRelFileBaseName();
3619 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3624 vector<string> const Buffer::getLabelList()
3626 /// if this is a child document and the parent is already loaded
3627 /// Use the parent's list instead [ale990407]
3628 if (!params.parentname.empty()
3629 && bufferlist.exists(params.parentname)) {
3630 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3632 return tmp->getLabelList();
3635 vector<string> label_list;
3636 for (inset_iterator it = inset_iterator_begin();
3637 it != inset_iterator_end(); ++it) {
3638 vector<string> const l = (*it)->getLabelList();
3639 label_list.insert(label_list.end(), l.begin(), l.end());
3645 Buffer::Lists const Buffer::getLists() const
3648 LyXParagraph * par = paragraph;
3651 LyXTextClassList::size_type cap;
3652 boost::tie(found, cap) = textclasslist
3653 .NumberOfLayout(params.textclass, "Caption");
3658 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3659 if (textclasslist.Style(params.textclass,
3660 par->GetLayout()).labeltype
3661 == LABEL_SENSITIVE) {
3663 switch (par->footnotekind) {
3664 case LyXParagraph::FIG:
3665 case LyXParagraph::WIDE_FIG:
3668 case LyXParagraph::TAB:
3669 case LyXParagraph::WIDE_TAB:
3672 case LyXParagraph::ALGORITHM:
3675 case LyXParagraph::FOOTNOTE:
3676 case LyXParagraph::MARGIN:
3679 if (!type.empty()) {
3680 SingleList & item = l[type];
3682 tostr(item.size()+1) + ". " + par->String(this, false);
3683 item.push_back(TocItem(par, 0, str));
3686 } else if (!par->IsDummy()) {
3688 char const labeltype =
3689 textclasslist.Style(params.textclass,
3690 par->GetLayout()).labeltype;
3692 if (labeltype >= LABEL_COUNTER_CHAPTER
3693 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3694 // insert this into the table of contents
3695 SingleList & item = l["TOC"];
3698 textclasslist.TextClass(params.textclass).maxcounter());
3699 item.push_back(TocItem(par, depth, par->String(this, true)));
3702 // For each paragrph, traverse its insets and look for
3706 LyXParagraph::inset_iterator it =
3707 par->inset_iterator_begin();
3708 LyXParagraph::inset_iterator end =
3709 par->inset_iterator_end();
3711 for (; it != end; ++it) {
3712 if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
3714 static_cast<InsetFloat*>(*it);
3716 string const type = il->type();
3718 // Now find the caption in the float...
3719 // We now tranverse the paragraphs of
3721 LyXParagraph * tmp = il->inset->par;
3723 if (tmp->layout == cap) {
3724 SingleList & item = l[type];
3726 tostr(item.size()+1) + ". " + tmp->String(this, false);
3727 item.push_back(TocItem(tmp, 0 , str));
3734 lyxerr << "caption not found" << endl;
3749 // This is also a buffer property (ale)
3750 vector<pair<string, string> > const Buffer::getBibkeyList()
3752 /// if this is a child document and the parent is already loaded
3753 /// Use the parent's list instead [ale990412]
3754 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3755 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3757 return tmp->getBibkeyList();
3760 vector<pair<string, string> > keys;
3761 LyXParagraph * par = paragraph;
3764 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3765 par->String(this, false)));
3773 // Might be either using bibtex or a child has bibliography
3775 for (inset_iterator it = inset_iterator_begin();
3776 it != inset_iterator_end(); ++it) {
3777 // Search for Bibtex or Include inset
3778 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3779 vector<pair<string,string> > tmp =
3780 static_cast<InsetBibtex*>(*it)->getKeys(this);
3781 keys.insert(keys.end(), tmp.begin(), tmp.end());
3782 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3783 vector<pair<string,string> > const tmp =
3784 static_cast<InsetInclude*>(*it)->getKeys();
3785 keys.insert(keys.end(), tmp.begin(), tmp.end());
3794 bool Buffer::isDepClean(string const & name) const
3796 DEPCLEAN * item = dep_clean;
3797 while (item && item->master != name)
3799 if (!item) return true;
3804 void Buffer::markDepClean(string const & name)
3807 dep_clean = new DEPCLEAN;
3808 dep_clean->clean = true;
3809 dep_clean->master = name;
3810 dep_clean->next = 0;
3812 DEPCLEAN * item = dep_clean;
3813 while (item && item->master != name)
3818 item = new DEPCLEAN;
3820 item->master = name;
3827 bool Buffer::Dispatch(string const & command)
3829 // Split command string into command and argument
3831 string line = frontStrip(command);
3832 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3834 return Dispatch(lyxaction.LookupFunc(cmd), arg);
3838 bool Buffer::Dispatch(int action, string const & argument)
3840 bool dispatched = true;
3843 Exporter::Export(this, argument, false);
3853 void Buffer::resize()
3855 /// resize the BufferViews!
3861 void Buffer::resizeInsets(BufferView * bv)
3863 /// then remove all LyXText in text-insets
3864 LyXParagraph * par = paragraph;
3866 for (; par; par = par->next_) {
3867 par->resizeInsetsLyXText(bv);
3870 for (; par; par = par->next()) {
3871 par->resizeInsetsLyXText(bv);
3877 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3880 LyXParagraph * par = paragraph;
3882 par->ChangeLanguage(params, from, to);
3892 bool Buffer::isMultiLingual()
3894 LyXParagraph * par = paragraph;
3896 if (par->isMultiLingual(params))
3908 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3909 LyXParagraph::size_type pos)
3912 it = par->InsetIterator(pos);
3913 if (it == par->inset_iterator_end()) {
3924 void Buffer::inset_iterator::SetParagraph()
3927 it = par->inset_iterator_begin();
3928 if (it != par->inset_iterator_end())
3937 // We maintain an invariant that whenever par = 0 then it = 0