#include "buffer.h"
#include "bufferlist.h"
-#include "lyx_main.h"
+#include "counters.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
#include "ParagraphParameters.h"
#include "iterators.h"
#include "lyxtextclasslist.h"
+#include "sgml.h"
#include "mathed/formulamacro.h"
#include "mathed/formula.h"
#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
+#include "graphics/Previews.h"
+
#include "support/textutils.h"
#include "support/filetools.h"
#include "support/path.h"
#include "support/lyxmanip.h"
#include "support/lyxalgo.h" // for lyx::count
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+
#include <fstream>
#include <iomanip>
#include <map>
#include <sys/types.h>
#include <utime.h>
-
#ifdef HAVE_LOCALE
#include <locale>
#endif
using std::set;
using std::stack;
using std::list;
+using std::for_each;
using lyx::pos_type;
using lyx::textclass_type;
// all these externs should eventually be removed.
extern BufferList bufferlist;
-extern LyXAction lyxaction;
-
namespace {
const int LYX_FORMAT = 220;
} // namespace anon
-extern int tex_code_break_column;
-
-
Buffer::Buffer(string const & file, bool ronly)
- : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
+ : niceFile(true), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly),
- filename_(file), users(0)
+ filename_(file), users(0), ctrs(new Counters)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// filename = file;
filepath_ = OnlyPath(file);
-// paragraph = 0;
// lyx_clean = true;
// bak_clean = true;
// dep_clean = 0;
DestroyBufferTmpDir(tmppath);
}
- Paragraph * par = paragraph;
- Paragraph * tmppar;
- while (par) {
- tmppar = par->next();
- delete par;
- par = tmppar;
- }
- paragraph = 0;
+ paragraphs.clear();
+
+ // Remove any previewed LaTeX snippets assocoated with this buffer.
+ grfx::Previews::get().removeLoader(this);
}
if (read_only != flag) {
read_only = flag;
updateTitles();
- users->owner()->getDialogs()->updateBufferDependent(false);
+ users->owner()->getDialogs().updateBufferDependent(false);
}
}
if (!par) {
par = new Paragraph;
- par->layout(textclasslist[params.textclass].defaultLayout());
+ par->layout(params.getLyXTextClass().defaultLayout());
} else {
// We are inserting into an existing document
users->text->breakParagraph(users);
if (!first_par)
first_par = par;
- paragraph = first_par;
+ paragraphs.set(first_par);
if (unknown_layouts > 0) {
string s = _("Couldn't set the layout for ");
last = last->next();
// create the new paragraph after the last one
Paragraph * par = new Paragraph(last);
- par->layout(textclasslist[params.textclass].defaultLayoutName());
+ par->layout(params.getLyXTextClass().defaultLayoutName());
par->setInsetOwner(last->inInset());
// set the contents
LyXFont font(LyXFont::ALL_INHERIT, params.language);
lex.eatLine();
string layoutname = lex.getString();
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
if (layoutname.empty()) {
layoutname = tclass.defaultLayoutName();
}
#ifndef NO_COMPABILITY
- if (compare_no_case(layoutname, "latex") == 0) {
+ if (compare_ascii_no_case(layoutname, "latex") == 0) {
ert_comp.active = true;
ert_comp.fromlayout = true;
ert_comp.font = font;
#ifdef USE_CAPTION
// The is the compability reading of layout caption.
// It can be removed in LyX version 1.3.0. (Lgb)
- if (compare_no_case(layoutname, "caption") == 0) {
+ if (compare_ascii_no_case(layoutname, "caption") == 0) {
// We expect that the par we are now working on is
// really inside a InsetText inside a InsetFloat.
// We also know that captions can only be
first_par = par;
else {
par = new Paragraph(par);
- par->layout(textclasslist[params.textclass].defaultLayout());
+ par->layout(params.getLyXTextClass().defaultLayout());
}
pos = 0;
- par->layout(textclasslist[params.textclass][layoutname]);
+ par->layout(params.getLyXTextClass()[layoutname]);
// Test whether the layout is obsolete.
LyXLayout_ptr const & layout = par->layout();
if (!layout->obsoleted_by().empty())
- par->layout(textclasslist[params.textclass][layout->obsoleted_by()]);
+ par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
par->params().depth(depth);
#ifndef NO_COMPABILITY
} else {
par->layout(layoutname);
// Test whether the layout is obsolete.
LyXLayout_ptr const & layout =
- textclasslist[params.textclass][par->layout()];
+ params.getLyXTextClass()[par->layout()];
if (!layout->obsoleted_by().empty())
par->layout(layout->obsoleted_by());
par->params().depth(depth);
old_float << "collapsed true\n";
} else if (tmptok == "fig") {
inset = new InsetFloat(params, "figure");
- old_float << "placement htbp\n"
- << "wide false\n"
+ old_float << "wide false\n"
<< "collapsed false\n";
} else if (tmptok == "tab") {
inset = new InsetFloat(params, "table");
- old_float << "placement htbp\n"
- << "wide false\n"
+ old_float << "wide false\n"
<< "collapsed false\n";
} else if (tmptok == "alg") {
inset = new InsetFloat(params, "algorithm");
- old_float << "placement htbp\n"
- << "wide false\n"
+ old_float << "wide false\n"
<< "collapsed false\n";
} else if (tmptok == "wide-fig") {
inset = new InsetFloat(params, "figure");
//InsetFloat * tmp = new InsetFloat("figure");
//tmp->wide(true);
//inset = tmp;
- old_float << "placement htbp\n"
- << "wide true\n"
+ old_float << "wide true\n"
<< "collapsed false\n";
} else if (tmptok == "wide-tab") {
inset = new InsetFloat(params, "table");
//InsetFloat * tmp = new InsetFloat("table");
//tmp->wide(true);
//inset = tmp;
- old_float << "placement htbp\n"
- << "wide true\n"
+ old_float << "wide true\n"
<< "collapsed false\n";
}
string(_("LyX will not be able to produce output correctly.")));
params.textclass = 0;
}
- if (!textclasslist[params.textclass].load()) {
+ if (!params.getLyXTextClass().load()) {
// if the textclass wasn't loaded properly
// we need to either substitute another
// or stop loading the file.
// stop loading... ideas?? ARRae980418
Alert::alert(_("Textclass Loading Error!"),
string(_("Can't load textclass ")) +
- textclasslist[params.textclass].name(),
+ params.getLyXTextClass().name(),
_("-- substituting default"));
params.textclass = 0;
}
int tmpret = lex.findToken(string_paragraph_separation);
if (tmpret == -1)
++tmpret;
- if (tmpret != LYX_LAYOUT_DEFAULT)
- params.paragraph_separation =
- static_cast<BufferParams::PARSEP>(tmpret);
+ params.paragraph_separation =
+ static_cast<BufferParams::PARSEP>(tmpret);
} else if (token == "\\defskip") {
lex.nextToken();
params.defskip = VSpace(lex.getString());
int tmpret = lex.findToken(string_quotes_language);
if (tmpret == -1)
++tmpret;
- if (tmpret != LYX_LAYOUT_DEFAULT) {
- InsetQuotes::quote_language tmpl =
- InsetQuotes::EnglishQ;
- switch (tmpret) {
- case 0:
- tmpl = InsetQuotes::EnglishQ;
- break;
- case 1:
- tmpl = InsetQuotes::SwedishQ;
- break;
- case 2:
- tmpl = InsetQuotes::GermanQ;
- break;
- case 3:
- tmpl = InsetQuotes::PolishQ;
- break;
- case 4:
- tmpl = InsetQuotes::FrenchQ;
- break;
- case 5:
- tmpl = InsetQuotes::DanishQ;
- break;
- }
- params.quotes_language = tmpl;
+ InsetQuotes::quote_language tmpl =
+ InsetQuotes::EnglishQ;
+ switch (tmpret) {
+ case 0:
+ tmpl = InsetQuotes::EnglishQ;
+ break;
+ case 1:
+ tmpl = InsetQuotes::SwedishQ;
+ break;
+ case 2:
+ tmpl = InsetQuotes::GermanQ;
+ break;
+ case 3:
+ tmpl = InsetQuotes::PolishQ;
+ break;
+ case 4:
+ tmpl = InsetQuotes::FrenchQ;
+ break;
+ case 5:
+ tmpl = InsetQuotes::DanishQ;
+ break;
}
+ params.quotes_language = tmpl;
} else if (token == "\\quotes_times") {
lex.nextToken();
switch (lex.getInteger()) {
int tmpret = lex.findToken(string_orientation);
if (tmpret == -1)
++tmpret;
- if (tmpret != LYX_LAYOUT_DEFAULT)
- params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
+ params.orientation =
+ static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
} else if (token == "\\paperwidth") {
lex.next();
params.paperwidth = lex.getString();
params.footskip = lex.getString();
} else if (token == "\\paperfontsize") {
lex.nextToken();
- params.fontsize = strip(lex.getString());
+ params.fontsize = rtrim(lex.getString());
} else if (token == "\\papercolumns") {
lex.nextToken();
params.columns = lex.getInteger();
}
} else if (token == "\\paperpagestyle") {
lex.nextToken();
- params.pagestyle = strip(lex.getString());
+ params.pagestyle = rtrim(lex.getString());
} else if (token == "\\bullet") {
lex.nextToken();
int const index = lex.getInteger();
params.tocdepth = lex.getInteger();
} else if (token == "\\spacing") {
lex.next();
- string const tmp = strip(lex.getString());
+ string const tmp = rtrim(lex.getString());
Spacing::Space tmp_space = Spacing::Default;
float tmp_val = 0.0;
if (tmp == "single") {
}
} else if (token == "\\paragraph_spacing") {
lex.next();
- string const tmp = strip(lex.getString());
+ string const tmp = rtrim(lex.getString());
if (tmp == "single") {
par->params().spacing(Spacing(Spacing::Single));
} else if (tmp == "onehalf") {
} else if (token == "\\align") {
int tmpret = lex.findToken(string_align);
if (tmpret == -1) ++tmpret;
- if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
- int const tmpret2 = int(pow(2.0, tmpret));
- //lyxerr << "Tmpret2 = " << tmpret2 << endl;
- par->params().align(LyXAlignment(tmpret2));
- }
+ int const tmpret2 = int(pow(2.0, tmpret));
+ par->params().align(LyXAlignment(tmpret2));
} else if (token == "\\added_space_top") {
lex.nextToken();
VSpace value = VSpace(lex.getString());
if (par->params().pextraStartMinipage() &&
!par->params().pextraHfill()) {
Paragraph * p = new Paragraph;
- p->layout(textclasslist[params.textclass].defaultLayoutName());
+ p->layout(params.getLyXTextClass().defaultLayoutName());
p->previous(parBeforeMinipage);
parBeforeMinipage->next(p);
// a sequence of minipages
// in its own paragraph.
Paragraph * p = new Paragraph;
- p->layout(textclasslist[params.textclass].defaultLayoutName());
+ p->layout(params.getLyXTextClass().defaultLayoutName());
p->previous(par->previous());
p->next(0);
p->params().depth(depth);
for(string::const_iterator cit = str.begin();
cit != str.end(); ++cit) {
if (*cit == '\n') {
- if (autobreakrows && (par->size() || layout->keepempty)) {
+ if (autobreakrows && (!par->empty() || layout->keepempty)) {
par->breakParagraph(params, pos,
layout->isEnvironment());
par = par->next();
// This strange command allows LyX to recognize "natbib" style
// citations: citet, citep, Citet etc.
- if (compare_no_case(cmdName, "cite", 4) == 0) {
+ if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
inset = new InsetCitation(inscmd);
} else if (cmdName == "bibitem") {
lex.printError("Wrong place for bibitem");
"Use LyX 0.10.x to read this!"));
return false;
} else if (file_format < 220) {
- Alert::alert(_("ERROR!"),
- _("Old LyX file format found. "
- "Use LyX 1.2.x to read this!"));
- return false;
+ string const command = "lyx2lyx "
+ + QuoteName(filename_);
+ cmd_ret const ret = RunCommand(command);
+ if (ret.first) {
+ Alert::alert(_("ERROR!"),
+ _("An error occured while "
+ "running the conversion script."));
+ return false;
+ }
+ istringstream is(ret.second);
+ LyXLex tmplex(0, 0);
+ tmplex.setStream(is);
+ return readFile(tmplex);
}
}
bool the_end = readLyXformat2(lex, par);
}
}
- if (writeFile(fileName(), false)) {
- markLyxClean();
+ if (writeFile(fileName())) {
+ markClean();
removeAutosaveFile(fileName());
} else {
// Saving failed, so backup is not backup
}
-// Returns false if unsuccesful
-bool Buffer::writeFile(string const & fname, bool flag) const
+bool Buffer::writeFile(string const & fname) const
{
- // if flag is false writeFile will not create any GUI
- // warnings, only cerr.
- // Needed for autosave in background or panic save (Matthias 120496)
-
if (read_only && (fname == fileName())) {
- // Here we should come with a question if we should
- // perform the write anyway.
- if (flag)
- lyxerr << _("Error! Document is read-only: ")
- << fname << endl;
- else
- Alert::alert(_("Error! Document is read-only: "),
- fname);
return false;
}
FileInfo finfo(fname);
if (finfo.exist() && !finfo.writable()) {
- // Here we should come with a question if we should
- // try to do the save anyway. (i.e. do a chmod first)
- if (flag)
- lyxerr << _("Error! Cannot write file: ")
- << fname << endl;
- else
- Alert::err_alert(_("Error! Cannot write file: "),
- fname);
return false;
}
ofstream ofs(fname.c_str());
if (!ofs) {
- if (flag)
- lyxerr << _("Error! Cannot open file: ")
- << fname << endl;
- else
- Alert::err_alert(_("Error! Cannot open file: "),
- fname);
return false;
}
// this will write out all the paragraphs
// using recursive descent.
- paragraph->writeFile(this, ofs, params, depth);
+ paragraphs.begin()->writeFile(this, ofs, params, depth);
// Write marker that shows file is complete
ofs << "\n\\the_end" << endl;
if (compare_no_case(tmp, "itemize") == 0) {
ltype = 1;
ltype_depth = depth + 1;
- } else if (compare_no_case(tmp, "enumerate") == 0) {
+ } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
ltype = 2;
ltype_depth = depth + 1;
- } else if (contains(lowercase(tmp), "ection")) {
+ } else if (contains(ascii_lowercase(tmp), "ection")) {
ltype = 3;
ltype_depth = depth + 1;
- } else if (contains(lowercase(tmp), "aragraph")) {
+ } else if (contains(ascii_lowercase(tmp), "aragraph")) {
ltype = 4;
ltype_depth = depth + 1;
- } else if (compare_no_case(tmp, "description") == 0) {
+ } else if (compare_ascii_no_case(tmp, "description") == 0) {
ltype = 5;
ltype_depth = depth + 1;
- } else if (compare_no_case(tmp, "abstract") == 0) {
+ } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
ltype = 6;
ltype_depth = 0;
- } else if (compare_no_case(tmp, "bibliography") == 0) {
+ } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
ltype = 7;
ltype_depth = 0;
} else {
void Buffer::writeFileAscii(ostream & ofs, int linelen)
{
- Paragraph * par = paragraph;
- while (par) {
- ofs << asciiParagraph(par, linelen, par->previous() == 0);
- par = par->next();
+ ParagraphList::iterator beg = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ ParagraphList::iterator it = beg;
+ for (; it != end; ++it) {
+ ofs << asciiParagraph(&*it, linelen, it == beg);
}
ofs << "\n";
}
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
- bool nice, bool only_body)
+ bool nice, bool only_body, bool only_preamble)
{
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
return;
}
- niceFile = nice; // this will be used by Insetincludes.
+ makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
+
+ ofs.close();
+ if (ofs.fail()) {
+ lyxerr << "File was not closed properly." << endl;
+ }
+}
- tex_code_break_column = lyxrc.ascii_linelen;
+
+void Buffer::makeLaTeXFile(ostream & os,
+ string const & original_path,
+ bool nice, bool only_body, bool only_preamble)
+{
+ niceFile = nice; // this will be used by Insetincludes.
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
texrow.reset();
// The starting paragraph of the coming rows is the
// first paragraph of the document. (Asger)
- texrow.start(paragraph, 0);
+ texrow.start(&*(paragraphs.begin()), 0);
if (!only_body && nice) {
- ofs << "%% " << lyx_docversion << " created this file. "
+ os << "%% " << lyx_docversion << " created this file. "
"For more info, see http://www.lyx.org/.\n"
"%% Do not edit unless you really know what "
"you are doing.\n";
// usual is \batchmode and has a
// special input@path to allow the including of figures
// with either \input or \includegraphics (what figinsets do).
- // batchmode is not set if there is a tex_code_break_column.
- // In this case somebody is interested in the generated LaTeX,
- // so this is OK. input@path is set when the actual parameter
+ // input@path is set when the actual parameter
// original_path is set. This is done for usual tex-file, but not
// for nice-latex-file. (Matthias 250696)
if (!only_body) {
if (!nice) {
// code for usual, NOT nice-latex-file
- ofs << "\\batchmode\n"; // changed
+ os << "\\batchmode\n"; // changed
// from \nonstopmode
texrow.newline();
}
if (!original_path.empty()) {
string inputpath = os::external_path(original_path);
subst(inputpath, "~", "\\string~");
- ofs << "\\makeatletter\n"
+ os << "\\makeatletter\n"
<< "\\def\\input@path{{"
<< inputpath << "/}}\n"
<< "\\makeatother\n";
texrow.newline();
}
- ofs << "\\documentclass";
+ os << "\\documentclass";
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
ostringstream options; // the document class options.
string strOptions(options.str().c_str());
if (!strOptions.empty()) {
- strOptions = strip(strOptions, ',');
- ofs << '[' << strOptions << ']';
+ strOptions = rtrim(strOptions, ",");
+ os << '[' << strOptions << ']';
}
- ofs << '{' << tclass.latexname() << "}\n";
+ os << '{' << tclass.latexname() << "}\n";
texrow.newline();
// end of \documentclass defs
// The ae package is not needed when using OT1 font encoding.
if (params.fonts != "default" &&
(params.fonts != "ae" || lyxrc.fontenc != "default")) {
- ofs << "\\usepackage{" << params.fonts << "}\n";
+ os << "\\usepackage{" << params.fonts << "}\n";
texrow.newline();
if (params.fonts == "ae") {
- ofs << "\\usepackage{aecompl}\n";
+ os << "\\usepackage{aecompl}\n";
texrow.newline();
}
}
// this one is not per buffer
if (lyxrc.fontenc != "default") {
- ofs << "\\usepackage[" << lyxrc.fontenc
+ os << "\\usepackage[" << lyxrc.fontenc
<< "]{fontenc}\n";
texrow.newline();
}
// in the document
set<string> encodings = features.getEncodingSet(doc_encoding);
- ofs << "\\usepackage[";
+ os << "\\usepackage[";
std::copy(encodings.begin(), encodings.end(),
- std::ostream_iterator<string>(ofs, ","));
- ofs << doc_encoding << "]{inputenc}\n";
+ std::ostream_iterator<string>(os, ","));
+ os << doc_encoding << "]{inputenc}\n";
texrow.newline();
} else if (params.inputenc != "default") {
- ofs << "\\usepackage[" << params.inputenc
+ os << "\\usepackage[" << params.inputenc
<< "]{inputenc}\n";
texrow.newline();
}
if (params.paperpackage != BufferParams::PACKAGE_NONE) {
switch (params.paperpackage) {
case BufferParams::PACKAGE_A4:
- ofs << "\\usepackage{a4}\n";
+ os << "\\usepackage{a4}\n";
texrow.newline();
break;
case BufferParams::PACKAGE_A4WIDE:
- ofs << "\\usepackage{a4wide}\n";
+ os << "\\usepackage{a4wide}\n";
texrow.newline();
break;
case BufferParams::PACKAGE_WIDEMARGINSA4:
- ofs << "\\usepackage[widemargins]{a4}\n";
+ os << "\\usepackage[widemargins]{a4}\n";
texrow.newline();
break;
}
}
if (params.use_geometry) {
- ofs << "\\usepackage{geometry}\n";
+ os << "\\usepackage{geometry}\n";
texrow.newline();
- ofs << "\\geometry{verbose";
+ os << "\\geometry{verbose";
if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
- ofs << ",landscape";
+ os << ",landscape";
switch (params.papersize2) {
case BufferParams::VM_PAPER_CUSTOM:
if (!params.paperwidth.empty())
- ofs << ",paperwidth="
+ os << ",paperwidth="
<< params.paperwidth;
if (!params.paperheight.empty())
- ofs << ",paperheight="
+ os << ",paperheight="
<< params.paperheight;
break;
case BufferParams::VM_PAPER_USLETTER:
- ofs << ",letterpaper";
+ os << ",letterpaper";
break;
case BufferParams::VM_PAPER_USLEGAL:
- ofs << ",legalpaper";
+ os << ",legalpaper";
break;
case BufferParams::VM_PAPER_USEXECUTIVE:
- ofs << ",executivepaper";
+ os << ",executivepaper";
break;
case BufferParams::VM_PAPER_A3:
- ofs << ",a3paper";
+ os << ",a3paper";
break;
case BufferParams::VM_PAPER_A4:
- ofs << ",a4paper";
+ os << ",a4paper";
break;
case BufferParams::VM_PAPER_A5:
- ofs << ",a5paper";
+ os << ",a5paper";
break;
case BufferParams::VM_PAPER_B3:
- ofs << ",b3paper";
+ os << ",b3paper";
break;
case BufferParams::VM_PAPER_B4:
- ofs << ",b4paper";
+ os << ",b4paper";
break;
case BufferParams::VM_PAPER_B5:
- ofs << ",b5paper";
+ os << ",b5paper";
break;
default:
// default papersize ie BufferParams::VM_PAPER_DEFAULT
switch (lyxrc.default_papersize) {
case BufferParams::PAPER_DEFAULT: // keep compiler happy
case BufferParams::PAPER_USLETTER:
- ofs << ",letterpaper";
+ os << ",letterpaper";
break;
case BufferParams::PAPER_LEGALPAPER:
- ofs << ",legalpaper";
+ os << ",legalpaper";
break;
case BufferParams::PAPER_EXECUTIVEPAPER:
- ofs << ",executivepaper";
+ os << ",executivepaper";
break;
case BufferParams::PAPER_A3PAPER:
- ofs << ",a3paper";
+ os << ",a3paper";
break;
case BufferParams::PAPER_A4PAPER:
- ofs << ",a4paper";
+ os << ",a4paper";
break;
case BufferParams::PAPER_A5PAPER:
- ofs << ",a5paper";
+ os << ",a5paper";
break;
case BufferParams::PAPER_B5PAPER:
- ofs << ",b5paper";
+ os << ",b5paper";
break;
}
}
if (!params.topmargin.empty())
- ofs << ",tmargin=" << params.topmargin;
+ os << ",tmargin=" << params.topmargin;
if (!params.bottommargin.empty())
- ofs << ",bmargin=" << params.bottommargin;
+ os << ",bmargin=" << params.bottommargin;
if (!params.leftmargin.empty())
- ofs << ",lmargin=" << params.leftmargin;
+ os << ",lmargin=" << params.leftmargin;
if (!params.rightmargin.empty())
- ofs << ",rmargin=" << params.rightmargin;
+ os << ",rmargin=" << params.rightmargin;
if (!params.headheight.empty())
- ofs << ",headheight=" << params.headheight;
+ os << ",headheight=" << params.headheight;
if (!params.headsep.empty())
- ofs << ",headsep=" << params.headsep;
+ os << ",headsep=" << params.headsep;
if (!params.footskip.empty())
- ofs << ",footskip=" << params.footskip;
- ofs << "}\n";
+ os << ",footskip=" << params.footskip;
+ os << "}\n";
texrow.newline();
}
if (tokenPos(tclass.opt_pagestyle(),
'|', params.pagestyle) >= 0) {
if (params.pagestyle == "fancy") {
- ofs << "\\usepackage{fancyhdr}\n";
+ os << "\\usepackage{fancyhdr}\n";
texrow.newline();
}
- ofs << "\\pagestyle{" << params.pagestyle << "}\n";
+ os << "\\pagestyle{" << params.pagestyle << "}\n";
texrow.newline();
}
if (params.secnumdepth != tclass.secnumdepth()) {
- ofs << "\\setcounter{secnumdepth}{"
+ os << "\\setcounter{secnumdepth}{"
<< params.secnumdepth
<< "}\n";
texrow.newline();
}
if (params.tocdepth != tclass.tocdepth()) {
- ofs << "\\setcounter{tocdepth}{"
+ os << "\\setcounter{tocdepth}{"
<< params.tocdepth
<< "}\n";
texrow.newline();
if (params.paragraph_separation) {
switch (params.defskip.kind()) {
case VSpace::SMALLSKIP:
- ofs << "\\setlength\\parskip{\\smallskipamount}\n";
+ os << "\\setlength\\parskip{\\smallskipamount}\n";
break;
case VSpace::MEDSKIP:
- ofs << "\\setlength\\parskip{\\medskipamount}\n";
+ os << "\\setlength\\parskip{\\medskipamount}\n";
break;
case VSpace::BIGSKIP:
- ofs << "\\setlength\\parskip{\\bigskipamount}\n";
+ os << "\\setlength\\parskip{\\bigskipamount}\n";
break;
case VSpace::LENGTH:
- ofs << "\\setlength\\parskip{"
+ os << "\\setlength\\parskip{"
<< params.defskip.length().asLatexString()
<< "}\n";
break;
default: // should never happen // Then delete it.
- ofs << "\\setlength\\parskip{\\medskipamount}\n";
+ os << "\\setlength\\parskip{\\medskipamount}\n";
break;
}
texrow.newline();
- ofs << "\\setlength\\parindent{0pt}\n";
+ os << "\\setlength\\parindent{0pt}\n";
texrow.newline();
}
preamble += "\\makeatother\n";
- ofs << preamble;
+ os << preamble;
+
+ if (only_preamble)
+ return;
// make the body.
- ofs << "\\begin{document}\n";
+ os << "\\begin{document}\n";
texrow.newline();
} // only_body
lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
if (!lyxrc.language_auto_begin) {
- ofs << subst(lyxrc.language_command_begin, "$$lang",
+ os << subst(lyxrc.language_command_begin, "$$lang",
params.language->babel())
<< endl;
texrow.newline();
}
- latexParagraphs(ofs, paragraph, 0, texrow);
+ latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
// add this just in case after all the paragraphs
- ofs << endl;
+ os << endl;
texrow.newline();
if (!lyxrc.language_auto_end) {
- ofs << subst(lyxrc.language_command_end, "$$lang",
+ os << subst(lyxrc.language_command_end, "$$lang",
params.language->babel())
<< endl;
texrow.newline();
}
if (!only_body) {
- ofs << "\\end{document}\n";
+ os << "\\end{document}\n";
texrow.newline();
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
// Just to be sure. (Asger)
texrow.newline();
- // tex_code_break_column's value is used to decide
- // if we are in batchmode or not (within mathed_write()
- // in math_write.C) so we must set it to a non-zero
- // value when we leave otherwise we save incorrect .lyx files.
- tex_code_break_column = lyxrc.ascii_linelen;
-
- ofs.close();
- if (ofs.fail()) {
- lyxerr << "File was not closed properly." << endl;
- }
-
lyxerr[Debug::INFO] << "Finished making latex file." << endl;
lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
bool Buffer::isLatex() const
{
- return textclasslist[params.textclass].outputType() == LATEX;
+ return params.getLyXTextClass().outputType() == LATEX;
}
bool Buffer::isLinuxDoc() const
{
- return textclasslist[params.textclass].outputType() == LINUXDOC;
+ return params.getLyXTextClass().outputType() == LINUXDOC;
}
bool Buffer::isLiterate() const
{
- return textclasslist[params.textclass].outputType() == LITERATE;
+ return params.getLyXTextClass().outputType() == LITERATE;
}
bool Buffer::isDocBook() const
{
- return textclasslist[params.textclass].outputType() == DOCBOOK;
+ return params.getLyXTextClass().outputType() == DOCBOOK;
}
bool Buffer::isSGML() const
{
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
return tclass.outputType() == LINUXDOC ||
tclass.outputType() == DOCBOOK;
texrow.reset();
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
string top_element = tclass.latexname();
<< " -->\n";
Paragraph::depth_type depth = 0; // paragraph depth
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
string item_name;
vector<string> environment_stack(5);
os << c;
++char_line_count;
} else {
- string sgml_string;
- if (par->sgmlConvertChar(c, sgml_string)
- && !style->free_spacing && !par->isFreeSpacing())
- {
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
+ if (ws && !style->free_spacing && !par->isFreeSpacing()) {
// in freespacing mode, spaces are
// non-breaking characters
if (desc_on) {// if char is ' ' then...
os << c;
}
} else {
- os << sgml_string;
- char_line_count += sgml_string.length();
+ os << str;
+ char_line_count += str.length();
}
}
font_old = font;
return;
}
- Paragraph * par = paragraph;
+ Paragraph * par = &*(paragraphs.begin());
niceFile = nice; // this will be used by Insetincludes.
texrow.reset();
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
string top_element = tclass.latexname();
if (!only_body) {
}
} else {
char c = par->getChar(i);
- string sgml_string;
- par->sgmlConvertChar(c, sgml_string);
+ bool ws;
+ string str;
+ boost::tie(ws, str) = sgml::escapeChar(c);
if (style->pass_thru) {
os << c;
} else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
- os << sgml_string;
+ os << str;
} else if (desc_on ==1) {
++char_line_count;
os << "\n</term><listitem><para>";
void Buffer::validate(LaTeXFeatures & features) const
{
- Paragraph * par = paragraph;
- LyXTextClass const & tclass = textclasslist[params.textclass];
+ LyXTextClass const & tclass = params.getLyXTextClass();
// AMS Style is at document level
if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
features.require("amsmath");
- while (par) {
- // We don't use "lyxerr.debug" because of speed. (Asger)
- if (lyxerr.debugging(Debug::LATEX))
- lyxerr << "Paragraph: " << par << endl;
-
- // Now just follow the list of paragraphs and run
- // validate on each of them.
- par->validate(features);
-
- // and then the next paragraph
- par = par->next();
- }
+ for_each(paragraphs.begin(), paragraphs.end(),
+ boost::bind(&Paragraph::validate, _1, boost::ref(features)));
// the bullet shapes are buffer level not paragraph level
// so they are tested here
}
-vector<string> const Buffer::getLabelList()
+vector<string> const Buffer::getLabelList() const
{
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990407]
if (!params.parentname.empty()
&& bufferlist.exists(params.parentname)) {
- Buffer * tmp = bufferlist.getBuffer(params.parentname);
+ Buffer const * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getLabelList();
}
vector<string> label_list;
- for (inset_iterator it = inset_iterator_begin();
- it != inset_iterator_end(); ++it) {
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it) {
vector<string> const l = (*it)->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
}
-Buffer::Lists const Buffer::getLists() const
-{
- Lists l;
- Paragraph * par = paragraph;
-
- LyXTextClass const & textclass = textclasslist[params.textclass];
- bool found = textclass.hasLayout("Caption");
- string const layout("Caption");
-
- while (par) {
-#warning bogus type (Lgb)
- char const labeltype = par->layout()->labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
- // insert this into the table of contents
- SingleList & item = l["TOC"];
- int depth = max(0,
- labeltype -
- textclass.maxcounter());
- item.push_back(TocItem(par, depth, par->asString(this, true)));
- }
- // For each paragrph, traverse its insets and look for
- // FLOAT_CODE
-
- if (found) {
- Paragraph::inset_iterator it =
- par->inset_iterator_begin();
- Paragraph::inset_iterator end =
- par->inset_iterator_end();
-
- for (; it != end; ++it) {
- if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
- InsetFloat * il =
- static_cast<InsetFloat*>(*it);
-
- string const type = il->type();
-
- // Now find the caption in the float...
- // We now tranverse the paragraphs of
- // the inset...
- Paragraph * tmp = il->inset.paragraph();
- while (tmp) {
- if (tmp->layout()->name() == layout) {
- SingleList & item = l[type];
- string const str =
- tostr(item.size()+1) + ". " + tmp->asString(this, false);
- item.push_back(TocItem(tmp, 0 , str));
- }
- tmp = tmp->next();
- }
- }
- }
- } else {
- lyxerr << "Caption not found" << endl;
- }
-
- par = par->next();
- }
- return l;
-}
-
-
// This is also a buffer property (ale)
vector<pair<string, string> > const Buffer::getBibkeyList() const
{
}
vector<StringPair> keys;
- Paragraph * par = paragraph;
- while (par) {
- if (par->bibkey) {
- string const key = par->bibkey->getContents();
- string const opt = par->bibkey->getOptions();
- string const ref = par->asString(this, false);
+ ParagraphList::iterator pit = paragraphs.begin();
+ ParagraphList::iterator pend = paragraphs.end();
+ for (; pit != pend; ++pit) {
+ if (pit->bibkey) {
+ string const key = pit->bibkey->getContents();
+ string const opt = pit->bibkey->getOptions();
+ string const ref = pit->asString(this, false);
string const info = opt + "TheBibliographyRef" + ref;
keys.push_back(StringPair(key, info));
}
- par = par->next();
}
// Might be either using bibtex or a child has bibliography
{
// Split command string into command and argument
string cmd;
- string line = frontStrip(command);
- string const arg = strip(frontStrip(split(line, cmd, ' ')));
+ string line = ltrim(command);
+ string const arg = trim(split(line, cmd, ' '));
return dispatch(lyxaction.LookupFunc(cmd), arg, result);
}
void Buffer::resizeInsets(BufferView * bv)
{
/// then remove all LyXText in text-insets
- Paragraph * par = paragraph;
- for (; par; par = par->next()) {
- par->resizeInsetsLyXText(bv);
- }
+ for_each(paragraphs.begin(), paragraphs.end(),
+ boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
}
}
+Counters & Buffer::counters() const
+{
+ return *ctrs.get();
+}
+
+
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
: par(paragraph)
{
- it = par->InsetIterator(pos);
- if (it == par->inset_iterator_end()) {
+ it = par->insetlist.insetIterator(pos);
+ if (it == par->insetlist.end()) {
par = par->next();
setParagraph();
}
void Buffer::inset_iterator::setParagraph()
{
while (par) {
- it = par->inset_iterator_begin();
- if (it != par->inset_iterator_end())
+ it = par->insetlist.begin();
+ if (it != par->insetlist.end())
return;
par = par->next();
}
Paragraph * Buffer::getParFromID(int id) const
{
- if (id < 0) return 0;
- Paragraph * par = paragraph;
- while (par) {
- if (par->id() == id) {
- return par;
+ if (id < 0)
+ return 0;
+
+ ParagraphList::iterator it = paragraphs.begin();
+ ParagraphList::iterator end = paragraphs.end();
+ for (; it != end; ++it) {
+ if (it->id() == id) {
+ return &*it;
}
- Paragraph * tmp = par->getParFromID(id);
+ Paragraph * tmp = it->getParFromID(id);
if (tmp) {
return tmp;
}
- par = par->next();
}
return 0;
}
ParIterator Buffer::par_iterator_begin()
{
- return ParIterator(paragraph);
+ return ParIterator(&*(paragraphs.begin()));
}