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 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
41 using std::lower_bound;
42 using std::upper_bound;
45 int tex_code_break_column = 72; // needs non-zero initialization. set later.
46 // this is a bad idea, but how can LyXParagraph find its buffer to get
47 // parameters? (JMarc)
48 extern BufferView * current_view;
49 extern string bibitemWidest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
78 /* table stuff -- begin*/
80 /* table stuff -- end*/
84 bibkey = 0; // ale970302
89 // This konstruktor inserts the new paragraph in a list.
90 LyXParagraph::LyXParagraph(LyXParagraph * par)
93 par->text.resize(par->text.size());
95 for (int i = 0; i < 10; ++i) setCounter(i, 0);
99 // double linked list begin
102 next->previous = this;
104 previous->next = this;
106 footnoteflag = LyXParagraph::NO_FOOTNOTE;
107 footnotekind = LyXParagraph::FOOTNOTE;
110 /* table stuff -- begin*/
112 /* table stuff -- end*/
115 id_ = paragraph_id++;
117 bibkey = 0; // ale970302
123 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
124 char footflag, char dth) const
126 LyXFont font1, font2;
131 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
133 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
135 // The beginning or the end of a footnote environment?
136 if (footflag != footnoteflag) {
137 footflag = footnoteflag;
139 os << "\n\\begin_float "
140 << string_footnotekinds[footnotekind]
143 os << "\n\\end_float ";
147 // The beginning or end of a deeper (i.e. nested) area?
150 while (depth > dth) {
151 os << "\n\\begin_deeper ";
155 while (depth < dth) {
156 os << "\n\\end_deeper ";
162 // First write the layout
164 << textclasslist.NameOfLayout(params.textclass, layout)
167 // Maybe some vertical spaces.
168 if (added_space_top.kind() != VSpace::NONE)
169 os << "\\added_space_top "
170 << added_space_top.asLyXCommand() << " ";
171 if (added_space_bottom.kind() != VSpace::NONE)
172 os << "\\added_space_bottom "
173 << added_space_bottom.asLyXCommand() << " ";
175 // Maybe the paragraph has special spacing
176 spacing.writeFile(os, true);
178 // The labelwidth string used in lists.
179 if (!labelwidthstring.empty())
180 os << "\\labelwidthstring "
181 << labelwidthstring << '\n';
183 // Lines above or below?
187 os << "\\line_bottom ";
189 // Pagebreaks above or below?
191 os << "\\pagebreak_top ";
192 if (pagebreak_bottom)
193 os << "\\pagebreak_bottom ";
195 // Start of appendix?
196 if (start_of_appendix)
197 os << "\\start_of_appendix ";
204 if (align != LYX_ALIGN_LAYOUT) {
206 case LYX_ALIGN_LEFT: h = 1; break;
207 case LYX_ALIGN_RIGHT: h = 2; break;
208 case LYX_ALIGN_CENTER: h = 3; break;
209 default: h = 0; break;
211 os << "\\align " << string_align[h] << " ";
213 if (pextra_type != PEXTRA_NONE) {
214 os << "\\pextra_type " << pextra_type;
215 if (pextra_type == PEXTRA_MINIPAGE) {
216 os << " \\pextra_alignment "
219 os << " \\pextra_hfill "
221 if (pextra_start_minipage)
222 os << " \\pextra_start_minipage "
223 << pextra_start_minipage;
225 if (!pextra_width.empty()) {
226 os << " \\pextra_width "
227 << VSpace(pextra_width).asLyXCommand();
228 } else if (!pextra_widthp.empty()) {
229 os << " \\pextra_widthp "
235 // Dummy layout. This means that a footnote ended.
236 os << "\n\\end_float ";
237 footflag = LyXParagraph::NO_FOOTNOTE;
240 // It might be a table.
242 os << "\\LyXTable\n";
250 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
253 for (size_type i = 0; i < size(); ++i) {
259 // Write font changes
260 font2 = GetFontSettings(params, i);
261 if (font2 != font1) {
262 font2.lyxWriteChanges(font1, os);
271 Inset const * inset = GetInset(i);
273 if (inset->DirectWrite()) {
274 // international char, let it write
275 // code directly so it's shorter in
279 os << "\n\\begin_inset ";
281 os << "\n\\end_inset \n\n";
287 os << "\n\\newline \n";
291 os << "\n\\hfill \n";
295 os << "\n\\backslash \n";
299 if (i + 1 < size() && GetChar(i + 1) == ' ') {
306 if ((column > 70 && c == ' ')
311 // this check is to amend a bug. LyX sometimes
312 // inserts '\0' this could cause problems.
316 lyxerr << "ERROR (LyXParagraph::writeFile):"
317 " NULL char in structure." << endl;
323 // now write the next paragraph
325 next->writeFile(os, params, footflag, dth);
329 void LyXParagraph::validate(LaTeXFeatures & features) const
331 BufferParams const & params = features.bufferParams();
333 // this will be useful later
334 LyXLayout const & layout =
335 textclasslist.Style(params.textclass,
339 if (line_top || line_bottom)
340 features.lyxline = true;
341 if (!spacing.isDefault())
342 features.setspace = true;
345 features.layout[GetLayout()] = true;
348 Language const * doc_language = params.language_info;
350 for (FontList::const_iterator cit = fontlist.begin();
351 cit != fontlist.end(); ++cit) {
352 if ((*cit).font.noun() == LyXFont::ON) {
353 lyxerr[Debug::LATEX] << "font.noun: "
354 << (*cit).font.noun()
356 features.noun = true;
357 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
358 << (*cit).font.stateText(0)
361 switch ((*cit).font.color()) {
363 case LColor::inherit:
367 features.color = true;
368 lyxerr[Debug::LATEX] << "Color enabled. Font: "
369 << (*cit).font.stateText(0)
373 Language const * language = (*cit).font.language();
374 if (language != doc_language) {
375 features.UsedLanguages.insert(language);
376 lyxerr[Debug::LATEX] << "Found language "
377 << language->lang << endl;
382 // This is not efficient. I plan to use the code above, after I
383 // change the fontlist handling.
384 for (size_type i = 0; i < size(); ++i) {
385 Language const * language =
386 GetFontSettings(params, i).language();
387 if (language != doc_language)
388 features.UsedLanguages.insert(language);
392 for (InsetList::const_iterator cit = insetlist.begin();
393 cit != insetlist.end(); ++cit) {
395 (*cit).inset->Validate(features);
398 if (table && table->IsLongTable())
399 features.longtable = true;
400 if (pextra_type == PEXTRA_INDENT)
401 features.LyXParagraphIndent = true;
402 if (pextra_type == PEXTRA_FLOATFLT)
403 features.floatflt = true;
404 if (layout.needprotect
405 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
406 features.NeedLyXFootnoteCode = true;
407 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
408 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
409 features.NeedLyXMinipageIndent = true;
410 if (table && table->NeedRotating())
411 features.rotating = true;
412 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
413 features.algorithm = true;
417 // First few functions needed for cut and paste and paragraph breaking.
418 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
419 LyXParagraph::size_type pos) const
421 minibuffer_char = GetChar(pos);
422 minibuffer_font = GetFontSettings(bparams, pos);
423 minibuffer_inset = 0;
424 if (minibuffer_char == LyXParagraph::META_INSET) {
426 minibuffer_inset = GetInset(pos)->Clone();
428 minibuffer_inset = 0;
429 minibuffer_char = ' ';
430 // This reflects what GetInset() does (ARRae)
436 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
437 LyXParagraph::size_type pos)
439 minibuffer_char = GetChar(pos);
440 minibuffer_font = GetFontSettings(bparams, pos);
441 minibuffer_inset = 0;
442 if (minibuffer_char == LyXParagraph::META_INSET) {
444 minibuffer_inset = GetInset(pos);
445 // This is a little hack since I want exactly
446 // the inset, not just a clone. Otherwise
447 // the inset would be deleted when calling Erase(pos)
449 InsetList::iterator it = lower_bound(insetlist.begin(),
452 if (it != insetlist.end() && (*it).pos == pos)
455 minibuffer_inset = 0;
456 minibuffer_char = ' ';
457 // This reflects what GetInset() does (ARRae)
462 // Erase(pos); now the caller is responsible for that.
466 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
468 if ((minibuffer_char == LyXParagraph::META_INSET) &&
469 !InsertInsetAllowed(minibuffer_inset))
471 InsertChar(pos, minibuffer_char);
472 SetFont(pos, minibuffer_font);
473 if (minibuffer_char == LyXParagraph::META_INSET)
474 InsertInset(pos, minibuffer_inset);
482 void LyXParagraph::Clear()
487 pagebreak_top = false;
488 pagebreak_bottom = false;
490 added_space_top = VSpace(VSpace::NONE);
491 added_space_bottom = VSpace(VSpace::NONE);
492 spacing.set(Spacing::Default);
494 align = LYX_ALIGN_LAYOUT;
498 pextra_type = PEXTRA_NONE;
499 pextra_width.erase();
500 pextra_widthp.erase();
501 pextra_alignment = MINIPAGE_ALIGN_TOP;
502 pextra_hfill = false;
503 pextra_start_minipage = false;
506 labelwidthstring.erase();
510 start_of_appendix = false;
514 // the destructor removes the new paragraph from the list
515 LyXParagraph::~LyXParagraph()
518 previous->next = next;
520 next->previous = previous;
522 for (InsetList::iterator it = insetlist.begin();
523 it != insetlist.end(); ++it) {
527 /* table stuff -- begin*/
529 /* table stuff -- end*/
535 //lyxerr << "LyXParagraph::paragraph_id = "
536 // << LyXParagraph::paragraph_id << endl;
540 void LyXParagraph::Erase(LyXParagraph::size_type pos)
542 // > because last is the next unused position, and you can
543 // use it if you want
545 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
546 NextAfterFootnote()->Erase(pos - text.size() - 1);
548 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
549 "position does not exist." << endl;
552 if (pos < size()) { // last is free for insertation, but should be empty
553 // if it is an inset, delete the inset entry
554 if (text[pos] == LyXParagraph::META_INSET) {
556 InsetList::iterator it = lower_bound(insetlist.begin(),
559 if (it != insetlist.end() && (*it).pos == pos) {
564 text.erase(text.begin() + pos);
565 // Erase entries in the tables.
566 for (FontList::iterator it = fontlist.begin();
567 it != fontlist.end(); ++it) {
568 if (pos >= (*it).pos && pos <= (*it).pos_end) {
569 if ((*it).pos == (*it).pos_end) {
570 // If it is a multi-character font
571 // entry, we just make it smaller
572 // (see update below), otherwise we
579 // Update all other entries.
580 for (FontList::iterator it = fontlist.begin();
581 it != fontlist.end(); ++it) {
584 if ((*it).pos_end >= pos)
588 // Update the inset table.
589 for (InsetList::iterator it = upper_bound(insetlist.begin(),
592 it != insetlist.end(); ++it)
595 lyxerr << "ERROR (LyXParagraph::Erase): "
596 "can't erase non-existant char." << endl;
601 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
603 // > because last is the next unused position, and you can
604 // use it if you want
607 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
608 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
611 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
612 "position does not exist." << endl;
615 text.insert(text.begin() + pos, c);
616 // Update the font table.
617 for (FontList::iterator it = fontlist.begin();
618 it != fontlist.end(); ++it) {
619 if ((*it).pos >= pos)
621 if ((*it).pos_end >= pos)
625 // Update the inset table.
626 for (InsetList::iterator it = lower_bound(insetlist.begin(),
629 it != insetlist.end(); ++it)
634 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
637 // > because last is the next unused position, and you can
638 // use it if you want
641 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
643 ->InsertInset(pos - text.size() - 1, inset);
645 lyxerr << "ERROR (LyXParagraph::InsertInset): "
646 "position does not exist: " << pos << endl;
649 if (text[pos] != LyXParagraph::META_INSET) {
650 lyxerr << "ERROR (LyXParagraph::InsertInset): "
651 "there is no LyXParagraph::META_INSET" << endl;
656 // Add a new entry in the inset table.
657 InsetList::iterator it = lower_bound(insetlist.begin(),
660 if (it != insetlist.end() && (*it).pos == pos)
661 lyxerr << "ERROR (LyXParagraph::InsertInset): "
662 "there is an inset in position: " << pos << endl;
664 insetlist.insert(it, InsetTable(pos,inset));
666 inset->setOwner(inset_owner);
671 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
674 return inset_owner->InsertInsetAllowed(inset);
679 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
683 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
684 return NextAfterFootnote()
685 ->GetInset(pos - text.size() - 1);
687 lyxerr << "ERROR (LyXParagraph::GetInset): "
688 "position does not exist: "
694 InsetList::iterator it = lower_bound(insetlist.begin(),
697 if (it != insetlist.end() && (*it).pos == pos)
700 lyxerr << "ERROR (LyXParagraph::GetInset): "
701 "Inset does not exist: " << pos << endl;
702 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
703 // Did this commenting out introduce a bug? So far I have not
704 // see any, please enlighten me. (Lgb)
705 // My guess is that since the inset does not exist, we might
706 // as well replace it with a space to prevent craches. (Asger)
711 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
715 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
716 return NextAfterFootnote()
717 ->GetInset(pos - text.size() - 1);
719 lyxerr << "ERROR (LyXParagraph::GetInset): "
720 "position does not exist: "
726 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
729 if (cit != insetlist.end() && (*cit).pos == pos)
732 lyxerr << "ERROR (LyXParagraph::GetInset): "
733 "Inset does not exist: " << pos << endl;
734 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
735 // Did this commenting out introduce a bug? So far I have not
736 // see any, please enlighten me. (Lgb)
737 // My guess is that since the inset does not exist, we might
738 // as well replace it with a space to prevent craches. (Asger)
743 // Gets uninstantiated font setting at position.
744 // Optimized after profiling. (Asger)
745 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
746 LyXParagraph::size_type pos) const
749 #ifdef SORTED_FONT_LIST
750 for (FontList::const_iterator cit = fontlist.begin();
751 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
752 if (pos >= (*cit).pos)
755 for (FontList::const_iterator cit = fontlist.begin();
756 cit != fontlist.end(); ++cit)
757 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
761 // > because last is the next unused position, and you can
762 // use it if you want
763 else if (pos > size()) {
765 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
766 return NextAfterFootnote()
767 ->GetFontSettings(bparams,
768 pos - text.size() - 1);
770 // Why is it an error to ask for the font of a
771 // position that does not exist? Would it be
772 // enough for this to be enabled on debug?
773 // We want strict error checking, but it's ok to only
774 // have it when debugging. (Asger)
775 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
776 "position does not exist. "
777 << pos << " (" << static_cast<int>(pos)
780 } else if (pos > 0) {
781 return GetFontSettings(bparams, pos - 1);
782 } else // pos = size() = 0
783 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
785 return LyXFont(LyXFont::ALL_INHERIT);
788 // Gets uninstantiated font setting at position 0
789 LyXFont LyXParagraph::GetFirstFontSettings() const
792 #ifdef SORTED_FONT_LIST
793 if (!fontlist.empty() && fontlist.front().pos == 0)
794 return fontlist.front().font;
796 for (FontList::const_iterator cit = fontlist.begin();
797 cit != fontlist.end(); ++cit)
798 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
801 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
802 return NextAfterFootnote()->GetFirstFontSettings();
803 return LyXFont(LyXFont::ALL_INHERIT);
807 // Gets the fully instantiated font at a given position in a paragraph
808 // This is basically the same function as LyXText::GetFont() in text2.C.
809 // The difference is that this one is used for generating the LaTeX file,
810 // and thus cosmetic "improvements" are disallowed: This has to deliver
811 // the true picture of the buffer. (Asger)
812 // If position is -1, we get the layout font of the paragraph.
813 // If position is -2, we get the font of the manual label of the paragraph.
814 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
815 LyXParagraph::size_type pos) const
818 LyXLayout const & layout =
819 textclasslist.Style(bparams.textclass,
821 LyXParagraph::size_type main_body = 0;
822 if (layout.labeltype == LABEL_MANUAL)
823 main_body = BeginningOfMainBody();
828 layoutfont = layout.labelfont;
830 layoutfont = layout.font;
831 tmpfont = GetFontSettings(bparams, pos);
832 tmpfont.realize(layoutfont);
834 // process layoutfont for pos == -1 and labelfont for pos < -1
836 tmpfont = layout.font;
838 tmpfont = layout.labelfont;
839 tmpfont.setLanguage(getParLanguage(bparams));
842 // check for environment font information
843 char par_depth = GetDepth();
844 LyXParagraph const * par = this;
845 while (par && par_depth && !tmpfont.resolved()) {
846 par = par->DepthHook(par_depth - 1);
848 tmpfont.realize(textclasslist.
849 Style(bparams.textclass,
850 par->GetLayout()).font);
851 par_depth = par->GetDepth();
855 tmpfont.realize(textclasslist
856 .TextClass(bparams.textclass)
862 /// Returns the height of the highest font in range
864 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
865 LyXParagraph::size_type endpos) const
867 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
868 for (FontList::const_iterator cit = fontlist.begin();
869 cit != fontlist.end(); ++cit) {
870 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
871 LyXFont::FONT_SIZE size = (*cit).font.size();
872 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
880 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
887 // > because last is the next unused position, and you can
888 // use it if you want
889 else if (pos > size()) {
890 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
891 return NextAfterFootnote()
892 ->GetChar(pos - text.size() - 1);
894 lyxerr << "ERROR (LyXParagraph::GetChar): "
895 "position does not exist."
896 << pos << " (" << static_cast<int>(pos)
898 // Assert(false); // This triggers sometimes...
903 // We should have a footnote environment.
904 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
905 // Notice that LyX does request the
906 // last char from time to time. (Asger)
907 //lyxerr << "ERROR (LyXParagraph::GetChar): "
908 // "expected footnote." << endl;
911 switch (next->footnotekind) {
912 case LyXParagraph::FOOTNOTE:
913 return LyXParagraph::META_FOOTNOTE;
914 case LyXParagraph::MARGIN:
915 return LyXParagraph::META_MARGIN;
916 case LyXParagraph::FIG:
917 case LyXParagraph::WIDE_FIG:
918 return LyXParagraph::META_FIG;
919 case LyXParagraph::TAB:
920 case LyXParagraph::WIDE_TAB:
921 return LyXParagraph::META_TAB;
922 case LyXParagraph::ALGORITHM:
923 return LyXParagraph::META_ALGORITHM;
925 return '\0'; // to shut up gcc
930 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
937 // > because last is the next unused position, and you can
938 // use it if you want
939 else if (pos > size()) {
940 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
941 return NextAfterFootnote()
942 ->GetChar(pos - text.size() - 1);
944 lyxerr << "ERROR (LyXParagraph::GetChar const): "
945 "position does not exist."
946 << pos << " (" << static_cast<int>(pos)
952 // We should have a footnote environment.
953 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
954 // Notice that LyX does request the
955 // last char from time to time. (Asger)
956 //lyxerr << "ERROR (LyXParagraph::GetChar): "
957 // "expected footnote." << endl;
960 switch (next->footnotekind) {
961 case LyXParagraph::FOOTNOTE:
962 return LyXParagraph::META_FOOTNOTE;
963 case LyXParagraph::MARGIN:
964 return LyXParagraph::META_MARGIN;
965 case LyXParagraph::FIG:
966 case LyXParagraph::WIDE_FIG:
967 return LyXParagraph::META_FIG;
968 case LyXParagraph::TAB:
969 case LyXParagraph::WIDE_TAB:
970 return LyXParagraph::META_TAB;
971 case LyXParagraph::ALGORITHM:
972 return LyXParagraph::META_ALGORITHM;
974 return '\0'; // to shut up gcc
979 // return an string of the current word, and the end of the word in lastpos.
980 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
984 // the current word is defined as starting at the first character
985 // from the immediate left of lastpospos which meets the definition
986 // of IsLetter(), continuing to the last character to the right
987 // of this meeting IsLetter.
993 // move back until we have a letter
995 //there's no real reason to have firstpos & lastpos as
996 //separate variables as this is written, but maybe someon
997 // will want to return firstpos in the future.
999 //since someone might have typed a punctuation first
1000 int firstpos = lastpos;
1002 while ((firstpos >= 0) && !IsLetter(firstpos))
1005 // now find the beginning by looking for a nonletter
1007 while ((firstpos>= 0) && IsLetter(firstpos))
1010 // the above is now pointing to the preceeding non-letter
1014 // so copy characters into theword until we get a nonletter
1015 // note that this can easily exceed lastpos, wich means
1016 // that if used in the middle of a word, the whole word
1019 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1026 LyXParagraph::size_type LyXParagraph::Last() const
1028 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1029 return text.size() + NextAfterFootnote()->Last() + 1;
1030 // the 1 is the symbol
1037 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1039 // > because last is the next unused position, and you can
1040 // use it if you want
1043 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1044 return NextAfterFootnote()
1045 ->ParFromPos(pos - text.size() - 1);
1047 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1048 "position does not exist." << endl;
1055 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1057 // > because last is the next unused position, and you can
1058 // use it if you want
1061 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1062 return NextAfterFootnote()
1063 ->PositionInParFromPos(pos - text.size() - 1);
1066 "ERROR (LyXParagraph::PositionInParFromPos): "
1067 "position does not exist." << endl;
1075 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1076 LyXFont const & font)
1078 // > because last is the next unused position, and you can
1079 // use it if you want
1082 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1083 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1086 lyxerr << "ERROR (LyXParagraph::SetFont): "
1087 "position does not exist." << endl;
1091 LyXFont patternfont(LyXFont::ALL_INHERIT);
1093 // First, reduce font against layout/label font
1094 // Update: The SetCharFont() routine in text2.C already
1095 // reduces font, so we don't need to do that here. (Asger)
1096 // No need to simplify this because it will disappear
1097 // in a new kernel. (Asger)
1098 // Next search font table
1099 FontList::iterator tmp = fontlist.begin();
1100 for (; tmp != fontlist.end(); ++tmp) {
1101 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1105 if (tmp == fontlist.end()) { // !found
1106 // if we did not find a font entry, but if the font at hand
1107 // is the same as default, we just forget it
1108 if (font == patternfont) return;
1110 // ok, we did not find a font entry. But maybe there is exactly
1111 // the needed font ientry one position left
1112 FontList::iterator tmp2 = fontlist.begin();
1113 for (; tmp2 != fontlist.end(); ++tmp2) {
1114 if (pos - 1 >= (*tmp2).pos
1115 && pos - 1 <= (*tmp2).pos_end)
1118 if (tmp2 != fontlist.end()) {
1119 // ok there is one, maybe it is exactly
1121 if ((*tmp2).font == font) {
1122 // put the position under the font
1127 // Add a new entry in the
1128 // fontlist for the position
1132 ft.font = font; // or patternfont
1133 // It seems that using font instead of patternfont here
1134 // fixes all the problems. This also surfaces a "bug" in
1136 fontlist.insert(fontlist.begin(), ft);
1137 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1139 // more than one character
1140 if (pos == (*tmp).pos) {
1141 // maybe we should enlarge the left fonttable
1142 FontList::iterator tmp2 = fontlist.begin();
1143 for (; tmp2 != fontlist.end(); ++tmp2) {
1144 if (pos - 1 >= (*tmp2).pos
1145 && pos - 1 <= (*tmp2).pos_end)
1148 // Is there is one, and is it exactly
1150 if (tmp2 != fontlist.end() &&
1151 (*tmp2).font == font) {
1152 // Put the position under the font
1158 // Add a new entry in the
1159 // fontlist for the position
1162 ft.pos_end = (*tmp).pos_end;
1163 ft.font = (*tmp).font;
1164 (*tmp).pos_end = pos;
1166 fontlist.insert(fontlist.begin(), ft);
1167 } else if (pos == (*tmp).pos_end) {
1168 // Add a new entry in the
1169 // fontlist for the position
1171 ft.pos = (*tmp).pos;
1172 ft.pos_end = (*tmp).pos_end - 1;
1173 ft.font = (*tmp).font;
1174 (*tmp).pos = (*tmp).pos_end;
1176 fontlist.insert(fontlist.begin(), ft);
1178 // Add a new entry in the
1179 // fontlist for the position
1181 ft.pos = (*tmp).pos;
1182 ft.pos_end = pos - 1;
1183 ft.font = (*tmp).font;
1187 ft2.pos_end = (*tmp).pos_end;
1188 ft2.font = (*tmp).font;
1191 (*tmp).pos_end = pos;
1194 fontlist.insert(fontlist.begin(), ft);
1195 fontlist.insert(fontlist.begin(), ft2);
1203 // This function is able to hide closed footnotes.
1204 LyXParagraph * LyXParagraph::Next()
1206 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1207 LyXParagraph * tmp = next;
1209 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1211 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1212 return tmp->Next(); /* there can be more than one
1213 footnote in a logical
1216 return next; // This should never happen!
1222 LyXParagraph * LyXParagraph::NextAfterFootnote()
1224 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1225 LyXParagraph * tmp = next;
1226 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1228 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1229 return tmp; /* there can be more than one footnote
1230 in a logical paragraph */
1232 return next; // This should never happen!
1238 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1240 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1241 LyXParagraph * tmp = next;
1242 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1244 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1245 return tmp; /* there can be more than one footnote
1246 in a logical paragraph */
1248 return next; // This should never happen!
1254 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1257 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1259 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 tmp = tmp->previous;
1261 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1262 return tmp; /* there can be more than one footnote
1263 in a logical paragraph */
1265 return previous; // This should never happen!
1271 LyXParagraph * LyXParagraph::LastPhysicalPar()
1273 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1276 LyXParagraph * tmp = this;
1278 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1279 tmp = tmp->NextAfterFootnote();
1284 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1286 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1289 LyXParagraph const * tmp = this;
1291 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1292 tmp = tmp->NextAfterFootnote();
1297 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1301 LyXParagraph * tmppar = this;
1305 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1306 tmppar = tmppar->previous;
1315 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1319 LyXParagraph const * tmppar = this;
1323 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1324 tmppar = tmppar->previous;
1333 // This function is able to hide closed footnotes.
1334 LyXParagraph * LyXParagraph::Previous()
1336 LyXParagraph * tmp = previous;
1341 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1342 tmp = tmp->previous;
1344 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1345 tmp = tmp->previous;
1346 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1347 return tmp->next->Previous();
1356 // This function is able to hide closed footnotes.
1357 LyXParagraph const * LyXParagraph::Previous() const
1359 LyXParagraph * tmp = previous;
1364 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1365 tmp = tmp->previous;
1367 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1368 tmp = tmp->previous;
1369 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1370 return tmp->next->Previous();
1379 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1380 LyXParagraph::size_type pos,
1383 size_type i, j, pos_end, pos_first;
1384 // create a new paragraph
1385 LyXParagraph * par = ParFromPos(pos);
1386 LyXParagraph * firstpar = FirstPhysicalPar();
1388 LyXParagraph * tmp = new LyXParagraph(par);
1390 tmp->footnoteflag = footnoteflag;
1391 tmp->footnotekind = footnotekind;
1393 // this is an idea for a more userfriendly layout handling, I will
1394 // see what the users say
1396 // layout stays the same with latex-environments
1398 tmp->SetOnlyLayout(bparams, firstpar->layout);
1399 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1402 if (Last() > pos || !Last() || flag == 2) {
1403 tmp->SetOnlyLayout(bparams, firstpar->layout);
1404 tmp->align = firstpar->align;
1405 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1407 tmp->line_bottom = firstpar->line_bottom;
1408 firstpar->line_bottom = false;
1409 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1410 firstpar->pagebreak_bottom = false;
1411 tmp->added_space_bottom = firstpar->added_space_bottom;
1412 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1414 tmp->depth = firstpar->depth;
1415 tmp->noindent = firstpar->noindent;
1417 // copy everything behind the break-position
1418 // to the new paragraph
1420 while (ParFromPos(pos_first) != par)
1423 pos_end = pos_first + par->text.size() - 1;
1425 for (i = j = pos; i <= pos_end; ++i) {
1426 par->CutIntoMinibuffer(bparams, i - pos_first);
1427 if (tmp->InsertFromMinibuffer(j - pos))
1430 tmp->text.resize(tmp->text.size());
1431 for (i = pos_end; i >= pos; --i)
1432 par->Erase(i - pos_first);
1434 par->text.resize(par->text.size());
1437 // just an idea of me
1439 tmp->line_top = firstpar->line_top;
1440 tmp->pagebreak_top = firstpar->pagebreak_top;
1441 tmp->added_space_top = firstpar->added_space_top;
1442 tmp->bibkey = firstpar->bibkey;
1444 // layout stays the same with latex-environments
1446 firstpar->SetOnlyLayout(bparams, tmp->layout);
1447 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1448 firstpar->depth = tmp->depth;
1454 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1456 par = par->FirstPhysicalPar();
1457 footnoteflag = par->footnoteflag;
1458 footnotekind = par->footnotekind;
1460 layout = par->layout;
1461 align = par-> align;
1462 SetLabelWidthString(par->labelwidthstring);
1464 line_bottom = par->line_bottom;
1465 pagebreak_bottom = par->pagebreak_bottom;
1466 added_space_bottom = par->added_space_bottom;
1468 line_top = par->line_top;
1469 pagebreak_top = par->pagebreak_top;
1470 added_space_top = par->added_space_top;
1472 spacing = par->spacing;
1474 pextra_type = par->pextra_type;
1475 pextra_width = par->pextra_width;
1476 pextra_widthp = par->pextra_widthp;
1477 pextra_alignment = par->pextra_alignment;
1478 pextra_hfill = par->pextra_hfill;
1479 pextra_start_minipage = par->pextra_start_minipage;
1481 noindent = par->noindent;
1486 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1488 LyXParagraph * tmppar = this;
1491 && tmppar->previous->footnoteflag ==
1492 LyXParagraph::CLOSED_FOOTNOTE)
1493 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1494 tmppar = tmppar->previous;
1497 return this; // This should never happen!
1502 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1504 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1508 if (!IsDummy() && !table){
1510 && (IsNewline(0) || IsLineSeparator(0))){
1519 LyXParagraph * LyXParagraph::Clone() const
1521 // create a new paragraph
1522 LyXParagraph * result = new LyXParagraph;
1524 result->MakeSameLayout(this);
1526 // this is because of the dummy layout of the paragraphs that
1528 result->layout = layout;
1531 /* table stuff -- begin*/
1533 result->table = table->Clone();
1536 /* table stuff -- end*/
1538 result->inset_owner = inset_owner;
1541 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1544 // copy everything behind the break-position to the new paragraph
1546 result->text = text;
1547 result->fontlist = fontlist;
1548 result->insetlist = insetlist;
1549 for (InsetList::iterator it = result->insetlist.begin();
1550 it != result->insetlist.end(); ++it)
1551 (*it).inset = (*it).inset->Clone();
1556 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1558 par = par->FirstPhysicalPar();
1561 par->footnoteflag == footnoteflag &&
1562 par->footnotekind == footnotekind &&
1564 par->layout == layout &&
1566 par->align == align &&
1568 par->line_bottom == line_bottom &&
1569 par->pagebreak_bottom == pagebreak_bottom &&
1570 par->added_space_bottom == added_space_bottom &&
1572 par->line_top == line_top &&
1573 par->pagebreak_top == pagebreak_top &&
1574 par->added_space_top == added_space_top &&
1576 par->spacing == spacing &&
1578 par->pextra_type == pextra_type &&
1579 par->pextra_width == pextra_width &&
1580 par->pextra_widthp == pextra_widthp &&
1581 par->pextra_alignment == pextra_alignment &&
1582 par->pextra_hfill == pextra_hfill &&
1583 par->pextra_start_minipage == pextra_start_minipage &&
1585 par->table == table && // what means: NO TABLE AT ALL
1588 par->noindent == noindent &&
1589 par->depth == depth);
1593 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1594 LyXParagraph::size_type pos)
1596 // create a new paragraph
1597 LyXParagraph * par = ParFromPos(pos);
1599 LyXParagraph * tmp = new LyXParagraph(par);
1601 tmp->MakeSameLayout(par);
1603 // When can pos < Last()?
1604 // I guess pos == Last() is possible.
1606 // copy everything behind the break-position to the new
1608 size_type pos_first = 0;
1609 while (ParFromPos(pos_first) != par)
1611 size_type pos_end = pos_first + par->text.size() - 1;
1614 for (i = j = pos; i <= pos_end; ++i) {
1615 par->CutIntoMinibuffer(bparams, i - pos_first);
1616 if (tmp->InsertFromMinibuffer(j - pos))
1619 tmp->text.resize(tmp->text.size());
1620 for (size_type i = pos_end; i >= pos; --i)
1621 par->Erase(i - pos_first);
1623 par->text.resize(par->text.size());
1628 // Be carefull, this does not make any check at all.
1629 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1631 // copy the next paragraph to this one
1632 LyXParagraph * the_next = Next();
1634 LyXParagraph * firstpar = FirstPhysicalPar();
1636 // first the DTP-stuff
1637 firstpar->line_bottom = the_next->line_bottom;
1638 firstpar->added_space_bottom = the_next->added_space_bottom;
1639 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1641 size_type pos_end = the_next->text.size() - 1;
1642 size_type pos_insert = Last();
1644 // ok, now copy the paragraph
1646 for (i = j = 0; i <= pos_end; ++i) {
1647 the_next->CutIntoMinibuffer(bparams, i);
1648 if (InsertFromMinibuffer(pos_insert + j))
1652 // delete the next paragraph
1653 LyXParagraph *ppar = the_next->previous;
1654 LyXParagraph *npar = the_next->next;
1660 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1662 LyXParagraph * par = ParFromPos(pos);
1664 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1665 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1671 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1673 LyXParagraph * par = ParFromPos(pos);
1675 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1676 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1681 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1683 LyXParagraph const * par = this;
1684 int par_depth = GetDepth();
1686 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1688 textclasslist.Style(bparams.textclass,
1689 layout).endlabeltype;
1690 if (endlabeltype != END_LABEL_NO_LABEL) {
1691 LyXParagraph const * last = this;
1692 if( footnoteflag == NO_FOOTNOTE)
1693 last = LastPhysicalPar();
1694 else if (next->footnoteflag == NO_FOOTNOTE)
1695 return endlabeltype;
1697 if (!last || !last->next)
1698 return endlabeltype;
1700 int next_depth = last->next->GetDepth();
1701 if (par_depth > next_depth ||
1702 (par_depth == next_depth && layout != last->next->GetLayout() ))
1703 return endlabeltype;
1708 par = par->DepthHook(par_depth - 1);
1710 par_depth = par->GetDepth();
1712 return END_LABEL_NO_LABEL;
1716 LyXTextClass::size_type LyXParagraph::GetLayout() const
1718 return FirstPhysicalPar()->layout;
1722 char LyXParagraph::GetDepth() const
1724 return FirstPhysicalPar()->depth;
1728 char LyXParagraph::GetAlign() const
1730 return FirstPhysicalPar()->align;
1734 string LyXParagraph::GetLabelstring() const
1736 return FirstPhysicalPar()->labelstring;
1740 int LyXParagraph::GetFirstCounter(int i) const
1742 return FirstPhysicalPar()->counter_[i];
1746 // the next two functions are for the manual labels
1747 string LyXParagraph::GetLabelWidthString() const
1749 if (!FirstPhysicalPar()->labelwidthstring.empty())
1750 return FirstPhysicalPar()->labelwidthstring;
1752 return _("Senseless with this layout!");
1756 void LyXParagraph::SetLabelWidthString(string const & s)
1758 LyXParagraph * par = FirstPhysicalPar();
1760 par->labelwidthstring = s;
1764 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1765 LyXTextClass::size_type new_layout)
1767 LyXParagraph * par = FirstPhysicalPar();
1768 LyXParagraph * ppar = 0;
1769 LyXParagraph * npar = 0;
1771 par->layout = new_layout;
1773 /* table stuff -- begin*/
1776 /* table stuff -- end*/
1778 if (par->pextra_type == PEXTRA_NONE) {
1779 if (par->Previous()) {
1780 ppar = par->Previous()->FirstPhysicalPar();
1783 && (ppar->depth > par->depth))
1784 ppar = ppar->Previous()->FirstPhysicalPar();
1787 npar = par->Next()->NextAfterFootnote();
1790 && (npar->depth > par->depth))
1791 npar = npar->Next()->NextAfterFootnote();
1793 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1795 p1 = ppar->pextra_width,
1796 p2 = ppar->pextra_widthp;
1797 ppar->SetPExtraType(bparams, ppar->pextra_type,
1798 p1.c_str(), p2.c_str());
1800 if ((par->pextra_type == PEXTRA_NONE) &&
1801 npar && (npar->pextra_type != PEXTRA_NONE)) {
1803 p1 = npar->pextra_width,
1804 p2 = npar->pextra_widthp;
1805 npar->SetPExtraType(bparams, npar->pextra_type,
1806 p1.c_str(), p2.c_str());
1812 void LyXParagraph::SetLayout(BufferParams const & bparams,
1813 LyXTextClass::size_type new_layout)
1816 * par = FirstPhysicalPar(),
1820 par->layout = new_layout;
1821 par->labelwidthstring.erase();
1822 par->align = LYX_ALIGN_LAYOUT;
1823 par->added_space_top = VSpace(VSpace::NONE);
1824 par->added_space_bottom = VSpace(VSpace::NONE);
1825 par->spacing.set(Spacing::Default);
1828 /* table stuff -- begin*/
1831 /* table stuff -- end*/
1833 if (par->pextra_type == PEXTRA_NONE) {
1834 if (par->Previous()) {
1835 ppar = par->Previous()->FirstPhysicalPar();
1838 && (ppar->depth > par->depth))
1839 ppar = ppar->Previous()->FirstPhysicalPar();
1842 npar = par->Next()->NextAfterFootnote();
1845 && (npar->depth > par->depth))
1846 npar = npar->Next()->NextAfterFootnote();
1848 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1850 p1 = ppar->pextra_width,
1851 p2 = ppar->pextra_widthp;
1852 ppar->SetPExtraType(bparams, ppar->pextra_type,
1853 p1.c_str(), p2.c_str());
1855 if ((par->pextra_type == PEXTRA_NONE) &&
1856 npar && (npar->pextra_type != PEXTRA_NONE)) {
1858 p1 = npar->pextra_width,
1859 p2 = npar->pextra_widthp;
1860 npar->SetPExtraType(bparams, npar->pextra_type,
1861 p1.c_str(), p2.c_str());
1867 // if the layout of a paragraph contains a manual label, the beginning of the
1868 // main body is the beginning of the second word. This is what the par-
1869 // function returns. If the layout does not contain a label, the main
1870 // body always starts with position 0. This differentiation is necessary,
1871 // because there cannot be a newline or a blank <= the beginning of the
1872 // main body in TeX.
1874 int LyXParagraph::BeginningOfMainBody() const
1876 if (FirstPhysicalPar() != this)
1879 // Unroll the first two cycles of the loop
1880 // and remember the previous character to
1881 // remove unnecessary GetChar() calls
1884 && GetChar(i) != LyXParagraph::META_NEWLINE
1887 char previous_char = 0, temp = 0;
1889 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1890 // Yes, this ^ is supposed to be "= " not "=="
1893 && previous_char != ' '
1894 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1896 previous_char = temp;
1901 if (i == 0 && i == size() &&
1902 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1903 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1904 ++i; /* the cursor should not jump
1905 * to the main body if there
1911 LyXParagraph * LyXParagraph::DepthHook(int deth)
1913 LyXParagraph * newpar = this;
1918 newpar = newpar->FirstPhysicalPar()->Previous();
1919 } while (newpar && newpar->GetDepth() > deth
1920 && newpar->footnoteflag == footnoteflag);
1923 if (Previous() || GetDepth())
1924 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1928 return newpar->FirstPhysicalPar();
1932 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1934 LyXParagraph const * newpar = this;
1939 newpar = newpar->FirstPhysicalPar()->Previous();
1940 } while (newpar && newpar->GetDepth() > deth
1941 && newpar->footnoteflag == footnoteflag);
1944 if (Previous() || GetDepth())
1945 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1949 return newpar->FirstPhysicalPar();
1953 int LyXParagraph::AutoDeleteInsets()
1956 InsetList::size_type index = 0;
1957 while (index < insetlist.size()) {
1958 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1959 Erase(insetlist[index].pos);
1960 // Erase() calls to insetlist.erase(&insetlist[index])
1961 // so index shouldn't be increased.
1970 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
1972 InsetList::iterator it = lower_bound(insetlist.begin(),
1975 return inset_iterator(it);
1979 // returns -1 if inset not found
1980 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1983 // We could use lower_bound here too, we just need to add
1984 // the approp. operator() to matchIT (and change the name
1985 // of that struct). Code would then be:
1986 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1988 // inset, matchIT());
1989 // if ((*cit).inset == inset) {
1990 // return (*cit).pos;
1992 for (InsetList::const_iterator cit = insetlist.begin();
1993 cit != insetlist.end(); ++cit) {
1994 if ((*cit).inset == inset) {
1998 // Think about footnotes.
1999 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2000 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2002 NextAfterFootnote()->GetPositionOfInset(inset);
2004 return text.size() + 1 + further;
2010 LyXParagraph * LyXParagraph::TeXOnePar(BufferParams const & bparams,
2011 ostream & os, TexRow & texrow,
2014 TexRow & foot_texrow,
2017 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2018 LyXLayout const & style =
2019 textclasslist.Style(bparams.textclass,
2022 bool further_blank_line = false;
2024 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2026 if (start_of_appendix) {
2027 os << "\\appendix\n";
2031 if (!spacing.isDefault()
2032 && (!Previous() || !Previous()->HasSameLayout(this))) {
2033 os << spacing.writeEnvirBegin() << "\n";
2037 if (tex_code_break_column && style.isCommand()){
2042 if (pagebreak_top) {
2044 further_blank_line = true;
2046 if (added_space_top.kind() != VSpace::NONE) {
2047 os << added_space_top.asLatexCommand(bparams);
2048 further_blank_line = true;
2052 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2053 << "\\vspace{-1\\parskip}";
2054 further_blank_line = true;
2057 if (further_blank_line){
2062 Language const * language = getParLanguage(bparams);
2063 Language const * doc_language = bparams.language_info;
2064 if (language != doc_language &&
2065 (!previous || previous->getParLanguage(bparams) != language)) {
2066 os << subst(lyxrc.language_command_begin, "$$lang",
2072 switch (style.latextype) {
2075 << style.latexname()
2076 << style.latexparam();
2078 case LATEX_ITEM_ENVIRONMENT:
2080 bibkey->Latex(os, false, false);
2084 case LATEX_LIST_ENVIRONMENT:
2091 bool need_par = SimpleTeXOnePar(bparams, os, texrow, moving_arg);
2093 // Spit out footnotes
2094 LyXParagraph * par = next;
2095 if (lyxrc.rtl_support) {
2096 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2097 && next->footnoteflag != footnoteflag) {
2098 LyXParagraph * p = 0;
2099 bool is_rtl = (size() > 0)
2100 ? GetFontSettings(bparams,
2101 size()-1).isRightToLeft()
2102 : language->RightToLeft();
2103 if ( (p = NextAfterFootnote()) != 0 &&
2105 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2106 is_rtl = getParLanguage(bparams)->RightToLeft();
2107 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2108 && par->footnoteflag != footnoteflag) {
2109 par = par->TeXFootnote(bparams,
2111 foot_texrow, foot_count,
2113 par->SimpleTeXOnePar(bparams,
2114 os, texrow, moving_arg);
2115 is_rtl = (par->size() > 0)
2116 ? par->GetFontSettings(bparams,
2117 par->size()-1).isRightToLeft()
2118 : language->RightToLeft();
2120 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2121 (p = par->NextAfterFootnote()) != 0 &&
2123 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2124 is_rtl = language->RightToLeft();
2129 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2130 && par->footnoteflag != footnoteflag) {
2131 par = par->TeXFootnote(bparams,
2133 foot, foot_texrow, foot_count,
2135 par->SimpleTeXOnePar(bparams, os, texrow, moving_arg);
2140 // Make sure that \\par is done with the font of the last
2141 // character if this has another size as the default.
2142 // This is necessary because LaTeX (and LyX on the screen)
2143 // calculates the space between the baselines according
2144 // to this font. (Matthias)
2145 LyXFont font = getFont(bparams, Last() - 1);
2147 if (style.resfont.size() != font.size()) {
2153 } else if (textclasslist.Style(bparams.textclass,
2154 GetLayout()).isCommand()) {
2155 if (style.resfont.size() != font.size()) {
2161 } else if (style.resfont.size() != font.size()){
2162 os << "{\\" << font.latexSize() << " \\par}";
2165 if (language != doc_language &&
2167 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2168 || par->getParLanguage(bparams) != language)) {
2170 << subst(lyxrc.language_command_end, "$$lang",
2171 doc_language->lang());
2174 switch (style.latextype) {
2175 case LATEX_ITEM_ENVIRONMENT:
2176 case LATEX_LIST_ENVIRONMENT:
2177 if (par && (depth < par->depth)) {
2182 case LATEX_ENVIRONMENT:
2183 // if its the last paragraph of the current environment
2184 // skip it otherwise fall through
2186 && (par->layout != layout
2187 || par->depth != depth
2188 || par->pextra_type != pextra_type))
2191 // we don't need it for the last paragraph!!!
2192 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2193 && footnotekind != LyXParagraph::FOOTNOTE
2194 && footnotekind != LyXParagraph::MARGIN
2198 // don't insert this if we would be adding it
2199 // before or after a table in a float. This
2200 // little trick is needed in order to allow
2201 // use of tables in \subfigures or \subtables.
2207 further_blank_line = false;
2209 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2210 further_blank_line = true;
2213 if (added_space_bottom.kind() != VSpace::NONE) {
2214 os << added_space_bottom.asLatexCommand(bparams);
2215 further_blank_line = true;
2218 if (pagebreak_bottom) {
2220 further_blank_line = true;
2223 if (further_blank_line){
2228 if (!spacing.isDefault()
2229 && (!par || !par->HasSameLayout(this))) {
2230 os << spacing.writeEnvirEnd() << "\n";
2234 // we don't need it for the last paragraph!!!
2235 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2236 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2241 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2246 // This one spits out the text of the paragraph
2247 bool LyXParagraph::SimpleTeXOnePar(BufferParams const & bparams,
2248 ostream & os, TexRow & texrow,
2251 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2255 return SimpleTeXOneTablePar(bparams, os, texrow);
2258 bool return_value = false;
2260 LyXLayout const & style =
2261 textclasslist.Style(bparams.textclass,
2263 LyXFont basefont, last_font;
2265 // Maybe we have to create a optional argument.
2266 size_type main_body;
2267 if (style.labeltype != LABEL_MANUAL)
2270 main_body = BeginningOfMainBody();
2272 if (main_body > 0) {
2274 basefont = getFont(bparams, -2); // Get label font
2276 basefont = getFont(bparams, -1); // Get layout font
2284 if (style.isCommand()) {
2287 } else if (align != LYX_ALIGN_LAYOUT) {
2290 return_value = true;
2294 moving_arg |= style.needprotect;
2296 // Which font is currently active?
2297 LyXFont running_font(basefont);
2298 // Do we have an open font change?
2299 bool open_font = false;
2301 texrow.start(this, 0);
2303 for (size_type i = 0; i < size(); ++i) {
2305 // First char in paragraph or after label?
2306 if (i == main_body && !IsDummy()) {
2307 if (main_body > 0) {
2309 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2312 basefont = getFont(bparams, -1); // Now use the layout font
2313 running_font = basefont;
2317 if (style.isCommand()) {
2320 } else if (align != LYX_ALIGN_LAYOUT) {
2323 return_value = true;
2327 os << "\\noindent ";
2331 case LYX_ALIGN_NONE:
2332 case LYX_ALIGN_BLOCK:
2333 case LYX_ALIGN_LAYOUT:
2334 case LYX_ALIGN_SPECIAL:
2336 case LYX_ALIGN_LEFT:
2337 if (getParLanguage(bparams)->lang() != "hebrew") {
2338 os << "\\raggedright ";
2341 os << "\\raggedleft ";
2345 case LYX_ALIGN_RIGHT:
2346 if (getParLanguage(bparams)->lang() != "hebrew") {
2347 os << "\\raggedleft ";
2350 os << "\\raggedright ";
2354 case LYX_ALIGN_CENTER:
2355 os << "\\centering ";
2363 // Fully instantiated font
2364 LyXFont font = getFont(bparams, i);
2365 LyXParagraph * p = 0;
2366 if (i == 0 && previous &&
2367 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2368 (p = PreviousBeforeFootnote()) != 0)
2369 last_font = p->getFont(bparams, p->size()-1);
2371 last_font = running_font;
2373 // Spaces at end of font change are simulated to be
2374 // outside font change, i.e. we write "\textXX{text} "
2375 // rather than "\textXX{text }". (Asger)
2376 if (open_font && c == ' ' && i <= size() - 2
2377 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2378 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2379 font = getFont(bparams, i + 1);
2381 // We end font definition before blanks
2382 if (!font.equalExceptLatex(running_font) && open_font) {
2383 column += running_font.latexWriteEndChanges(os,
2385 (i == main_body-1) ? basefont : font);
2386 running_font = basefont;
2390 // Blanks are printed before start of fontswitch
2392 // Do not print the separation of the optional argument
2393 if (i != main_body - 1) {
2394 SimpleTeXBlanks(os, texrow, i,
2395 column, font, style);
2399 // Do we need to change font?
2400 if (!font.equalExceptLatex(running_font)
2401 && i != main_body-1) {
2402 column += font.latexWriteStartChanges(os, basefont,
2404 running_font = font;
2408 if (c == LyXParagraph::META_NEWLINE) {
2409 // newlines are handled differently here than
2410 // the default in SimpleTeXSpecialChars().
2411 if (!style.newline_allowed
2412 || font.latex() == LyXFont::ON) {
2416 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2419 basefont = getFont(bparams, -1);
2420 running_font = basefont;
2421 if (font.family() ==
2422 LyXFont::TYPEWRITER_FAMILY) {
2430 texrow.start(this, i + 1);
2433 SimpleTeXSpecialChars(bparams,
2434 os, texrow, moving_arg,
2435 font, running_font, basefont,
2436 open_font, style, i, column, c);
2440 // If we have an open font definition, we have to close it
2442 LyXParagraph * p = 0;
2443 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2444 && (p = NextAfterFootnote()) != 0)
2445 running_font.latexWriteEndChanges(os, basefont,
2446 p->getFont(bparams, 0));
2448 running_font.latexWriteEndChanges(os, basefont, basefont);
2451 // Needed if there is an optional argument but no contents.
2452 if (main_body > 0 && main_body == size()) {
2454 return_value = false;
2457 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2458 return return_value;
2462 // This one spits out the text of a table paragraph
2463 bool LyXParagraph::SimpleTeXOneTablePar(BufferParams const & bparams,
2464 ostream & os, TexRow & texrow)
2466 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2468 bool return_value = false;
2470 LyXLayout const & style =
2471 textclasslist.Style(bparams.textclass, GetLayout());
2474 if (!IsDummy()) { // it is dummy if it is in a float!!!
2475 if (style.isCommand()) {
2478 } else if (align != LYX_ALIGN_LAYOUT) {
2481 return_value = true;
2484 os << "\\noindent ";
2488 case LYX_ALIGN_NONE:
2489 case LYX_ALIGN_BLOCK:
2490 case LYX_ALIGN_LAYOUT:
2491 case LYX_ALIGN_SPECIAL: break;
2492 case LYX_ALIGN_LEFT:
2493 os << "\\raggedright ";
2496 case LYX_ALIGN_RIGHT:
2497 os << "\\raggedleft ";
2500 case LYX_ALIGN_CENTER:
2501 os << "\\centering ";
2507 LyXFont basefont = getFont(bparams, -1); // Get layout font
2508 // Which font is currently active?
2509 LyXFont running_font = basefont;
2511 // Do we have an open font change?
2512 bool open_font = false;
2513 int current_cell_number = -1;
2514 int tmp = table->TexEndOfCell(os, current_cell_number);
2515 for (; tmp > 0 ; --tmp)
2518 texrow.start(this, 0);
2520 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2521 bool first_in_cell = true;
2523 for (size_type i = 0; i < size(); ++i) {
2524 char c = GetChar(i);
2525 if (table->IsContRow(current_cell_number + 1)) {
2526 if (c == LyXParagraph::META_NEWLINE)
2527 ++current_cell_number;
2532 if (first_in_cell && is_rtl) {
2535 first_in_cell = false;
2538 // Fully instantiated font
2539 LyXFont font = getFont(bparams, i);
2540 last_font = running_font;
2542 // Spaces at end of font change are simulated to be
2543 // outside font change.
2544 // i.e. we write "\textXX{text} " rather than
2545 // "\textXX{text }". (Asger)
2546 if (open_font && c == ' ' && i <= size() - 2
2547 && getFont(bparams, i + 1) != running_font
2548 && getFont(bparams, i + 1) != font) {
2549 font = getFont(bparams, i + 1);
2552 // We end font definition before blanks
2553 if (font != running_font && open_font) {
2554 column += running_font.latexWriteEndChanges(os,
2557 running_font = basefont;
2560 // Blanks are printed before start of fontswitch
2562 SimpleTeXBlanks(os, texrow, i, column, font, style);
2564 // Do we need to change font?
2565 if (font != running_font) {
2566 column += font.latexWriteStartChanges(os, basefont,
2568 running_font = font;
2571 // Do we need to turn on LaTeX mode?
2572 if (font.latex() != running_font.latex()) {
2573 if (font.latex() == LyXFont::ON
2574 && style.needprotect) {
2579 if (c == LyXParagraph::META_NEWLINE) {
2580 // special case for inside a table
2581 // different from default case in
2582 // SimpleTeXSpecialChars()
2584 column += running_font
2585 .latexWriteEndChanges(os, basefont,
2589 basefont = getFont(bparams, -1);
2590 running_font = basefont;
2591 ++current_cell_number;
2592 if (table->CellHasContRow(current_cell_number) >= 0) {
2593 TeXContTableRows(bparams, os, i + 1,
2594 current_cell_number,
2597 if (is_rtl && !first_in_cell) {
2599 first_in_cell = true;
2602 // if this cell follow only ContRows till end don't
2603 // put the EndOfCell because it is put after the
2605 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2606 --current_cell_number;
2609 int tmp = table->TexEndOfCell(os,
2610 current_cell_number);
2613 } else if (tmp < 0) {
2619 texrow.start(this, i + 1);
2621 SimpleTeXSpecialChars(bparams,
2623 font, running_font, basefont,
2624 open_font, style, i, column, c);
2628 // If we have an open font definition, we have to close it
2630 running_font.latexWriteEndChanges(os, basefont, basefont);
2632 ++current_cell_number;
2633 if (is_rtl && !first_in_cell)
2635 tmp = table->TexEndOfCell(os, current_cell_number);
2636 for (; tmp > 0; --tmp)
2638 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2639 return return_value;
2643 // This one spits out the text off ContRows in tables
2644 bool LyXParagraph::TeXContTableRows(BufferParams const & bparams,
2646 LyXParagraph::size_type i,
2647 int current_cell_number,
2648 int & column, TexRow & texrow)
2650 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2654 bool return_value = false;
2655 LyXLayout const & style =
2656 textclasslist.Style(bparams.textclass,
2658 LyXFont basefont = getFont(bparams, -1); // Get layout font
2660 // Which font is currently active?
2661 LyXFont running_font = basefont;
2662 // Do we have an open font change?
2663 bool open_font = false;
2665 size_type lastpos = i;
2666 int cell = table->CellHasContRow(current_cell_number);
2667 ++current_cell_number;
2670 // first find the right position
2672 for (; (i < size()) && (current_cell_number<cell); ++i) {
2674 if (c == LyXParagraph::META_NEWLINE)
2675 ++current_cell_number;
2679 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2683 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2688 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2692 // Fully instantiated font
2693 LyXFont font = getFont(bparams, i);
2694 last_font = running_font;
2696 // Spaces at end of font change are simulated to
2697 // be outside font change. i.e. we write
2698 // "\textXX{text} " rather than "\textXX{text }".
2700 if (open_font && c == ' ' && i <= size() - 2
2701 && getFont(bparams, i + 1) != running_font
2702 && getFont(bparams, i + 1) != font) {
2703 font = getFont(bparams, i + 1);
2706 // We end font definition before blanks
2707 if (font != running_font && open_font) {
2708 column += running_font.latexWriteEndChanges(os, basefont, font);
2709 running_font = basefont;
2712 // Blanks are printed before start of fontswitch
2714 SimpleTeXBlanks(os, texrow, i,
2715 column, font, style);
2717 // Do we need to change font?
2718 if (font != running_font) {
2720 font.latexWriteStartChanges(os,
2723 running_font = font;
2726 // Do we need to turn on LaTeX mode?
2727 if (font.latex() != running_font.latex()) {
2728 if (font.latex() == LyXFont::ON
2729 && style.needprotect) {
2734 SimpleTeXSpecialChars(bparams,
2735 os, texrow, false, font,
2736 running_font, basefont,
2737 open_font, style, i, column, c);
2739 // If we have an open font definition, we have to close it
2741 running_font.latexWriteEndChanges(os, basefont,
2745 basefont = getFont(bparams, -1);
2746 running_font = basefont;
2747 cell = table->CellHasContRow(current_cell_number);
2749 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2750 return return_value;
2754 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2756 bool retval = false;
2758 case LyXParagraph::META_HFILL:
2759 sgml_string.erase();
2761 case LyXParagraph::META_NEWLINE:
2765 sgml_string = "&";
2768 sgml_string = "<";
2771 sgml_string = ">";
2774 sgml_string = "$";
2777 sgml_string = "#";
2780 sgml_string = "%";
2783 sgml_string = "[";
2786 sgml_string = "]";
2789 sgml_string = "{";
2792 sgml_string = "}";
2795 sgml_string = "˜";
2798 sgml_string = """;
2801 sgml_string = "\";
2807 case '\0': // Ignore :-)
2808 sgml_string.erase();
2818 void LyXParagraph::SimpleDocBookOneTablePar(BufferParams const & bparams,
2819 ostream & os, string & extra,
2820 int & desc_on, int depth)
2823 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2825 LyXFont font1, font2;
2828 size_type main_body;
2829 bool emph_flag = false;
2831 LyXLayout const & style =
2832 textclasslist.Style(bparams.textclass,
2835 if (style.labeltype != LABEL_MANUAL)
2838 main_body = BeginningOfMainBody();
2840 // Gets paragraph main font.
2842 font1 = style.labelfont;
2846 int char_line_count = depth;
2847 os << newlineAndDepth(depth);
2848 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2849 os << "<INFORMALTABLE>"
2850 << newlineAndDepth(++depth);
2852 int current_cell_number = -1;
2853 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2855 // Parsing main loop.
2856 for (size_type i = 0; i < size(); ++i) {
2858 if (table->IsContRow(current_cell_number+1)) {
2859 if (c == LyXParagraph::META_NEWLINE)
2860 ++current_cell_number;
2865 // Fully instantiated font
2866 font2 = getFont(bparams, i);
2868 // Handle <emphasis> tag.
2869 if (font1.emph() != font2.emph() && i) {
2870 if (font2.emph() == LyXFont::ON) {
2873 } else if (emph_flag) {
2874 os << "</emphasis>";
2878 if (c == LyXParagraph::META_NEWLINE) {
2879 // We have only to control for emphasis open here!
2881 os << "</emphasis>";
2884 font1 = font2 = getFont(bparams, -1);
2885 ++current_cell_number;
2886 if (table->CellHasContRow(current_cell_number) >= 0) {
2887 DocBookContTableRows(bparams,
2888 os, extra, desc_on, i + 1,
2889 current_cell_number,
2892 // if this cell follow only ContRows till end don't
2893 // put the EndOfCell because it is put after the
2895 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2896 --current_cell_number;
2899 tmp = table->DocBookEndOfCell(os,
2900 current_cell_number,
2905 } else if (c == LyXParagraph::META_INSET) {
2906 inset = GetInset(i);
2908 std::ostringstream ost;
2909 inset->DocBook(ost);
2910 string tmp_out = ost.str().c_str();
2913 inset->DocBook(ost);
2915 char * ctmp = ost.str();
2916 string tmp_out(ctmp);
2920 // This code needs some explanation:
2921 // Two insets are treated specially
2922 // label if it is the first element in a
2923 // command paragraph
2925 // graphics inside tables or figure floats
2927 // title (the equivalente in latex for this
2929 // and title should come first
2932 if(desc_on != 3 || i != 0) {
2933 if(tmp_out[0] == '@') {
2935 extra += frontStrip(tmp_out,
2938 os << frontStrip(tmp_out,
2943 } else if (font2.latex() == LyXFont::ON) {
2944 // "TeX"-Mode on == > SGML-Mode on.
2950 if (linuxDocConvertChar(c, sgml_string)
2951 && !style.free_spacing) {
2952 // in freespacing mode, spaces are
2953 // non-breaking characters
2958 << "</term><listitem><para>";
2970 // Needed if there is an optional argument but no contents.
2971 if (main_body > 0 && main_body == size()) {
2976 os << "</emphasis>";
2979 ++current_cell_number;
2980 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2981 // Resets description flag correctly.
2984 // <term> not closed...
2988 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2989 os << "</INFORMALTABLE>";
2991 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2996 void LyXParagraph::DocBookContTableRows(BufferParams const & bparams,
2997 ostream & os, string & extra,
2999 LyXParagraph::size_type i,
3000 int current_cell_number, int &column)
3005 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3010 //string emph = "emphasis";
3011 bool emph_flag = false;
3012 int char_line_count = 0;
3014 LyXLayout const & style =
3015 textclasslist.Style(bparams.textclass,
3018 size_type main_body;
3019 if (style.labeltype != LABEL_MANUAL)
3022 main_body = BeginningOfMainBody();
3024 // Gets paragraph main font.
3027 font1 = style.labelfont;
3031 size_type lastpos = i;
3032 int cell = table->CellHasContRow(current_cell_number);
3033 ++current_cell_number;
3035 // first find the right position
3037 for (; i < size() && current_cell_number < cell; ++i) {
3039 if (c == LyXParagraph::META_NEWLINE)
3040 ++current_cell_number;
3044 // I don't know how to handle this so I comment it
3045 // for the moment (Jug)
3046 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3047 // file += " \\\\\n";
3050 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3055 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3059 // Fully instantiated font
3060 font2 = getFont(bparams, i);
3062 // Handle <emphasis> tag.
3063 if (font1.emph() != font2.emph() && i) {
3064 if (font2.emph() == LyXFont::ON) {
3067 } else if (emph_flag) {
3068 os << "</emphasis>";
3072 if (c == LyXParagraph::META_INSET) {
3073 inset = GetInset(i);
3075 std::ostringstream ost;
3076 inset->DocBook(ost);
3077 string tmp_out = ost.str().c_str();
3080 inset->DocBook(ost);
3082 char * ctmp = ost.str();
3083 string tmp_out(ctmp);
3087 // This code needs some explanation:
3088 // Two insets are treated specially
3089 // label if it is the first element in a
3090 // command paragraph
3092 // graphics inside tables or figure floats
3093 // can't go on title (the equivalente in
3094 // latex for this case is caption and title
3095 // should come first
3098 if(desc_on != 3 || i != 0) {
3099 if(tmp_out[0] == '@') {
3101 extra += frontStrip(tmp_out, '@');
3103 os << frontStrip(tmp_out, '@');
3107 } else if (font2.latex() == LyXFont::ON) {
3108 // "TeX"-Mode on == > SGML-Mode on.
3114 if (linuxDocConvertChar(c, sgml_string)
3115 && !style.free_spacing) {
3116 // in freespacing mode, spaces are
3117 // non-breaking characters
3122 << "</term><listitem><para>";
3132 // we have only to control for emphasis open here!
3134 os << "</emphasis>";
3137 font1 = font2 = getFont(bparams, -1);
3138 cell = table->CellHasContRow(current_cell_number);
3140 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3144 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3145 LyXParagraph::size_type const i,
3146 int & column, LyXFont const & font,
3147 LyXLayout const & style)
3149 if (column > tex_code_break_column
3151 && GetChar(i - 1) != ' '
3153 // In LaTeX mode, we don't want to
3154 // break lines since some commands
3156 && ! (font.latex() == LyXFont::ON)
3157 // same in FreeSpacing mode
3158 && !style.free_spacing
3159 // In typewriter mode, we want to avoid
3160 // ! . ? : at the end of a line
3161 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3162 && (GetChar(i-1) == '.'
3163 || GetChar(i-1) == '?'
3164 || GetChar(i-1) == ':'
3165 || GetChar(i-1) == '!'))) {
3166 if (tex_code_break_column == 0) {
3167 // in batchmode we need LaTeX to still
3168 // see it as a space not as an extra '\n'
3174 texrow.start(this, i + 1);
3176 } else if (font.latex() == LyXFont::OFF) {
3177 if (style.free_spacing) {
3186 void LyXParagraph::SimpleTeXSpecialChars(BufferParams const & bparams,
3187 ostream & os, TexRow & texrow,
3190 LyXFont & running_font,
3193 LyXLayout const & style,
3194 LyXParagraph::size_type & i,
3195 int & column, char const c)
3197 // Two major modes: LaTeX or plain
3198 // Handle here those cases common to both modes
3199 // and then split to handle the two modes separately.
3201 case LyXParagraph::META_INSET: {
3202 Inset * inset = GetInset(i);
3205 int len = os.tellp();
3206 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3207 || inset->LyxCode() == Inset::MATH_CODE
3208 || inset->LyxCode() == Inset::URL_CODE)
3209 && running_font.isRightToLeft()) {
3214 int tmp = inset->Latex(os, moving_arg,
3215 style.free_spacing);
3223 column += os.tellp() - len;
3232 case LyXParagraph::META_NEWLINE:
3234 column += running_font.latexWriteEndChanges(os,
3239 basefont = getFont(bparams, -1);
3240 running_font = basefont;
3243 case LyXParagraph::META_HFILL:
3249 // And now for the special cases within each mode
3250 // Are we in LaTeX mode?
3251 if (font.latex() == LyXFont::ON) {
3252 // at present we only have one option
3253 // but I'll leave it as a switch statement
3254 // so its simpler to extend. (ARRae)
3257 // make sure that we will not print
3258 // error generating chars to the tex
3259 // file. This test would not be needed
3260 // if it were done in the buffer
3268 // Plain mode (i.e. not LaTeX)
3271 os << "\\textbackslash{}";
3275 case '°': case '±': case '²': case '³':
3276 case '×': case '÷': case '¹': case 'ª':
3277 case 'º': case '¬': case 'µ':
3278 if (bparams.inputenc == "latin1") {
3279 os << "\\ensuremath{"
3288 case '|': case '<': case '>':
3289 // In T1 encoding, these characters exist
3290 if (lyxrc.fontenc == "T1") {
3292 //... but we should avoid ligatures
3293 if ((c == '>' || c == '<')
3295 && GetChar(i + 1) == c){
3296 os << "\\textcompwordmark{}";
3301 // Typewriter font also has them
3302 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3306 // Otherwise, we use what LaTeX
3310 os << "\\textless{}";
3314 os << "\\textgreater{}";
3318 os << "\\textbar{}";
3324 case '-': // "--" in Typewriter mode -> "-{}-"
3326 && GetChar(i + 1) == '-'
3327 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3336 os << "\\char`\\\"{}";
3341 if (bparams.inputenc == "default") {
3350 case '%': case '#': case '{':
3357 os << "\\textasciitilde{}";
3362 os << "\\textasciicircum{}";
3366 case '*': case '[': case ']':
3367 // avoid being mistaken for optional arguments
3368 os << '{' << c << '}';
3373 // Blanks are printed before font switching.
3374 // Sure? I am not! (try nice-latex)
3375 // I am sure it's correct. LyX might be smarter
3376 // in the future, but for now, nothing wrong is
3381 /* idea for labels --- begin*/
3385 && font.family() != LyXFont::TYPEWRITER_FAMILY
3386 && GetChar(i + 1) == 'y'
3387 && GetChar(i + 2) == 'X') {
3395 && font.family() != LyXFont::TYPEWRITER_FAMILY
3396 && GetChar(i + 1) == 'e'
3397 && GetChar(i + 2) == 'X') {
3402 // Check for "LaTeX2e"
3405 && font.family() != LyXFont::TYPEWRITER_FAMILY
3406 && GetChar(i + 1) == 'a'
3407 && GetChar(i + 2) == 'T'
3408 && GetChar(i + 3) == 'e'
3409 && GetChar(i + 4) == 'X'
3410 && GetChar(i + 5) == '2'
3411 && GetChar(i + 6) == 'e') {
3416 // Check for "LaTeX"
3419 && font.family() != LyXFont::TYPEWRITER_FAMILY
3420 && GetChar(i + 1) == 'a'
3421 && GetChar(i + 2) == 'T'
3422 && GetChar(i + 3) == 'e'
3423 && GetChar(i + 4) == 'X') {
3427 /* idea for labels --- end*/
3428 } else if (c != '\0') {
3439 bool LyXParagraph::RoffContTableRows(ostream & os,
3440 LyXParagraph::size_type i,
3446 LyXFont font1(LyXFont::ALL_INHERIT);
3451 string fname2 = TmpFileName(string(), "RAT2");
3453 int cell = table->CellHasContRow(actcell);
3456 // first find the right position
3458 for (; i < size() && actcell < cell; ++i) {
3460 if (c == LyXParagraph::META_NEWLINE)
3465 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3468 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3470 font2 = GetFontSettings(i);
3471 if (font1.latex() != font2.latex()) {
3472 if (font2.latex() != LyXFont::OFF)
3477 case LyXParagraph::META_INSET:
3478 if ((inset = GetInset(i))) {
3480 stringstream ss(ios::in | ios::out);
3507 case LyXParagraph::META_NEWLINE:
3509 case LyXParagraph::META_HFILL:
3518 lyxerr.debug() << "RoffAsciiTable: "
3519 "NULL char in structure."
3524 cell = table->CellHasContRow(actcell);
3531 LyXParagraph * LyXParagraph::TeXDeeper(BufferParams const & bparams,
3532 ostream & os, TexRow & texrow,
3534 TexRow & foot_texrow,
3537 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3538 LyXParagraph * par = this;
3541 (par->depth == depth) &&
3542 (par->footnoteflag == footnoteflag)) {
3544 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3545 if (textclasslist.Style(bparams.textclass,
3546 par->layout).isEnvironment()
3547 || par->pextra_type != PEXTRA_NONE) {
3548 par = par->TeXEnvironment(bparams,
3553 par = par->TeXOnePar(bparams,
3559 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3565 LyXParagraph * LyXParagraph::TeXEnvironment(BufferParams const & bparams,
3566 ostream & os, TexRow & texrow,
3568 TexRow & foot_texrow,
3571 bool eindent_open = false;
3572 bool foot_this_level = false;
3573 // flags when footnotetext should be appended to file.
3574 static bool minipage_open = false;
3575 static int minipage_open_depth = 0;
3576 char par_sep = bparams.paragraph_separation;
3578 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3580 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3582 LyXLayout const & style =
3583 textclasslist.Style(bparams.textclass,
3586 if (pextra_type == PEXTRA_INDENT) {
3587 if (!pextra_width.empty()) {
3588 os << "\\begin{LyXParagraphIndent}{"
3589 << pextra_width << "}\n";
3591 //float ib = atof(pextra_widthp.c_str())/100;
3592 // string can't handle floats at present (971109)
3593 // so I'll do a conversion by hand knowing that
3594 // the limits are 0.0 to 1.0. ARRae.
3595 os << "\\begin{LyXParagraphIndent}{";
3596 switch (pextra_widthp.length()) {
3608 os << "\\columnwidth}\n";
3611 eindent_open = true;
3613 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3614 if (pextra_hfill && Previous() &&
3615 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3616 os << "\\hfill{}\n";
3619 if (par_sep == BufferParams::PARSEP_INDENT) {
3620 os << "{\\setlength\\parindent{0pt}\n";
3623 os << "\\begin{minipage}";
3624 switch(pextra_alignment) {
3625 case MINIPAGE_ALIGN_TOP:
3628 case MINIPAGE_ALIGN_MIDDLE:
3631 case MINIPAGE_ALIGN_BOTTOM:
3635 if (!pextra_width.empty()) {
3636 os << '{' << pextra_width << "}\n";
3638 //float ib = atof(par->pextra_width.c_str())/100;
3639 // string can't handle floats at present
3640 // so I'll do a conversion by hand knowing that
3641 // the limits are 0.0 to 1.0. ARRae.
3643 switch (pextra_widthp.length()) {
3655 os << "\\columnwidth}\n";
3658 if (par_sep == BufferParams::PARSEP_INDENT) {
3659 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3662 minipage_open = true;
3663 minipage_open_depth = depth;
3666 #ifdef WITH_WARNINGS
3667 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3668 //I disabled it because it breaks when lists span on several
3671 if (style.isEnvironment()){
3672 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3673 #ifdef FANCY_FOOTNOTE_CODE
3674 if (foot_count < 0) {
3675 // flag that footnote[mark][text] should be
3676 // used for any footnotes from now on
3678 foot_this_level = true;
3681 os << "\\begin{" << style.latexname() << "}{"
3682 << labelwidthstring << "}\n";
3683 } else if (style.labeltype == LABEL_BIBLIO) {
3685 os << "\\begin{" << style.latexname() << "}{"
3686 << bibitemWidest(current_view->painter())
3688 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3689 #ifdef FANCY_FOOTNOTE_CODE
3690 if (foot_count < 0) {
3691 // flag that footnote[mark][text] should be
3692 // used for any footnotes from now on
3694 foot_this_level = true;
3697 os << "\\begin{" << style.latexname() << '}'
3698 << style.latexparam() << '\n';
3700 os << "\\begin{" << style.latexname() << '}'
3701 << style.latexparam() << '\n';
3704 LyXParagraph * par = this;
3706 par = par->TeXOnePar(bparams,
3708 foot, foot_texrow, foot_count);
3710 if (minipage_open && par && !style.isEnvironment() &&
3711 (par->pextra_type == PEXTRA_MINIPAGE) &&
3712 par->pextra_start_minipage) {
3713 os << "\\end{minipage}\n";
3715 if (par_sep == BufferParams::PARSEP_INDENT) {
3719 minipage_open = false;
3721 if (par && par->depth > depth) {
3722 if (textclasslist.Style(bparams.textclass,
3723 par->layout).isParagraph()
3726 // How to handle this? (Lgb)
3727 //&& !suffixIs(os, "\n\n")
3729 // There should be at least one '\n' already
3730 // but we need there to be two for Standard
3731 // paragraphs that are depth-increment'ed to be
3732 // output correctly. However, tables can
3733 // also be paragraphs so don't adjust them.
3736 // Will it ever harm to have one '\n' too
3737 // many? i.e. that we sometimes will have
3738 // three in a row. (Lgb)
3742 par = par->TeXDeeper(bparams, os, texrow,
3743 foot, foot_texrow, foot_count);
3745 if (par && par->layout == layout && par->depth == depth &&
3746 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3747 if (par->pextra_hfill && par->Previous() &&
3748 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3749 os << "\\hfill{}\n";
3752 if (par_sep == BufferParams::PARSEP_INDENT) {
3753 os << "{\\setlength\\parindent{0pt}\n";
3756 os << "\\begin{minipage}";
3757 switch(par->pextra_alignment) {
3758 case MINIPAGE_ALIGN_TOP:
3761 case MINIPAGE_ALIGN_MIDDLE:
3764 case MINIPAGE_ALIGN_BOTTOM:
3768 if (!par->pextra_width.empty()) {
3769 os << '{' << par->pextra_width << "}\n";
3771 //float ib = atof(par->pextra_widthp.c_str())/100;
3772 // string can't handle floats at present
3773 // so I'll do a conversion by hand knowing that
3774 // the limits are 0.0 to 1.0. ARRae.
3776 switch (par->pextra_widthp.length()) {
3781 os << "0." << par->pextra_widthp;
3784 os << "0.0" << par->pextra_widthp;
3786 os << "\\columnwidth}\n";
3789 if (par_sep == BufferParams::PARSEP_INDENT) {
3790 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3793 minipage_open = true;
3794 minipage_open_depth = par->depth;
3797 && par->layout == layout
3798 && par->depth == depth
3799 && par->pextra_type == pextra_type
3800 && par->footnoteflag == footnoteflag);
3802 if (style.isEnvironment()) {
3803 os << "\\end{" << style.latexname() << '}';
3804 // maybe this should go after the minipage closes?
3805 if (foot_this_level) {
3806 if (foot_count >= 1) {
3807 if (foot_count > 1) {
3808 os << "\\addtocounter{footnote}{-"
3813 texrow += foot_texrow;
3815 foot_texrow.reset();
3820 if (minipage_open && (minipage_open_depth == depth) &&
3821 (!par || par->pextra_start_minipage ||
3822 par->pextra_type != PEXTRA_MINIPAGE)) {
3823 os << "\\end{minipage}\n";
3825 if (par_sep == BufferParams::PARSEP_INDENT) {
3829 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3830 os << "\\medskip\n\n";
3834 minipage_open = false;
3837 os << "\\end{LyXParagraphIndent}\n";
3840 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3841 && par->pextra_hfill)) {
3845 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3846 return par; // ale970302
3850 LyXParagraph * LyXParagraph::TeXFootnote(BufferParams const & bparams,
3851 ostream & os, TexRow & texrow,
3852 ostream & foot, TexRow & foot_texrow,
3856 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3857 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3858 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3859 "No footnote!" << endl;
3861 LyXParagraph * par = this;
3862 LyXLayout const & style =
3863 textclasslist.Style(bparams.textclass,
3864 previous->GetLayout());
3866 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3867 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3868 "Float other than footnote in command"
3869 " with moving argument is illegal" << endl;
3872 if (footnotekind != LyXParagraph::FOOTNOTE
3873 && footnotekind != LyXParagraph::MARGIN
3876 // How to solve this?
3877 //&& !suffixIs(file, '\n')
3879 // we need to ensure that real floats like tables and figures
3880 // have their \begin{} on a new line otherwise we can get
3881 // incorrect results when using the endfloat.sty package
3882 // especially if two floats follow one another. ARRae 981022
3883 // NOTE: if the file is length 0 it must have just been
3884 // written out so we assume it ended with a '\n'
3886 // As far as I can see there is never any harm in writing
3887 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3892 bool moving_arg = false;
3893 bool need_closing = false;
3894 bool is_rtl = isRightToLeftPar(bparams);
3896 if (is_rtl != parent_is_rtl) {
3901 need_closing = true;
3904 //BufferParams * params = ¤t_view->buffer()->params;
3905 bool footer_in_body = true;
3906 switch (footnotekind) {
3907 case LyXParagraph::FOOTNOTE:
3908 if (style.intitle) {
3909 os << "\\thanks{\n";
3910 footer_in_body = false;
3913 if (foot_count == -1) {
3914 // we're at depth 0 so we can use:
3915 os << "\\footnote{%\n";
3916 footer_in_body = false;
3918 os << "\\footnotemark{}%\n";
3920 // we only need this when there are
3921 // multiple footnotes
3922 os << "\\stepcounter{footnote}";
3924 os << "\\footnotetext{%\n";
3925 foot_texrow.start(this, 0);
3926 foot_texrow.newline();
3931 case LyXParagraph::MARGIN:
3932 os << "\\marginpar{\n";
3934 case LyXParagraph::FIG:
3935 if (pextra_type == PEXTRA_FLOATFLT
3936 && (!pextra_width.empty()
3937 || !pextra_widthp.empty())) {
3938 if (!pextra_width.empty())
3939 os << "\\begin{floatingfigure}{"
3940 << pextra_width << "}\n";
3942 os << "\\begin{floatingfigure}{"
3943 << atoi(pextra_widthp.c_str())/100.0
3944 << "\\textwidth}\n";
3946 os << "\\begin{figure}";
3947 if (!bparams.float_placement.empty()) {
3948 os << '[' << bparams.float_placement << "]\n";
3954 case LyXParagraph::TAB:
3955 os << "\\begin{table}";
3956 if (!bparams.float_placement.empty()) {
3957 os << '[' << bparams.float_placement << "]\n";
3962 case LyXParagraph::WIDE_FIG:
3963 os << "\\begin{figure*}";
3964 if (!bparams.float_placement.empty()) {
3965 os << '[' << bparams.float_placement << "]\n";
3970 case LyXParagraph::WIDE_TAB:
3971 os << "\\begin{table*}";
3972 if (!bparams.float_placement.empty()) {
3973 os << '[' << bparams.float_placement << "]\n";
3978 case LyXParagraph::ALGORITHM:
3979 os << "\\begin{algorithm}\n";
3984 if (footnotekind != LyXParagraph::FOOTNOTE
3985 || !footer_in_body) {
3986 // Process text for all floats except footnotes in body
3988 LyXLayout const & style =
3990 .Style(bparams.textclass, par->layout);
3992 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3994 if (style.isEnvironment()
3995 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3996 // Allows the use of minipages within float
3997 // environments. Shouldn't be circular because
3998 // we don't support footnotes inside
3999 // floats (yet). ARRae
4000 par = par->TeXEnvironment(bparams, os, texrow,
4004 par = par->TeXOnePar(bparams,
4005 os, texrow, moving_arg,
4010 if (par && !par->IsDummy() && par->depth > depth) {
4011 par = par->TeXDeeper(bparams, os, texrow,
4015 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4017 // process footnotes > depth 0 or in environments separately
4018 // NOTE: Currently don't support footnotes within footnotes
4019 // even though that is possible using the \footnotemark
4021 std::ostringstream dummy;
4025 TexRow dummy_texrow;
4026 int dummy_count = 0;
4028 LyXLayout const & style =
4030 .Style(bparams.textclass, par->layout);
4032 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4034 if (style.isEnvironment()
4035 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4036 // Allows the use of minipages within float
4037 // environments. Shouldn't be circular because
4038 // we don't support footnotes inside
4039 // floats (yet). ARRae
4040 par = par->TeXEnvironment(bparams,
4042 dummy, dummy_texrow,
4045 par = par->TeXOnePar(bparams,
4048 dummy, dummy_texrow,
4052 if (par && !par->IsDummy() && par->depth > depth) {
4053 par = par->TeXDeeper(bparams,
4055 dummy, dummy_texrow,
4059 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4061 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4062 "Footnote in a Footnote -- not supported"
4065 #ifndef HAVE_OSTREAM
4066 delete [] dummy.str();
4070 switch (footnotekind) {
4071 case LyXParagraph::FOOTNOTE:
4072 if (footer_in_body) {
4073 // This helps tell which of the multiple
4074 // footnotetexts an error was in.
4076 foot_texrow.newline();
4081 case LyXParagraph::MARGIN:
4084 case LyXParagraph::FIG:
4085 if (pextra_type == PEXTRA_FLOATFLT
4086 && (!pextra_width.empty()
4087 || !pextra_widthp.empty()))
4088 os << "\\end{floatingfigure}";
4090 os << "\\end{figure}";
4092 case LyXParagraph::TAB:
4093 os << "\\end{table}";
4095 case LyXParagraph::WIDE_FIG:
4096 os << "\\end{figure*}";
4098 case LyXParagraph::WIDE_TAB:
4099 os << "\\end{table*}";
4101 case LyXParagraph::ALGORITHM:
4102 os << "\\end{algorithm}";
4109 if (footnotekind != LyXParagraph::FOOTNOTE
4110 && footnotekind != LyXParagraph::MARGIN) {
4111 // we need to ensure that real floats like tables and figures
4112 // have their \end{} on a line of their own otherwise we can
4113 // get incorrect results when using the endfloat.sty package.
4118 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4123 bool LyXParagraph::IsDummy() const
4125 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4126 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4130 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4131 int type, char const * width,
4132 char const * widthp)
4135 pextra_width = width;
4136 pextra_widthp = widthp;
4138 if (textclasslist.Style(bparams.textclass,
4139 layout).isEnvironment()) {
4144 while (par && (par->layout == layout)
4145 && (par->depth == depth)) {
4147 par = par->Previous();
4149 par = par->FirstPhysicalPar();
4150 while (par && par->depth > depth) {
4151 par = par->Previous();
4153 par = par->FirstPhysicalPar();
4157 while (par && (par->layout == layout)
4158 && (par->depth == depth)) {
4159 par->pextra_type = type;
4160 par->pextra_width = width;
4161 par->pextra_widthp = widthp;
4162 par = par->NextAfterFootnote();
4163 if (par && (par->depth > depth))
4164 par->SetPExtraType(bparams,
4165 type, width, widthp);
4166 while (par && ((par->depth > depth) || par->IsDummy()))
4167 par = par->NextAfterFootnote();
4173 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4175 if (pextra_type == PEXTRA_NONE)
4178 pextra_type = PEXTRA_NONE;
4179 pextra_width.erase();
4180 pextra_widthp.erase();
4182 if (textclasslist.Style(bparams.textclass,
4183 layout).isEnvironment()) {
4188 while (par && (par->layout == layout)
4189 && (par->depth == depth)) {
4191 par = par->Previous();
4193 par = par->FirstPhysicalPar();
4194 while (par && par->depth > depth) {
4195 par = par->Previous();
4197 par = par->FirstPhysicalPar();
4201 while (par && (par->layout == layout)
4202 && (par->depth == depth)) {
4203 par->pextra_type = PEXTRA_NONE;
4204 par->pextra_width.erase();
4205 par->pextra_widthp.erase();
4206 par = par->NextAfterFootnote();
4207 if (par && (par->depth > depth))
4208 par->UnsetPExtraType(bparams);
4209 while (par && ((par->depth > depth) || par->IsDummy()))
4210 par = par->NextAfterFootnote();
4216 bool LyXParagraph::IsHfill(size_type pos) const
4218 return IsHfillChar(GetChar(pos));
4222 bool LyXParagraph::IsInset(size_type pos) const
4224 return IsInsetChar(GetChar(pos));
4228 bool LyXParagraph::IsFloat(size_type pos) const
4230 return IsFloatChar(GetChar(pos));
4234 bool LyXParagraph::IsNewline(size_type pos) const
4236 return pos >= 0 && IsNewlineChar(GetChar(pos));
4240 bool LyXParagraph::IsSeparator(size_type pos) const
4242 return IsSeparatorChar(GetChar(pos));
4246 bool LyXParagraph::IsLineSeparator(size_type pos) const
4248 return IsLineSeparatorChar(GetChar(pos));
4252 bool LyXParagraph::IsKomma(size_type pos) const
4254 return IsKommaChar(GetChar(pos));
4258 /// Used by the spellchecker
4259 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4261 unsigned char c = GetChar(pos);
4262 if (IsLetterChar(c))
4264 // '\0' is not a letter, allthough every string contains "" (below)
4267 // We want to pass the ' and escape chars to ispell
4268 string extra = lyxrc.isp_esc_chars + '\'';
4272 return contains(extra, ch);
4276 bool LyXParagraph::IsWord(size_type pos ) const
4278 return IsWordChar(GetChar(pos)) ;
4283 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4286 return FirstPhysicalPar()->getParLanguage(bparams);
4287 else if (size() > 0)
4291 return GetFirstFontSettings().language();
4294 for (size_type pos = 0; pos < size(); ++pos)
4296 return GetFontSettings(bparams, pos).language();
4297 return GetFirstFontSettings().language();
4301 return previous->getParLanguage(bparams);
4303 return bparams.language_info;
4307 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4309 return lyxrc.rtl_support && !table
4310 && getParLanguage(bparams)->RightToLeft();
4314 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4315 Language const * from, Language const * to)
4317 for(size_type i = 0; i < size(); ++i) {
4318 LyXFont font = GetFontSettings(bparams, i);
4319 if (font.language() == from) {
4320 font.setLanguage(to);
4327 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4329 Language const * doc_language =
4330 bparams.language_info;
4331 for(size_type i = 0; i < size(); ++i) {
4332 LyXFont font = GetFontSettings(bparams, i);
4333 if (font.language() != doc_language)
4340 // Convert the paragraph to a string.
4341 // Used for building the table of contents
4342 string LyXParagraph::String(BufferParams const & bparams, bool label)
4345 if (label && !IsDummy() && !labelstring.empty())
4346 s += labelstring + ' ';
4347 string::size_type len = s.size();
4349 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4350 unsigned char c = GetChar(i);
4353 else if (c == META_INSET &&
4354 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4356 std::ostringstream ost;
4357 GetInset(i)->Ascii(ost);
4360 GetInset(i)->Ascii(ost);
4363 s += subst(ost.str(),'\n',' ');
4367 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4368 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4369 s += NextAfterFootnote()->String(bparams, false);
4372 if (isRightToLeftPar(bparams))
4373 reverse(s.begin() + len,s.end());
4379 string LyXParagraph::String(LyXParagraph::size_type beg,
4380 LyXParagraph::size_type end)
4387 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4389 if (cell >= table->NumberOfCellsInRow(actcell))
4397 if (beg == 0 && !IsDummy() && !labelstring.empty())
4398 s += labelstring + ' ';
4400 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4401 unsigned char c = GetChar(i);
4404 else if (c == META_INSET) {
4406 std::ostringstream ost;
4407 GetInset(i)->Ascii(ost);
4410 GetInset(i)->Ascii(ost);
4414 } else if (table && IsNewlineChar(c)) {
4415 if (cell >= table->NumberOfCellsInRow(actcell)) {
4426 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4427 // s += NextAfterFootnote()->String(false);