1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* This file is Copyright 1996-2001
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-05-03 14:31:33 +00:00
|
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.h"
|
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "lyx_gui_misc.h"
|
1999-12-10 00:07:59 +00:00
|
|
|
|
#include "LyXAction.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "tex-strings.h"
|
|
|
|
|
#include "layout.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxfont.h"
|
1999-12-15 17:42:22 +00:00
|
|
|
|
#include "version.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "LaTeX.h"
|
|
|
|
|
#include "Chktex.h"
|
|
|
|
|
#include "LyXView.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "encoding.h"
|
|
|
|
|
#include "exporter.h"
|
|
|
|
|
#include "Lsstream.h"
|
|
|
|
|
#include "converter.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "ParagraphParameters.h"
|
|
|
|
|
#include "iterators.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "lyxtextclasslist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "mathed/formulamacro.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "mathed/formula.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "insets/inset.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/inseterror.h"
|
|
|
|
|
#include "insets/insetlabel.h"
|
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
#include "insets/inseturl.h"
|
2001-07-20 09:57:23 +00:00
|
|
|
|
#include "insets/insetnote.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetquotes.h"
|
|
|
|
|
#include "insets/insetlatexaccent.h"
|
|
|
|
|
#include "insets/insetbib.h"
|
2000-06-07 08:53:40 +00:00
|
|
|
|
#include "insets/insetcite.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
#include "insets/insetexternal.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetindex.h"
|
|
|
|
|
#include "insets/insetinclude.h"
|
|
|
|
|
#include "insets/insettoc.h"
|
|
|
|
|
#include "insets/insetparent.h"
|
|
|
|
|
#include "insets/insetspecialchar.h"
|
|
|
|
|
#include "insets/figinset.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
#include "insets/insetert.h"
|
2000-02-29 02:19:17 +00:00
|
|
|
|
#include "insets/insetgraphics.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "insets/insetfoot.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "insets/insetmarginal.h"
|
|
|
|
|
#include "insets/insetminipage.h"
|
|
|
|
|
#include "insets/insetfloat.h"
|
2000-05-04 08:14:34 +00:00
|
|
|
|
#include "insets/insettabular.h"
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "insets/insettheorem.h"
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#include "insets/insetlist.h"
|
|
|
|
|
#endif
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "insets/insetcaption.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
#include "insets/insetfloatlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
#include "support/textutils.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/filetools.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
|
#include "support/path.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
#include "support/os.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/syscall.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
#include "support/FileInfo.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#include "support/lyxmanip.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-12-08 14:20:11 +00:00
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <stack>
|
|
|
|
|
#include <list>
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include <algorithm>
|
2001-12-08 14:20:11 +00:00
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
#include <locale>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::fstream;
|
|
|
|
|
using std::ios;
|
|
|
|
|
using std::setw;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
using std::make_pair;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::vector;
|
2001-03-12 08:52:37 +00:00
|
|
|
|
using std::map;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::max;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
using std::set;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
using std::stack;
|
|
|
|
|
using std::list;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
using lyx::layout_type;
|
|
|
|
|
using lyx::textclass_type;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// all these externs should eventually be removed.
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
extern LyXAction lyxaction;
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-07-08 13:00:28 +00:00
|
|
|
|
const int LYX_FORMAT = 220;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
extern int tex_code_break_column;
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer::Buffer(string const & file, bool ronly)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
filename = file;
|
|
|
|
|
filepath = OnlyPath(file);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
paragraph = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lyx_clean = true;
|
|
|
|
|
bak_clean = true;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
dep_clean = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
read_only = ronly;
|
2000-07-26 13:43:16 +00:00
|
|
|
|
unnamed = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
users = 0;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxvc.buffer(this);
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (read_only || (lyxrc.use_tempdir)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppath = CreateBufferTmpDir();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
} else tmppath.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::~Buffer()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// here the buffer should take care that it is
|
|
|
|
|
// saved properly, before it goes into the void.
|
|
|
|
|
|
|
|
|
|
// make sure that views using this buffer
|
|
|
|
|
// forgets it.
|
|
|
|
|
if (users)
|
1999-11-09 23:52:04 +00:00
|
|
|
|
users->buffer(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (!tmppath.empty()) {
|
|
|
|
|
DestroyBufferTmpDir(tmppath);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
|
|
|
|
Paragraph * tmppar;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
delete par;
|
|
|
|
|
par = tmppar;
|
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
|
paragraph = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getLatexName(bool no_path) const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2001-12-08 14:20:11 +00:00
|
|
|
|
string const name = ChangeExtension(MakeLatexName(filename), ".tex");
|
2000-05-11 16:12:46 +00:00
|
|
|
|
if (no_path)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return OnlyFilename(name);
|
2000-05-11 16:12:46 +00:00
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return name;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2001-02-09 15:54:30 +00:00
|
|
|
|
pair<Buffer::LogType, string> const Buffer::getLogName(void) const
|
2001-02-06 17:41:42 +00:00
|
|
|
|
{
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const filename = getLatexName(false);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty())
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, string());
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string path = OnlyPath(filename);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (lyxrc.use_tempdir || !IsDirWriteable(path))
|
2001-02-09 15:54:30 +00:00
|
|
|
|
path = tmppath;
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const fname = AddName(path,
|
|
|
|
|
OnlyFilename(ChangeExtension(filename,
|
|
|
|
|
".log")));
|
|
|
|
|
string const bname =
|
|
|
|
|
AddName(path, OnlyFilename(
|
|
|
|
|
ChangeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension("literate") + ".out")));
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
// If no Latex log or Build log is newer, show Build log
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
FileInfo const f_fi(fname);
|
|
|
|
|
FileInfo const b_fi(bname);
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-02-06 17:41:42 +00:00
|
|
|
|
if (b_fi.exist() &&
|
2001-03-14 14:54:30 +00:00
|
|
|
|
(!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
|
2001-02-09 15:54:30 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
|
|
|
|
|
return make_pair(Buffer::buildlog, bname);
|
|
|
|
|
}
|
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
|
|
|
|
|
return make_pair(Buffer::latexlog, fname);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
void Buffer::setReadonly(bool flag)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (read_only != flag) {
|
|
|
|
|
read_only = flag;
|
|
|
|
|
updateTitles();
|
2000-10-13 05:57:05 +00:00
|
|
|
|
users->owner()->getDialogs()->updateBufferDependent(false);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// Update window titles of all users
|
|
|
|
|
// Should work on a list
|
2000-02-22 00:36:17 +00:00
|
|
|
|
void Buffer::updateTitles() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-12-08 14:20:11 +00:00
|
|
|
|
if (users)
|
|
|
|
|
users->owner()->updateWindowTitle();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Reset autosave timer of all users
|
|
|
|
|
// Should work on a list
|
2000-02-22 00:36:17 +00:00
|
|
|
|
void Buffer::resetAutosaveTimers() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-12-08 14:20:11 +00:00
|
|
|
|
if (users)
|
|
|
|
|
users->owner()->resetAutosaveTimer();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-12 00:11:06 +00:00
|
|
|
|
void Buffer::setFileName(string const & newfile)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
filename = MakeAbsPath(newfile);
|
|
|
|
|
filepath = OnlyPath(filename);
|
|
|
|
|
setReadonly(IsFileWriteable(filename) == 0);
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
// We'll remove this later. (Lgb)
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string last_inset_read;
|
2001-07-10 22:36:25 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
struct ErtComp
|
|
|
|
|
{
|
|
|
|
|
ErtComp() : active(false), in_tabular(false) {
|
|
|
|
|
}
|
|
|
|
|
string contents;
|
|
|
|
|
bool active;
|
|
|
|
|
bool in_tabular;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::stack<ErtComp> ert_stack;
|
|
|
|
|
ErtComp ert_comp;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#warning And _why_ is this here? (Lgb)
|
2001-07-16 14:46:31 +00:00
|
|
|
|
int unknown_layouts;
|
2001-11-25 17:58:05 +00:00
|
|
|
|
int unknown_tokens;
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
2001-08-30 07:13:15 +00:00
|
|
|
|
} // anon
|
|
|
|
|
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
// candidate for move to BufferView
|
|
|
|
|
// (at least some parts in the beginning of the func)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Uwe C. Schroeder
|
|
|
|
|
// changed to be public and have one parameter
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// if par = 0 normal behavior
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// else insert behavior
|
|
|
|
|
// Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-16 14:46:31 +00:00
|
|
|
|
unknown_layouts = 0;
|
2001-11-25 17:58:05 +00:00
|
|
|
|
unknown_tokens = 0;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.contents.erase();
|
|
|
|
|
ert_comp.active = false;
|
|
|
|
|
ert_comp.in_tabular = false;
|
2001-07-09 23:12:04 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int pos = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool the_end_read = false;
|
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
Paragraph * first_par = 0;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, params.language);
|
2001-01-11 11:06:10 +00:00
|
|
|
|
if (file_format < 216 && params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par = new Paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We are inserting into an existing document
|
|
|
|
|
users->text->breakParagraph(users);
|
2001-07-09 23:12:04 +00:00
|
|
|
|
first_par = users->text->firstParagraph();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
pos = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
markDirty();
|
|
|
|
|
// We don't want to adopt the parameters from the
|
|
|
|
|
// document we insert, so we skip until the text begins:
|
2001-08-06 19:12:46 +00:00
|
|
|
|
while (lex.isOK()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const pretoken = lex.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (pretoken == "\\layout") {
|
2001-07-09 23:12:04 +00:00
|
|
|
|
lex.pushToken(pretoken);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
while (lex.isOK()) {
|
2001-07-09 23:12:04 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
|
|
|
|
if (token.empty()) continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
lyxerr[Debug::PARSER] << "Handling token: `"
|
|
|
|
|
<< token << "'" << endl;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
|
|
|
|
the_end_read =
|
2001-07-09 23:12:04 +00:00
|
|
|
|
parseSingleLyXformat2Token(lex, par, first_par,
|
|
|
|
|
token, pos, depth,
|
|
|
|
|
font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
if (!first_par)
|
|
|
|
|
first_par = par;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
paragraph = first_par;
|
2001-07-16 14:11:35 +00:00
|
|
|
|
|
2001-07-16 14:46:31 +00:00
|
|
|
|
if (unknown_layouts > 0) {
|
|
|
|
|
string s = _("Couldn't set the layout for ");
|
|
|
|
|
if (unknown_layouts == 1) {
|
|
|
|
|
s += _("one paragraph");
|
|
|
|
|
} else {
|
|
|
|
|
s += tostr(unknown_layouts);
|
|
|
|
|
s += _(" paragraphs");
|
2001-07-16 14:11:35 +00:00
|
|
|
|
}
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
2001-07-18 13:26:52 +00:00
|
|
|
|
_("When reading " + fileName()));
|
2001-11-25 17:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unknown_tokens > 0) {
|
|
|
|
|
string s = _("Encountered ");
|
|
|
|
|
if (unknown_tokens == 1) {
|
|
|
|
|
s += _("one unknown token");
|
|
|
|
|
} else {
|
|
|
|
|
s += tostr(unknown_tokens);
|
|
|
|
|
s += _(" unknown tokens");
|
|
|
|
|
}
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
2001-11-25 17:58:05 +00:00
|
|
|
|
_("When reading " + fileName()));
|
|
|
|
|
}
|
2001-07-16 14:11:35 +00:00
|
|
|
|
|
2000-03-01 14:13:21 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
void Buffer::insertErtContents(Paragraph * par, int & pos,
|
2001-12-08 14:20:11 +00:00
|
|
|
|
LyXFont const & f, bool set_inactive)
|
2001-07-08 12:52:16 +00:00
|
|
|
|
{
|
2001-07-10 22:36:25 +00:00
|
|
|
|
if (!ert_comp.contents.empty()) {
|
2001-12-08 14:20:11 +00:00
|
|
|
|
lyxerr[Debug::INSETS] << "ERT contents:\n'"
|
|
|
|
|
<< ert_comp.contents << "'" << endl;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
Inset * inset = new InsetERT(ert_comp.contents, true);
|
2001-12-08 14:20:11 +00:00
|
|
|
|
LyXFont font;
|
|
|
|
|
font.setLanguage(f.language());
|
2001-07-08 12:52:16 +00:00
|
|
|
|
par->insertInset(pos++, inset, font);
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.contents.erase();
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
if (set_inactive) {
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.active = false;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2001-07-08 12:52:16 +00:00
|
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
bool
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
|
2001-07-09 23:12:04 +00:00
|
|
|
|
Paragraph *& first_par,
|
2000-04-24 20:58:23 +00:00
|
|
|
|
string const & token, int & pos,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type & depth,
|
|
|
|
|
LyXFont & font
|
2000-07-19 17:16:27 +00:00
|
|
|
|
)
|
2000-03-01 14:13:21 +00:00
|
|
|
|
{
|
2001-03-22 15:45:15 +00:00
|
|
|
|
bool the_end_read = false;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-03-22 15:45:15 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2001-03-14 14:54:30 +00:00
|
|
|
|
// This is super temporary but is needed to get the compability
|
|
|
|
|
// mode for minipages work correctly together with new tabulars.
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static int call_depth;
|
2001-03-14 14:54:30 +00:00
|
|
|
|
++call_depth;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
bool checkminipage = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
static Paragraph * minipar;
|
|
|
|
|
static Paragraph * parBeforeMinipage;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
#endif
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (token[0] != '\\') {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
if (ert_comp.active) {
|
|
|
|
|
ert_comp.contents += token;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2000-04-24 20:58:23 +00:00
|
|
|
|
for (string::const_iterator cit = token.begin();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cit != token.end(); ++cit) {
|
|
|
|
|
par->insertChar(pos, (*cit), font);
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++pos;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\i") {
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Inset * inset = new InsetLatexAccent;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\layout") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.in_tabular = false;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
// Do the insetert.
|
2001-07-08 12:52:16 +00:00
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#endif
|
2001-11-29 17:12:21 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
string const layoutname = lex.getString();
|
2001-12-28 13:26:54 +00:00
|
|
|
|
//lyxerr << "Looking for layout '"
|
|
|
|
|
// << layoutname << "'!" << endl;
|
|
|
|
|
|
2001-11-29 17:12:21 +00:00
|
|
|
|
pair<bool, layout_type> pp
|
|
|
|
|
= textclasslist.NumberOfLayout(params.textclass, layoutname);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
//lyxerr << "Result: " << pp.first << "/" << pp.second << endl;
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
if (compare_no_case(layoutname, "latex") == 0) {
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.active = true;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#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) {
|
|
|
|
|
// 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
|
|
|
|
|
// one paragraph. (Lgb)
|
|
|
|
|
|
|
|
|
|
// We should now read until the next "\layout"
|
|
|
|
|
// is reached.
|
|
|
|
|
// This is probably not good enough, what if the
|
|
|
|
|
// caption is the last par in the document (Lgb)
|
|
|
|
|
istream & ist = lex.getStream();
|
|
|
|
|
stringstream ss;
|
|
|
|
|
string line;
|
|
|
|
|
int begin = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
getline(ist, line);
|
|
|
|
|
if (prefixIs(line, "\\layout")) {
|
|
|
|
|
lex.pushToken(line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (prefixIs(line, "\\begin_inset"))
|
|
|
|
|
++begin;
|
|
|
|
|
if (prefixIs(line, "\\end_inset")) {
|
|
|
|
|
if (begin)
|
|
|
|
|
--begin;
|
|
|
|
|
else {
|
|
|
|
|
lex.pushToken(line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ss << line << '\n';
|
|
|
|
|
}
|
|
|
|
|
// Now we should have the whole layout in ss
|
|
|
|
|
// we should now be able to give this to the
|
|
|
|
|
// caption inset.
|
|
|
|
|
ss << "\\end_inset\n";
|
|
|
|
|
|
|
|
|
|
// This seems like a bug in stringstream.
|
|
|
|
|
// We really should be able to use ss
|
|
|
|
|
// directly. (Lgb)
|
|
|
|
|
istringstream is(ss.str());
|
|
|
|
|
LyXLex tmplex(0, 0);
|
|
|
|
|
tmplex.setStream(is);
|
|
|
|
|
Inset * inset = new InsetCaption;
|
|
|
|
|
inset->Read(this, tmplex);
|
|
|
|
|
par->InsertInset(pos, inset, font);
|
|
|
|
|
++pos;
|
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2001-07-09 23:12:04 +00:00
|
|
|
|
if (!first_par)
|
|
|
|
|
first_par = par;
|
2001-03-11 03:20:44 +00:00
|
|
|
|
else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par = new Paragraph(par);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
pos = 0;
|
|
|
|
|
if (pp.first) {
|
|
|
|
|
par->layout = pp.second;
|
2001-08-13 21:46:19 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
|
|
|
|
} else if (ert_comp.active) {
|
|
|
|
|
par->layout = 0;
|
|
|
|
|
#endif
|
2001-03-11 03:20:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
// layout not found
|
|
|
|
|
// use default layout "Standard" (0)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
//lyxerr << "Layout '" << layoutname
|
|
|
|
|
// << "' was not found!" << endl;
|
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
par->layout = 0;
|
2001-07-16 14:46:31 +00:00
|
|
|
|
++unknown_layouts;
|
|
|
|
|
string const s = _("Layout had to be changed from\n")
|
|
|
|
|
+ layoutname + _(" to ")
|
|
|
|
|
+ textclasslist.NameOfLayout(params.textclass, par->layout);
|
|
|
|
|
InsetError * new_inset = new InsetError(s);
|
2001-12-15 14:34:17 +00:00
|
|
|
|
par->insertInset(0, new_inset,
|
|
|
|
|
LyXFont(LyXFont::ALL_INHERIT,
|
|
|
|
|
params.language));
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
// Test whether the layout is obsolete.
|
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
|
|
|
|
par->layout);
|
|
|
|
|
if (!layout.obsoleted_by().empty())
|
|
|
|
|
par->layout = textclasslist
|
|
|
|
|
.NumberOfLayout(params.textclass,
|
|
|
|
|
layout.obsoleted_by())
|
|
|
|
|
.second;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().depth(depth);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT, params.language);
|
|
|
|
|
if (file_format < 216
|
|
|
|
|
&& params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
2001-03-14 14:54:30 +00:00
|
|
|
|
#if USE_CAPTION
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (token == "\\begin_float") {
|
2001-08-02 18:46:53 +00:00
|
|
|
|
insertErtContents(par, pos, font);
|
|
|
|
|
//insertErtContents(par, pos, font, false);
|
|
|
|
|
//ert_stack.push(ert_comp);
|
|
|
|
|
//ert_comp = ErtComp();
|
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// This is the compability reader. It can be removed in
|
|
|
|
|
// LyX version 1.3.0. (Lgb)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmptok = lex.getString();
|
2000-06-28 13:35:52 +00:00
|
|
|
|
//lyxerr << "old float: " << tmptok << endl;
|
|
|
|
|
|
|
|
|
|
Inset * inset = 0;
|
2001-03-11 03:20:44 +00:00
|
|
|
|
stringstream old_float;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
if (tmptok == "footnote") {
|
|
|
|
|
inset = new InsetFoot;
|
2001-08-13 21:46:19 +00:00
|
|
|
|
old_float << "collapsed true\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "margin") {
|
|
|
|
|
inset = new InsetMarginal;
|
2001-08-13 21:46:19 +00:00
|
|
|
|
old_float << "collapsed true\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "fig") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("figure");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
2001-08-13 21:46:19 +00:00
|
|
|
|
<< "wide false\n"
|
|
|
|
|
<< "collapsed false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "tab") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("table");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
2001-08-13 21:46:19 +00:00
|
|
|
|
<< "wide false\n"
|
|
|
|
|
<< "collapsed false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "alg") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("algorithm");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
2001-08-13 21:46:19 +00:00
|
|
|
|
<< "wide false\n"
|
|
|
|
|
<< "collapsed false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "wide-fig") {
|
2001-06-13 14:47:08 +00:00
|
|
|
|
inset = new InsetFloat("figure");
|
|
|
|
|
//InsetFloat * tmp = new InsetFloat("figure");
|
|
|
|
|
//tmp->wide(true);
|
|
|
|
|
//inset = tmp;
|
|
|
|
|
old_float << "placement htbp\n"
|
2001-08-13 21:46:19 +00:00
|
|
|
|
<< "wide true\n"
|
|
|
|
|
<< "collapsed false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "wide-tab") {
|
2001-06-13 14:47:08 +00:00
|
|
|
|
inset = new InsetFloat("table");
|
|
|
|
|
//InsetFloat * tmp = new InsetFloat("table");
|
|
|
|
|
//tmp->wide(true);
|
|
|
|
|
//inset = tmp;
|
|
|
|
|
old_float << "placement htbp\n"
|
2001-08-13 21:46:19 +00:00
|
|
|
|
<< "wide true\n"
|
|
|
|
|
<< "collapsed false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
if (!inset) {
|
2001-07-27 20:27:56 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2001-03-14 14:54:30 +00:00
|
|
|
|
--call_depth;
|
2001-07-27 20:27:56 +00:00
|
|
|
|
#endif
|
2001-03-14 14:54:30 +00:00
|
|
|
|
return false; // no end read yet
|
|
|
|
|
}
|
2000-07-21 14:59:00 +00:00
|
|
|
|
|
|
|
|
|
// Here we need to check for \end_deeper and handle that
|
|
|
|
|
// before we do the footnote parsing.
|
|
|
|
|
// This _is_ a hack! (Lgb)
|
2001-03-11 03:20:44 +00:00
|
|
|
|
while (true) {
|
2000-07-21 14:59:00 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmp = lex.getString();
|
2000-07-21 14:59:00 +00:00
|
|
|
|
if (tmp == "\\end_deeper") {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
//lyxerr << "\\end_deeper caught!" << endl;
|
2000-07-21 14:59:00 +00:00
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: "
|
|
|
|
|
"depth is already null");
|
|
|
|
|
} else
|
|
|
|
|
--depth;
|
|
|
|
|
|
|
|
|
|
} else {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
old_float << tmp << ' ';
|
2000-07-21 14:59:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
old_float << lex.getLongString("\\end_float")
|
|
|
|
|
<< "\n\\end_inset\n";
|
|
|
|
|
//lyxerr << "Float Body:\n" << old_float.str() << endl;
|
|
|
|
|
// That this does not work seems like a bug
|
|
|
|
|
// in stringstream. (Lgb)
|
|
|
|
|
istringstream istr(old_float.str());
|
2000-06-28 13:35:52 +00:00
|
|
|
|
LyXLex nylex(0, 0);
|
|
|
|
|
nylex.setStream(istr);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, nylex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
++pos;
|
2001-08-02 18:46:53 +00:00
|
|
|
|
insertErtContents(par, pos, font);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\begin_deeper") {
|
|
|
|
|
++depth;
|
|
|
|
|
} else if (token == "\\end_deeper") {
|
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: "
|
|
|
|
|
"depth is already null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
--depth;
|
|
|
|
|
} else if (token == "\\begin_preamble") {
|
|
|
|
|
params.readPreamble(lex);
|
|
|
|
|
} else if (token == "\\textclass") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
2001-11-29 17:12:21 +00:00
|
|
|
|
pair<bool, textclass_type> pp =
|
2001-08-06 19:12:46 +00:00
|
|
|
|
textclasslist.NumberOfClass(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (pp.first) {
|
|
|
|
|
params.textclass = pp.second;
|
|
|
|
|
} else {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(string(_("Textclass error")),
|
2000-11-29 15:34:56 +00:00
|
|
|
|
string(_("The document uses an unknown textclass \"")) +
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.getString() + string("\"."),
|
2000-11-29 15:34:56 +00:00
|
|
|
|
string(_("LyX will not be able to produce output correctly.")));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!textclasslist.Load(params.textclass)) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
// if the textclass wasn't loaded properly
|
|
|
|
|
// we need to either substitute another
|
|
|
|
|
// or stop loading the file.
|
|
|
|
|
// I can substitute but I don't see how I can
|
|
|
|
|
// stop loading... ideas?? ARRae980418
|
|
|
|
|
Alert::alert(_("Textclass Loading Error!"),
|
2000-03-01 14:13:21 +00:00
|
|
|
|
string(_("Can't load textclass ")) +
|
|
|
|
|
textclasslist.NameOfClass(params.textclass),
|
|
|
|
|
_("-- substituting default"));
|
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\options") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
params.options = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\language") {
|
|
|
|
|
params.readLanguage(lex);
|
|
|
|
|
} else if (token == "\\fontencoding") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\inputencoding") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
params.inputenc = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\graphics") {
|
|
|
|
|
params.readGraphicsDriver(lex);
|
|
|
|
|
} else if (token == "\\fontscheme") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
params.fonts = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\noindent") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().noindent(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\fill_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceTop(VSpace(VSpace::VFILL));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\fill_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceBottom(VSpace(VSpace::VFILL));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\line_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().lineTop(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\line_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().lineBottom(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pagebreak_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pagebreakTop(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pagebreak_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pagebreakBottom(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\start_of_appendix") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().startOfAppendix(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\paragraph_separation") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_paragraph_separation);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT)
|
|
|
|
|
params.paragraph_separation =
|
|
|
|
|
static_cast<BufferParams::PARSEP>(tmpret);
|
|
|
|
|
} else if (token == "\\defskip") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.defskip = VSpace(lex.getString());
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\epsfig") { // obsolete
|
|
|
|
|
// Indeed it is obsolete, but we HAVE to be backwards
|
|
|
|
|
// compatible until 0.14, because otherwise all figures
|
|
|
|
|
// in existing documents are irretrivably lost. (Asger)
|
|
|
|
|
params.readGraphicsDriver(lex);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\quotes_language") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_quotes_language);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT) {
|
|
|
|
|
InsetQuotes::quote_language tmpl =
|
|
|
|
|
InsetQuotes::EnglishQ;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (tmpret) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 0:
|
|
|
|
|
tmpl = InsetQuotes::EnglishQ;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 1:
|
|
|
|
|
tmpl = InsetQuotes::SwedishQ;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 2:
|
|
|
|
|
tmpl = InsetQuotes::GermanQ;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
tmpl = InsetQuotes::PolishQ;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
tmpl = InsetQuotes::FrenchQ;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
tmpl = InsetQuotes::DanishQ;
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.quotes_language = tmpl;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\quotes_times") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
switch (lex.getInteger()) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 1:
|
|
|
|
|
params.quotes_times = InsetQuotes::SingleQ;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
params.quotes_times = InsetQuotes::DoubleQ;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\papersize") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_papersize);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
|
|
|
|
else
|
|
|
|
|
params.papersize2 = tmpret;
|
|
|
|
|
} else if (token == "\\paperpackage") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_paperpackages);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) {
|
|
|
|
|
++tmpret;
|
|
|
|
|
params.paperpackage = BufferParams::PACKAGE_NONE;
|
|
|
|
|
} else
|
|
|
|
|
params.paperpackage = tmpret;
|
|
|
|
|
} else if (token == "\\use_geometry") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.use_geometry = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\use_amsmath") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.use_amsmath = lex.getInteger();
|
2001-07-19 14:12:37 +00:00
|
|
|
|
} else if (token == "\\use_natbib") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.use_natbib = lex.getInteger();
|
2001-07-19 14:12:37 +00:00
|
|
|
|
} else if (token == "\\use_numerical_citations") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.use_numerical_citations = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\paperorientation") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_orientation);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT)
|
|
|
|
|
params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
|
|
|
|
|
} else if (token == "\\paperwidth") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.paperwidth = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\paperheight") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.paperheight = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\leftmargin") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.leftmargin = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\topmargin") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.topmargin = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\rightmargin") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.rightmargin = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\bottommargin") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.bottommargin = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\headheight") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.headheight = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\headsep") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.headsep = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\footskip") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.footskip = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\paperfontsize") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.fontsize = strip(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\papercolumns") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.columns = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\papersides") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
switch (lex.getInteger()) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
default:
|
|
|
|
|
case 1: params.sides = LyXTextClass::OneSide; break;
|
|
|
|
|
case 2: params.sides = LyXTextClass::TwoSides; break;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\paperpagestyle") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.pagestyle = strip(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\bullet") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int const index = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int temp_int = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.user_defined_bullets[index].setFont(temp_int);
|
|
|
|
|
params.temp_bullets[index].setFont(temp_int);
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
temp_int = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.user_defined_bullets[index].setCharacter(temp_int);
|
|
|
|
|
params.temp_bullets[index].setCharacter(temp_int);
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
temp_int = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.user_defined_bullets[index].setSize(temp_int);
|
|
|
|
|
params.temp_bullets[index].setSize(temp_int);
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const temp_str = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (temp_str != "\\end_bullet") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// this element isn't really necessary for
|
|
|
|
|
// parsing but is easier for humans
|
|
|
|
|
// to understand bullets. Put it back and
|
|
|
|
|
// set a debug message?
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.printError("\\end_bullet expected, got" + temp_str);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//how can I put it back?
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\bulletLaTeX") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int const index = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string temp_str = lex.getString();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string sum_str;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
while (temp_str != "\\end_bullet") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// this loop structure is needed when user
|
|
|
|
|
// enters an empty string since the first
|
|
|
|
|
// thing returned will be the \\end_bullet
|
|
|
|
|
// OR
|
|
|
|
|
// if the LaTeX entry has spaces. Each element
|
|
|
|
|
// therefore needs to be read in turn
|
2000-03-01 14:13:21 +00:00
|
|
|
|
sum_str += temp_str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
temp_str = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
params.user_defined_bullets[index].setText(sum_str);
|
|
|
|
|
params.temp_bullets[index].setText(sum_str);
|
|
|
|
|
} else if (token == "\\secnumdepth") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.secnumdepth = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\tocdepth") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.tocdepth = lex.getInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\spacing") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmp = strip(lex.getString());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Spacing::Space tmp_space = Spacing::Default;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
float tmp_val = 0.0;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmp == "single") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Single;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "onehalf") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Onehalf;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "double") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Double;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "other") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Other;
|
2001-08-06 19:12:46 +00:00
|
|
|
|
tmp_val = lex.getFloat();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown spacing token: '$$Token'");
|
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// Small hack so that files written with klyx will be
|
|
|
|
|
// parsed correctly.
|
2001-07-09 23:12:04 +00:00
|
|
|
|
if (first_par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(tmp_space, tmp_val));
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
params.spacing.set(tmp_space, tmp_val);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (token == "\\paragraph_spacing") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmp = strip(lex.getString());
|
2000-04-11 22:55:29 +00:00
|
|
|
|
if (tmp == "single") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Single));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "onehalf") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Onehalf));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "double") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Double));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "other") {
|
|
|
|
|
lex.next();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Other,
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.getFloat()));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown spacing token: '$$Token'");
|
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\float_placement") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.float_placement = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\family") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setLyXFamily(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\series") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setLyXSeries(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\shape") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setLyXShape(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\size") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setLyXSize(lex.getString());
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else if (token == "\\latex") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tok = lex.getString();
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (tok == "no_latex") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
// Do the insetert.
|
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else if (tok == "latex") {
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.active = true;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else if (tok == "default") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
// Do the insetert.
|
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown LaTeX font flag "
|
|
|
|
|
"`$$Token'");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-03-17 10:14:46 +00:00
|
|
|
|
} else if (token == "\\lang") {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tok = lex.getString();
|
2000-10-10 12:36:36 +00:00
|
|
|
|
Language const * lang = languages.getLanguage(tok);
|
|
|
|
|
if (lang) {
|
|
|
|
|
font.setLanguage(lang);
|
2000-03-17 10:14:46 +00:00
|
|
|
|
} else {
|
2000-10-10 12:36:36 +00:00
|
|
|
|
font.setLanguage(params.language);
|
2000-03-17 10:14:46 +00:00
|
|
|
|
lex.printError("Unknown language `$$Token'");
|
|
|
|
|
}
|
2000-10-09 12:30:52 +00:00
|
|
|
|
} else if (token == "\\numeric") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setNumber(font.setLyXMisc(lex.getString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\emph") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setEmph(font.setLyXMisc(lex.getString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\bar") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tok = lex.getString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
// This is dirty, but gone with LyX3. (Asger)
|
|
|
|
|
if (tok == "under")
|
|
|
|
|
font.setUnderbar(LyXFont::ON);
|
|
|
|
|
else if (tok == "no")
|
|
|
|
|
font.setUnderbar(LyXFont::OFF);
|
|
|
|
|
else if (tok == "default")
|
|
|
|
|
font.setUnderbar(LyXFont::INHERIT);
|
|
|
|
|
else
|
|
|
|
|
lex.printError("Unknown bar font flag "
|
|
|
|
|
"`$$Token'");
|
|
|
|
|
} else if (token == "\\noun") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setNoun(font.setLyXMisc(lex.getString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\color") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
font.setLyXColor(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\align") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
int tmpret = lex.findToken(string_align);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) ++tmpret;
|
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
|
2000-11-21 21:51:25 +00:00
|
|
|
|
int const tmpret2 = int(pow(2.0, tmpret));
|
2000-11-21 22:16:14 +00:00
|
|
|
|
//lyxerr << "Tmpret2 = " << tmpret2 << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().align(LyXAlignment(tmpret2));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\added_space_top") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().spaceTop(VSpace(lex.getString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\added_space_bottom") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().spaceBottom(VSpace(lex.getString()));
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-03-16 00:09:53 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_type") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraType(lex.getInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_width") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraWidth(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_widthp") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraWidthp(lex.getString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_alignment") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraAlignment(lex.getInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_hfill") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraHfill(lex.getInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_start_minipage") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
par->params().pextraStartMinipage(lex.getInteger());
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2001-03-16 00:09:53 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\labelwidthstring") {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
par->params().labelWidthString(lex.getString());
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// do not delete this token, it is still needed!
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\end_inset") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
|
|
|
|
|
<< "Last inset read was: " << last_inset_read
|
|
|
|
|
<< endl;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Simply ignore this. The insets do not have
|
|
|
|
|
// to read this.
|
|
|
|
|
// But insets should read it, it is a part of
|
|
|
|
|
// the inset isn't it? Lgb.
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\begin_inset") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
insertErtContents(par, pos, font, false);
|
|
|
|
|
ert_stack.push(ert_comp);
|
|
|
|
|
ert_comp = ErtComp();
|
2001-07-09 23:12:04 +00:00
|
|
|
|
#endif
|
2000-07-24 21:49:58 +00:00
|
|
|
|
readInset(lex, par, pos, font);
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp = ert_stack.top();
|
|
|
|
|
ert_stack.pop();
|
2001-08-02 18:46:53 +00:00
|
|
|
|
insertErtContents(par, pos, font);
|
2001-07-10 22:36:25 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\SpecialChar") {
|
2000-03-09 03:36:48 +00:00
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
|
|
|
|
// Insets don't make sense in a free-spacing context! ---Kayvan
|
2001-11-29 16:29:30 +00:00
|
|
|
|
if (layout.free_spacing || par->isFreeSpacing()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
|
if (lex.isOK()) {
|
2000-03-09 03:36:48 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string next_token = lex.getString();
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (next_token == "\\-") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, '-', font);
|
2000-05-05 11:42:00 +00:00
|
|
|
|
} else if (next_token == "\\protected_separator"
|
2000-05-05 12:27:42 +00:00
|
|
|
|
|| next_token == "~") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Token `$$Token' "
|
|
|
|
|
"is in free space "
|
|
|
|
|
"paragraph layout!");
|
2000-04-24 20:58:23 +00:00
|
|
|
|
--pos;
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else {
|
|
|
|
|
Inset * inset = new InsetSpecialChar;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else if (token == "\\newline") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
if (!ert_comp.in_tabular && ert_comp.active) {
|
|
|
|
|
ert_comp.contents += char(Paragraph::META_NEWLINE);
|
2001-07-09 23:12:04 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Since we cannot know it this is only a regular
|
|
|
|
|
// newline or a tabular cell delimter we have to
|
|
|
|
|
// handle the ERT here.
|
|
|
|
|
insertErtContents(par, pos, font, false);
|
|
|
|
|
|
|
|
|
|
par->insertChar(pos, Paragraph::META_NEWLINE, font);
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
#else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, Paragraph::META_NEWLINE, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
2001-07-09 23:12:04 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\LyXTable") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
ert_comp.in_tabular = true;
|
2001-07-09 23:12:04 +00:00
|
|
|
|
#endif
|
2000-10-10 11:50:43 +00:00
|
|
|
|
Inset * inset = new InsetTabular(*this);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-05-17 14:43:09 +00:00
|
|
|
|
++pos;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\hfill") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, Paragraph::META_HFILL, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\protected_separator") { // obsolete
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// This is a backward compability thingie. (Lgb)
|
|
|
|
|
// Remove it later some time...introduced with fileformat
|
|
|
|
|
// 2.16. (Lgb)
|
2000-03-09 03:36:48 +00:00
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
2001-11-29 16:29:30 +00:00
|
|
|
|
if (layout.free_spacing || par->isFreeSpacing()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
} else {
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\bibitem") { // ale970302
|
2000-08-04 13:12:30 +00:00
|
|
|
|
if (!par->bibkey) {
|
2001-01-31 11:46:13 +00:00
|
|
|
|
InsetCommandParams p("bibitem", "dummy");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
par->bibkey = new InsetBibKey(p);
|
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
|
par->bibkey->read(this, lex);
|
2000-08-05 05:17:18 +00:00
|
|
|
|
} else if (token == "\\backslash") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
if (ert_comp.active) {
|
|
|
|
|
ert_comp.contents += "\\";
|
2001-07-08 12:52:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, '\\', font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-08-05 05:17:18 +00:00
|
|
|
|
} else if (token == "\\the_end") {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
//<2F>If we still have some ert active here we have to insert
|
|
|
|
|
// it so we don't loose it. (Lgb)
|
|
|
|
|
insertErtContents(par, pos, font);
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
the_end_read = true;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-27 20:27:56 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2001-03-22 15:45:15 +00:00
|
|
|
|
minipar = parBeforeMinipage = 0;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2001-07-27 20:27:56 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else {
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-10 22:36:25 +00:00
|
|
|
|
if (ert_comp.active) {
|
|
|
|
|
ert_comp.contents += token;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
// This should be insurance for the future: (Asger)
|
2001-11-25 17:58:05 +00:00
|
|
|
|
++unknown_tokens;
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string const s = _("Unknown token: ") + token
|
|
|
|
|
+ " " + lex.text() + "\n";
|
|
|
|
|
|
|
|
|
|
InsetError * new_inset = new InsetError(s);
|
2001-12-15 15:03:06 +00:00
|
|
|
|
par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
|
|
|
|
|
params.language));
|
2001-11-25 17:58:05 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-07-08 12:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-25 22:25:48 +00:00
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#ifndef NO_COMPABILITY
|
2001-03-22 15:45:15 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2001-07-25 22:25:48 +00:00
|
|
|
|
// I wonder if we could use this blanket fix for all the
|
|
|
|
|
// checkminipage cases...
|
2001-12-24 13:55:59 +00:00
|
|
|
|
// don't forget about ert paragraphs and compatibility read for'em
|
|
|
|
|
if (par && (par->size() || !ert_comp.contents.empty())) {
|
2001-07-25 22:25:48 +00:00
|
|
|
|
// It is possible that this will check to often,
|
|
|
|
|
// but that should not be an correctness issue.
|
|
|
|
|
// Only a speed issue.
|
|
|
|
|
checkminipage = true;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-22 15:45:15 +00:00
|
|
|
|
// now check if we have a minipage paragraph as at this
|
|
|
|
|
// point we already read all the necessary data!
|
|
|
|
|
// this cannot be done in layout because there we did
|
|
|
|
|
// not read yet the paragraph PEXTRA-params (Jug)
|
|
|
|
|
//
|
|
|
|
|
// BEGIN pextra_minipage compability
|
|
|
|
|
// This should be removed in 1.3.x (Lgb)
|
2001-12-24 13:55:59 +00:00
|
|
|
|
// I don't think we should remove this so fast (Jug)
|
2001-03-22 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
// This compability code is not perfect. In a couple
|
|
|
|
|
// of rand cases it fails. When the minipage par is
|
|
|
|
|
// the first par in the document, and when there are
|
|
|
|
|
// none or only one regular paragraphs after the
|
|
|
|
|
// minipage. Currently I am not investing any effort
|
|
|
|
|
// in fixing those cases.
|
|
|
|
|
|
|
|
|
|
//lyxerr << "Call depth: " << call_depth << endl;
|
|
|
|
|
if (checkminipage && (call_depth == 1)) {
|
|
|
|
|
checkminipage = false;
|
|
|
|
|
if (minipar && (minipar != par) &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
(par->params().pextraType()==Paragraph::PEXTRA_MINIPAGE))
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr << "minipages in a row" << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraStartMinipage()) {
|
2001-03-22 15:45:15 +00:00
|
|
|
|
lyxerr << "start new minipage" << endl;
|
|
|
|
|
// minipages in a row
|
|
|
|
|
par->previous()->next(0);
|
|
|
|
|
par->previous(0);
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmp = minipar;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
while (tmp) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmp->params().pextraType(0);
|
|
|
|
|
tmp->params().pextraWidth(string());
|
|
|
|
|
tmp->params().pextraWidthp(string());
|
|
|
|
|
tmp->params().pextraAlignment(0);
|
|
|
|
|
tmp->params().pextraHfill(false);
|
|
|
|
|
tmp->params().pextraStartMinipage(false);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
tmp = tmp->next();
|
|
|
|
|
}
|
|
|
|
|
// create a new paragraph to insert the
|
|
|
|
|
// minipages in the following case
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraStartMinipage() &&
|
|
|
|
|
!par->params().pextraHfill())
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * p = new Paragraph;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
p->layout = 0;
|
|
|
|
|
p->previous(parBeforeMinipage);
|
|
|
|
|
parBeforeMinipage->next(p);
|
|
|
|
|
p->next(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
p->params().depth(parBeforeMinipage->params().depth());
|
2001-03-22 15:45:15 +00:00
|
|
|
|
parBeforeMinipage = p;
|
|
|
|
|
}
|
|
|
|
|
InsetMinipage * mini = new InsetMinipage;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
|
|
|
|
|
mini->width(par->params().pextraWidth());
|
|
|
|
|
if (!par->params().pextraWidthp().empty()) {
|
2001-03-29 15:00:20 +00:00
|
|
|
|
lyxerr << "WP:" << mini->width() << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->width(tostr(par->params().pextraWidthp())+"%");
|
2001-03-29 15:00:20 +00:00
|
|
|
|
}
|
2001-12-24 13:55:59 +00:00
|
|
|
|
Paragraph * op = mini->firstParagraph();
|
2001-07-06 15:57:54 +00:00
|
|
|
|
mini->inset.paragraph(par);
|
2001-12-24 13:55:59 +00:00
|
|
|
|
//
|
|
|
|
|
// and free the old ones!
|
|
|
|
|
//
|
|
|
|
|
while(op) {
|
|
|
|
|
Paragraph * pp = op->next();
|
|
|
|
|
delete op;
|
|
|
|
|
op = pp;
|
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
// Insert the minipage last in the
|
|
|
|
|
// previous paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraHfill()) {
|
|
|
|
|
parBeforeMinipage->insertChar
|
|
|
|
|
(parBeforeMinipage->size(), Paragraph::META_HFILL);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
parBeforeMinipage->insertInset
|
2001-03-22 15:45:15 +00:00
|
|
|
|
(parBeforeMinipage->size(), mini);
|
|
|
|
|
|
|
|
|
|
minipar = par;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "new minipage par" << endl;
|
|
|
|
|
//nothing to do just continue reading
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (minipar && (minipar != par)) {
|
|
|
|
|
lyxerr << "last minipage par read" << endl;
|
|
|
|
|
// The last paragraph read was not part of a
|
|
|
|
|
// minipage but the par linked list is...
|
|
|
|
|
// So we need to remove the last par from the
|
|
|
|
|
// rest
|
|
|
|
|
if (par->previous())
|
|
|
|
|
par->previous()->next(0);
|
|
|
|
|
par->previous(parBeforeMinipage);
|
|
|
|
|
parBeforeMinipage->next(par);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmp = minipar;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
while (tmp) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmp->params().pextraType(0);
|
|
|
|
|
tmp->params().pextraWidth(string());
|
|
|
|
|
tmp->params().pextraWidthp(string());
|
|
|
|
|
tmp->params().pextraAlignment(0);
|
|
|
|
|
tmp->params().pextraHfill(false);
|
|
|
|
|
tmp->params().pextraStartMinipage(false);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
tmp = tmp->next();
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
depth = parBeforeMinipage->params().depth();
|
2001-12-24 13:55:59 +00:00
|
|
|
|
// and set this depth on the par as it has not been set already
|
|
|
|
|
par->params().depth(depth);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
minipar = parBeforeMinipage = 0;
|
|
|
|
|
} else if (!minipar &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
(par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
|
|
|
|
// par is the first paragraph in a minipage
|
|
|
|
|
lyxerr << "begin minipage" << endl;
|
|
|
|
|
// To minimize problems for
|
|
|
|
|
// the users we will insert
|
|
|
|
|
// the first minipage in
|
|
|
|
|
// a sequence of minipages
|
|
|
|
|
// in its own paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * p = new Paragraph;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
p->layout = 0;
|
|
|
|
|
p->previous(par->previous());
|
|
|
|
|
p->next(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
p->params().depth(depth);
|
|
|
|
|
par->params().depth(0);
|
2001-03-22 16:07:59 +00:00
|
|
|
|
depth = 0;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
if (par->previous())
|
|
|
|
|
par->previous()->next(p);
|
|
|
|
|
par->previous(0);
|
|
|
|
|
parBeforeMinipage = p;
|
|
|
|
|
minipar = par;
|
2001-07-09 23:12:04 +00:00
|
|
|
|
if (!first_par || (first_par == par))
|
|
|
|
|
first_par = p;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
InsetMinipage * mini = new InsetMinipage;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
|
|
|
|
|
mini->width(minipar->params().pextraWidth());
|
|
|
|
|
if (!par->params().pextraWidthp().empty()) {
|
2001-03-29 15:00:20 +00:00
|
|
|
|
lyxerr << "WP:" << mini->width() << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->width(tostr(par->params().pextraWidthp())+"%");
|
2001-03-29 15:00:20 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
mini->inset.paragraph(minipar);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
// Insert the minipage last in the
|
|
|
|
|
// previous paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (minipar->params().pextraHfill()) {
|
|
|
|
|
parBeforeMinipage->insertChar
|
|
|
|
|
(parBeforeMinipage->size(),Paragraph::META_HFILL);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
parBeforeMinipage->insertInset
|
2001-03-22 15:45:15 +00:00
|
|
|
|
(parBeforeMinipage->size(), mini);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// End of pextra_minipage compability
|
2001-03-14 14:54:30 +00:00
|
|
|
|
--call_depth;
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#endif
|
2001-07-27 20:27:56 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// needed to insert the selection
|
2001-11-27 10:34:16 +00:00
|
|
|
|
void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
|
2001-10-22 09:45:31 +00:00
|
|
|
|
LyXFont const & fn,string const & str) const
|
2001-07-23 09:11:14 +00:00
|
|
|
|
{
|
|
|
|
|
LyXLayout const & layout = textclasslist.Style(params.textclass,
|
2001-10-22 09:45:31 +00:00
|
|
|
|
par->getLayout());
|
|
|
|
|
LyXFont font = fn;
|
|
|
|
|
|
|
|
|
|
(void)par->checkInsertChar(font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// insert the string, don't insert doublespace
|
|
|
|
|
bool space_inserted = true;
|
|
|
|
|
for(string::const_iterator cit = str.begin();
|
|
|
|
|
cit != str.end(); ++cit) {
|
|
|
|
|
if (*cit == '\n') {
|
|
|
|
|
if (par->size() || layout.keepempty) {
|
|
|
|
|
par->breakParagraph(params, pos,
|
2001-10-22 09:45:31 +00:00
|
|
|
|
layout.isEnvironment());
|
2001-07-23 09:11:14 +00:00
|
|
|
|
par = par->next();
|
|
|
|
|
pos = 0;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// do not insert consecutive spaces if !free_spacing
|
2001-10-22 09:45:31 +00:00
|
|
|
|
} else if ((*cit == ' ' || *cit == '\t') &&
|
2001-11-29 16:29:30 +00:00
|
|
|
|
space_inserted && !layout.free_spacing &&
|
|
|
|
|
!par->isFreeSpacing())
|
2001-10-22 09:45:31 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
continue;
|
|
|
|
|
} else if (*cit == '\t') {
|
2001-11-29 16:29:30 +00:00
|
|
|
|
if (!layout.free_spacing && !par->isFreeSpacing()) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// tabs are like spaces here
|
|
|
|
|
par->insertChar(pos, ' ', font);
|
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
2001-11-27 10:34:16 +00:00
|
|
|
|
const pos_type nb = 8 - pos % 8;
|
|
|
|
|
for (pos_type a = 0; a < nb ; ++a) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (!IsPrintable(*cit)) {
|
|
|
|
|
// Ignore unprintables
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
// just insert the character
|
|
|
|
|
par->insertChar(pos, *cit, font);
|
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = (*cit == ' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::readInset(LyXLex & lex, Paragraph *& par,
|
2000-07-24 21:49:58 +00:00
|
|
|
|
int & pos, LyXFont & font)
|
|
|
|
|
{
|
|
|
|
|
// consistency check
|
2001-08-06 19:12:46 +00:00
|
|
|
|
if (lex.getString() != "\\begin_inset") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
lyxerr << "Buffer::readInset: Consistency check failed."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-27 05:40:29 +00:00
|
|
|
|
Inset * inset = 0;
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmptok = lex.getString();
|
2000-07-24 21:49:58 +00:00
|
|
|
|
last_inset_read = tmptok;
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
// test the different insets
|
2000-09-27 05:40:29 +00:00
|
|
|
|
if (tmptok == "LatexCommand") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
InsetCommandParams inscmd;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inscmd.read(lex);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
string const cmdName = inscmd.getCmdName();
|
|
|
|
|
|
2001-07-19 14:12:37 +00:00
|
|
|
|
// This strange command allows LyX to recognize "natbib" style
|
|
|
|
|
// citations: citet, citep, Citet etc.
|
|
|
|
|
if (compare_no_case(cmdName, "cite", 4) == 0) {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetCitation(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "bibitem") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
lex.printError("Wrong place for bibitem");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetBibKey(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "BibTeX") {
|
2000-10-03 09:13:34 +00:00
|
|
|
|
inset = new InsetBibtex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "index") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetIndex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "include") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetInclude(inscmd, *this);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "label") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetLabel(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "url"
|
|
|
|
|
|| cmdName == "htmlurl") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetUrl(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "ref"
|
|
|
|
|
|| cmdName == "pageref"
|
|
|
|
|
|| cmdName == "vref"
|
|
|
|
|
|| cmdName == "vpageref"
|
|
|
|
|
|| cmdName == "prettyref") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
if (!inscmd.getOptions().empty()
|
|
|
|
|
|| !inscmd.getContents().empty()) {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetRef(inscmd, *this);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "tableofcontents") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetTOC(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "listofalgorithms") {
|
|
|
|
|
inset = new InsetFloatList("algorithm");
|
|
|
|
|
} else if (cmdName == "listoffigures") {
|
|
|
|
|
inset = new InsetFloatList("figure");
|
|
|
|
|
} else if (cmdName == "listoftables") {
|
|
|
|
|
inset = new InsetFloatList("table");
|
|
|
|
|
} else if (cmdName == "printindex") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetPrintIndex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "lyxparent") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetParent(inscmd, *this);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
bool alreadyread = false;
|
2000-09-27 05:40:29 +00:00
|
|
|
|
if (tmptok == "Quotes") {
|
|
|
|
|
inset = new InsetQuotes;
|
|
|
|
|
} else if (tmptok == "External") {
|
|
|
|
|
inset = new InsetExternal;
|
|
|
|
|
} else if (tmptok == "FormulaMacro") {
|
|
|
|
|
inset = new InsetFormulaMacro;
|
|
|
|
|
} else if (tmptok == "Formula") {
|
|
|
|
|
inset = new InsetFormula;
|
2001-07-28 12:24:16 +00:00
|
|
|
|
} else if (tmptok == "Figure") { // Backward compatibility
|
2001-07-29 10:50:07 +00:00
|
|
|
|
inset = new InsetFig(100, 100, *this);
|
|
|
|
|
//inset = new InsetGraphics;
|
|
|
|
|
} else if (tmptok == "Graphics") {
|
2001-07-28 12:24:16 +00:00
|
|
|
|
inset = new InsetGraphics;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
} else if (tmptok == "Info") {// backwards compatibility
|
|
|
|
|
inset = new InsetNote(this,
|
|
|
|
|
lex.getLongString("\\end_inset"),
|
|
|
|
|
true);
|
|
|
|
|
alreadyread = true;
|
|
|
|
|
} else if (tmptok == "Note") {
|
2001-07-20 09:57:23 +00:00
|
|
|
|
inset = new InsetNote;
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Include") {
|
|
|
|
|
InsetCommandParams p( "Include" );
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetInclude(p, *this);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "ERT") {
|
|
|
|
|
inset = new InsetERT;
|
|
|
|
|
} else if (tmptok == "Tabular") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetTabular(*this);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Text") {
|
|
|
|
|
inset = new InsetText;
|
|
|
|
|
} else if (tmptok == "Foot") {
|
|
|
|
|
inset = new InsetFoot;
|
|
|
|
|
} else if (tmptok == "Marginal") {
|
|
|
|
|
inset = new InsetMarginal;
|
|
|
|
|
} else if (tmptok == "Minipage") {
|
|
|
|
|
inset = new InsetMinipage;
|
|
|
|
|
} else if (tmptok == "Float") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string tmptok = lex.getString();
|
2000-09-27 05:40:29 +00:00
|
|
|
|
inset = new InsetFloat(tmptok);
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#if 0
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "List") {
|
|
|
|
|
inset = new InsetList;
|
|
|
|
|
} else if (tmptok == "Theorem") {
|
|
|
|
|
inset = new InsetList;
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Caption") {
|
|
|
|
|
inset = new InsetCaption;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (tmptok == "FloatList") {
|
|
|
|
|
inset = new InsetFloatList;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
if (inset && !alreadyread) inset->read(this, lex);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inset) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
++pos;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool Buffer::readFile(LyXLex & lex, Paragraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-06 19:12:46 +00:00
|
|
|
|
if (lex.isOK()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const token(lex.getString());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (token == "\\lyxformat") { // the first token _must_ be...
|
2001-08-06 19:12:46 +00:00
|
|
|
|
lex.eatLine();
|
|
|
|
|
string tmp_format = lex.getString();
|
2001-01-11 11:06:10 +00:00
|
|
|
|
//lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
|
|
|
|
|
// if present remove ".," from string.
|
|
|
|
|
string::size_type dot = tmp_format.find_first_of(".,");
|
|
|
|
|
//lyxerr << " dot found at " << dot << endl;
|
|
|
|
|
if (dot != string::npos)
|
|
|
|
|
tmp_format.erase(dot, 1);
|
|
|
|
|
file_format = strToInt(tmp_format);
|
|
|
|
|
if (file_format == LYX_FORMAT) {
|
|
|
|
|
// current format
|
|
|
|
|
} else if (file_format > LYX_FORMAT) {
|
|
|
|
|
// future format
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Warning!"),
|
2001-01-11 11:06:10 +00:00
|
|
|
|
_("LyX file format is newer that what"),
|
|
|
|
|
_("is supported in this LyX version. Expect some problems."));
|
|
|
|
|
|
|
|
|
|
} else if (file_format < LYX_FORMAT) {
|
|
|
|
|
// old formats
|
|
|
|
|
if (file_format < 200) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("ERROR!"),
|
2001-01-11 11:06:10 +00:00
|
|
|
|
_("Old LyX file format found. "
|
|
|
|
|
"Use LyX 0.10.x to read this!"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool the_end = readLyXformat2(lex, par);
|
2001-11-07 10:25:05 +00:00
|
|
|
|
params.setPaperStuff();
|
2001-01-11 11:06:10 +00:00
|
|
|
|
// the_end was added in 213
|
|
|
|
|
if (file_format < 213)
|
|
|
|
|
the_end = true;
|
|
|
|
|
|
2001-11-26 10:19:58 +00:00
|
|
|
|
if (!the_end) {
|
|
|
|
|
Alert::alert(_("Warning!"),
|
2001-01-11 11:06:10 +00:00
|
|
|
|
_("Reading of document is not complete"),
|
|
|
|
|
_("Maybe the document is truncated"));
|
2001-11-26 10:19:58 +00:00
|
|
|
|
}
|
2001-01-11 11:06:10 +00:00
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else { // "\\lyxformat" not found
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("ERROR!"), _("Not a LyX file!"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
} else
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("ERROR!"), _("Unable to read file!"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should probably be moved to somewhere else: BufferView? LyXView?
|
2000-03-20 14:49:54 +00:00
|
|
|
|
bool Buffer::save() const
|
2000-02-22 00:36:17 +00:00
|
|
|
|
{
|
|
|
|
|
// We don't need autosaves in the immediate future. (Asger)
|
|
|
|
|
resetAutosaveTimers();
|
|
|
|
|
|
|
|
|
|
// make a backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
string s;
|
|
|
|
|
if (lyxrc.make_backup) {
|
|
|
|
|
s = fileName() + '~';
|
|
|
|
|
if (!lyxrc.backupdir_path.empty())
|
|
|
|
|
s = AddName(lyxrc.backupdir_path,
|
2001-05-17 15:11:01 +00:00
|
|
|
|
subst(os::slashify_path(s),'/','!'));
|
2000-03-20 14:49:54 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Rename is the wrong way of making a backup,
|
|
|
|
|
// this is the correct way.
|
|
|
|
|
/* truss cp fil fil2:
|
|
|
|
|
lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
|
|
|
|
|
stat("LyXVC.lyx", 0xEFFFF688) = 0
|
|
|
|
|
open("LyXVC.lyx", O_RDONLY) = 3
|
|
|
|
|
open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
|
|
|
|
|
fstat(4, 0xEFFFF508) = 0
|
|
|
|
|
fstat(3, 0xEFFFF508) = 0
|
|
|
|
|
read(3, " # T h i s f i l e w".., 8192) = 5579
|
|
|
|
|
write(4, " # T h i s f i l e w".., 5579) = 5579
|
|
|
|
|
read(3, 0xEFFFD4A0, 8192) = 0
|
|
|
|
|
close(4) = 0
|
|
|
|
|
close(3) = 0
|
|
|
|
|
chmod("LyXVC3.lyx", 0100644) = 0
|
|
|
|
|
lseek(0, 0, SEEK_CUR) = 46440
|
|
|
|
|
_exit(0)
|
|
|
|
|
*/
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Should probably have some more error checking here.
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should be cleaned up in 0.13, at least a bit.
|
|
|
|
|
// Doing it this way, also makes the inodes stay the same.
|
|
|
|
|
// This is still not a very good solution, in particular we
|
|
|
|
|
// might loose the owner of the backup.
|
|
|
|
|
FileInfo finfo(fileName());
|
|
|
|
|
if (finfo.exist()) {
|
|
|
|
|
mode_t fmode = finfo.getMode();
|
2000-03-28 02:18:55 +00:00
|
|
|
|
struct utimbuf times = {
|
|
|
|
|
finfo.getAccessTime(),
|
|
|
|
|
finfo.getModificationTime() };
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
|
|
ifstream ifs(fileName().c_str());
|
|
|
|
|
ofstream ofs(s.c_str(), ios::out|ios::trunc);
|
|
|
|
|
if (ifs && ofs) {
|
|
|
|
|
ofs << ifs.rdbuf();
|
|
|
|
|
ifs.close();
|
|
|
|
|
ofs.close();
|
|
|
|
|
::chmod(s.c_str(), fmode);
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
if (::utime(s.c_str(), ×)) {
|
2000-02-22 00:36:17 +00:00
|
|
|
|
lyxerr << "utime error." << endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "LyX was not able to make "
|
2001-06-25 00:06:33 +00:00
|
|
|
|
"backup copy. Beware." << endl;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (writeFile(fileName(), false)) {
|
|
|
|
|
markLyxClean();
|
2000-08-08 15:36:25 +00:00
|
|
|
|
removeAutosaveFile(fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Saving failed, so backup is not backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
if (lyxrc.make_backup) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
lyx::rename(s, fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Returns false if unsuccesful
|
2000-02-22 00:36:17 +00:00
|
|
|
|
bool Buffer::writeFile(string const & fname, bool flag) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// if flag is false writeFile will not create any GUI
|
1999-10-07 18:44:17 +00:00
|
|
|
|
// warnings, only cerr.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Needed for autosave in background or panic save (Matthias 120496)
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
if (read_only && (fname == filename)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Here we should come with a question if we should
|
|
|
|
|
// perform the write anyway.
|
|
|
|
|
if (flag)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << _("Error! Document is read-only: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Error! Document is read-only: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
FileInfo finfo(fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << _("Error! Cannot write file: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::err_alert(_("Error! Cannot write file: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
1999-12-07 00:44:53 +00:00
|
|
|
|
if (!ofs) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (flag)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
lyxerr << _("Error! Cannot open file: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::err_alert(_("Error! Cannot open file: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
// Use the standard "C" locale for file output.
|
2000-09-15 10:24:15 +00:00
|
|
|
|
ofs.imbue(std::locale::classic());
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The top of the file should not be written by params.
|
|
|
|
|
|
|
|
|
|
// write out a comment in the top of the file
|
2001-10-03 15:49:32 +00:00
|
|
|
|
ofs << '#' << lyx_docversion
|
2001-02-14 19:22:41 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/\n"
|
|
|
|
|
<< "\\lyxformat " << LYX_FORMAT << "\n";
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// now write out the buffer paramters.
|
|
|
|
|
params.writeFile(ofs);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// this will write out all the paragraphs
|
|
|
|
|
// using recursive descent.
|
2001-05-08 17:08:44 +00:00
|
|
|
|
paragraph->writeFile(this, ofs, params, depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write marker that shows file is complete
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "\n\\the_end" << endl;
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// how to check if close went ok?
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// Following is an attempt... (BE 20001011)
|
|
|
|
|
|
|
|
|
|
// good() returns false if any error occured, including some
|
|
|
|
|
// formatting error.
|
|
|
|
|
// bad() returns true if something bad happened in the buffer,
|
|
|
|
|
// which should include file system full errors.
|
|
|
|
|
|
|
|
|
|
bool status = true;
|
|
|
|
|
if (!ofs.good()) {
|
|
|
|
|
status = false;
|
|
|
|
|
#if 0
|
|
|
|
|
if (ofs.bad()) {
|
|
|
|
|
lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
string const Buffer::asciiParagraph(Paragraph const * par,
|
2001-12-27 15:54:25 +00:00
|
|
|
|
unsigned int linelen,
|
|
|
|
|
bool noparbreak) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ostringstream word;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
int ltype = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type ltype_depth = 0;
|
2001-10-01 15:31:59 +00:00
|
|
|
|
string::size_type currlinelen = 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
bool ref_printed = false;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// if (!par->previous()) {
|
|
|
|
|
#if 0
|
|
|
|
|
// begins or ends a deeper area ?
|
|
|
|
|
if (depth != par->params().depth()) {
|
|
|
|
|
if (par->params().depth() > depth) {
|
|
|
|
|
while (par->params().depth() > depth) {
|
|
|
|
|
++depth;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
while (par->params().depth() < depth) {
|
|
|
|
|
--depth;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
depth = par->params().depth();
|
|
|
|
|
#endif
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// First write the layout
|
|
|
|
|
string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
|
|
|
|
|
if (tmp == "Itemize") {
|
|
|
|
|
ltype = 1;
|
|
|
|
|
ltype_depth = depth + 1;
|
|
|
|
|
} else if (tmp == "Enumerate") {
|
|
|
|
|
ltype = 2;
|
|
|
|
|
ltype_depth = depth + 1;
|
|
|
|
|
} else if (contains(tmp, "ection")) {
|
|
|
|
|
ltype = 3;
|
|
|
|
|
ltype_depth = depth + 1;
|
|
|
|
|
} else if (contains(tmp, "aragraph")) {
|
|
|
|
|
ltype = 4;
|
|
|
|
|
ltype_depth = depth + 1;
|
|
|
|
|
} else if (tmp == "Description") {
|
|
|
|
|
ltype = 5;
|
|
|
|
|
ltype_depth = depth + 1;
|
|
|
|
|
} else if (tmp == "Abstract") {
|
|
|
|
|
ltype = 6;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else if (tmp == "Bibliography") {
|
|
|
|
|
ltype = 7;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ltype = 0;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
/* maybe some vertical spaces */
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
/* the labelwidthstring used in lists */
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
/* some lines? */
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
/* some pagebreaks? */
|
2000-09-26 15:25:14 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
/* noindent ? */
|
|
|
|
|
|
|
|
|
|
/* what about the alignment */
|
|
|
|
|
// } else {
|
|
|
|
|
// lyxerr << "Should this ever happen?" << endl;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// linelen <= 0 is special and means we don't have pargraph breaks
|
|
|
|
|
if (!noparbreak) {
|
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "\n\n";
|
|
|
|
|
for (Paragraph::depth_type j = 0; j < depth; ++j)
|
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
//--
|
|
|
|
|
// we should probably change to the paragraph language in the
|
|
|
|
|
// gettext here (if possible) so that strings are outputted in
|
|
|
|
|
// the correct language! (20012712 Jug)
|
|
|
|
|
//--
|
|
|
|
|
switch (ltype) {
|
|
|
|
|
case 0: // Standard
|
|
|
|
|
case 4: // (Sub)Paragraph
|
|
|
|
|
case 5: // Description
|
|
|
|
|
break;
|
|
|
|
|
case 6: // Abstract
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0)
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("Abstract") << "\n\n";
|
|
|
|
|
else
|
|
|
|
|
buffer << _("Abstract: ");
|
|
|
|
|
break;
|
|
|
|
|
case 7: // Bibliography
|
|
|
|
|
if (!ref_printed) {
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0)
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("References") << "\n\n";
|
2000-10-10 10:38:11 +00:00
|
|
|
|
else
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("References: ");
|
|
|
|
|
ref_printed = true;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
buffer << par->params().labelString() << " ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string s = buffer.str();
|
|
|
|
|
if (s.rfind('\n') != string::npos) {
|
|
|
|
|
string dummy;
|
|
|
|
|
s = rsplit(buffer.str().c_str(), dummy, '\n');
|
|
|
|
|
}
|
|
|
|
|
currlinelen = s.length();
|
|
|
|
|
if (!currlinelen) {
|
|
|
|
|
for (Paragraph::depth_type j = 0; j < depth; ++j)
|
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
if (ltype_depth > depth) {
|
|
|
|
|
for (Paragraph::depth_type j = ltype_depth;
|
|
|
|
|
j > depth; --j)
|
|
|
|
|
{
|
|
|
|
|
buffer << " ";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
currlinelen += (ltype_depth-depth)*2;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
|
|
|
|
// this is to change the linebreak to do it by word a bit more intelligent
|
|
|
|
|
// hopefully! (only in the case where we have a max linelenght!) (Jug)
|
|
|
|
|
for (pos_type i = 0; i < par->size(); ++i) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getUChar(params, i);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
switch (c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_INSET:
|
2001-05-16 07:53:23 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset const * inset = par->getInset(i);
|
2001-05-16 07:53:23 +00:00
|
|
|
|
if (inset) {
|
2002-01-10 10:38:49 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << word.str();
|
2002-01-10 10:38:49 +00:00
|
|
|
|
word.str("");
|
|
|
|
|
}
|
2001-12-27 15:54:25 +00:00
|
|
|
|
if (inset->ascii(this, buffer, linelen)) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// to be sure it breaks paragraph
|
|
|
|
|
currlinelen += linelen;
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
else {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
string dummy;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
string const s =
|
|
|
|
|
rsplit(buffer.str().c_str(),
|
|
|
|
|
dummy, '\n');
|
2001-12-27 12:00:03 +00:00
|
|
|
|
currlinelen = s.length();
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
#endif
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-05-16 07:53:23 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_NEWLINE:
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << word.str() << "\n";
|
|
|
|
|
word.str("");
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = 0;
|
|
|
|
|
j < depth; ++j)
|
2000-10-10 10:38:11 +00:00
|
|
|
|
buffer << " ";
|
2001-12-27 12:00:03 +00:00
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
if (ltype_depth > depth) {
|
|
|
|
|
for (Paragraph::depth_type j = ltype_depth;
|
|
|
|
|
j > depth; --j)
|
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen += (ltype_depth - depth) * 2;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
case Paragraph::META_HFILL:
|
|
|
|
|
buffer << word.str() << "\t";
|
|
|
|
|
currlinelen += word.str().length() + 1;
|
|
|
|
|
word.str("");
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
2001-09-30 22:41:32 +00:00
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
|
default:
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (c == ' ') {
|
|
|
|
|
buffer << word.str() << ' ';
|
|
|
|
|
currlinelen += word.str().length() + 1;
|
|
|
|
|
word.str("");
|
|
|
|
|
} else {
|
|
|
|
|
if (c != '\0') {
|
|
|
|
|
word << c;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] <<
|
|
|
|
|
"writeAsciiFile: NULL char in structure." << endl;
|
|
|
|
|
}
|
|
|
|
|
if ((linelen > 0) &&
|
|
|
|
|
(currlinelen+word.str().length()) > linelen)
|
|
|
|
|
{
|
|
|
|
|
buffer << "\n";
|
|
|
|
|
for (Paragraph::depth_type j = 0; j < depth; ++j)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << " ";
|
2001-12-27 12:00:03 +00:00
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
if (ltype_depth > depth) {
|
|
|
|
|
for (Paragraph::depth_type j = ltype_depth;
|
|
|
|
|
j > depth; --j)
|
|
|
|
|
{
|
|
|
|
|
buffer << " ";
|
|
|
|
|
}
|
|
|
|
|
currlinelen += (ltype_depth-depth)*2;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << word.str();
|
2000-11-06 15:47:22 +00:00
|
|
|
|
return buffer.str().c_str();
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::writeFileAscii(string const & fname, int linelen)
|
|
|
|
|
{
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::err_alert(_("Error: Cannot write file:"), fname);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
writeFileAscii(ofs, linelen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::writeFileAscii(ostream & ofs, int linelen)
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
while (par) {
|
2001-12-27 15:54:25 +00:00
|
|
|
|
ofs << asciiParagraph(par, linelen, par->previous() == 0);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
ofs << "\n";
|
|
|
|
|
}
|
2000-11-15 03:22:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2001-02-25 10:22:54 +00:00
|
|
|
|
bool use_babel;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
void Buffer::makeLaTeXFile(string const & fname,
|
|
|
|
|
string const & original_path,
|
|
|
|
|
bool nice, bool only_body)
|
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
|
|
|
|
|
|
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
tex_code_break_column = lyxrc.ascii_linelen;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
|
|
|
|
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::err_alert(_("Error: Cannot open file: "), fname);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validate the buffer.
|
|
|
|
|
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
|
|
|
|
|
|
|
|
|
|
texrow.reset();
|
|
|
|
|
// The starting paragraph of the coming rows is the
|
|
|
|
|
// first paragraph of the document. (Asger)
|
|
|
|
|
texrow.start(paragraph, 0);
|
|
|
|
|
|
|
|
|
|
if (!only_body && nice) {
|
2001-10-03 15:49:32 +00:00
|
|
|
|
ofs << "%% " << lyx_docversion << " created this file. "
|
2000-03-06 02:42:40 +00:00
|
|
|
|
"For more info, see http://www.lyx.org/.\n"
|
|
|
|
|
"%% Do not edit unless you really know what "
|
|
|
|
|
"you are doing.\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "lyx header finished" << endl;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// There are a few differences between nice LaTeX and usual files:
|
|
|
|
|
// 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
|
|
|
|
|
// 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
|
|
|
|
|
// from \nonstopmode
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (!original_path.empty()) {
|
|
|
|
|
ofs << "\\makeatletter\n"
|
|
|
|
|
<< "\\def\\input@path{{"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
<< os::external_path(original_path) << "/}}\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\makeatother\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << "\\documentclass";
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
ostringstream options; // the document class options.
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
if (tokenPos(tclass.opt_fontsize(),
|
|
|
|
|
'|', params.fontsize) >= 0) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// only write if existing in list (and not default)
|
2001-05-09 09:14:50 +00:00
|
|
|
|
options << params.fontsize << "pt,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!params.use_geometry &&
|
|
|
|
|
(params.paperpackage == BufferParams::PACKAGE_NONE)) {
|
|
|
|
|
switch (params.papersize) {
|
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "a4paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_USLETTER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "letterpaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "a5paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_B5PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "b5paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "executivepaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "legalpaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if needed
|
|
|
|
|
if (params.sides != tclass.sides()) {
|
|
|
|
|
switch (params.sides) {
|
|
|
|
|
case LyXTextClass::OneSide:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "oneside,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case LyXTextClass::TwoSides:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "twoside,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if needed
|
|
|
|
|
if (params.columns != tclass.columns()) {
|
|
|
|
|
if (params.columns == 2)
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "twocolumn,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
else
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "onecolumn,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!params.use_geometry
|
|
|
|
|
&& params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "landscape,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-03-17 10:14:46 +00:00
|
|
|
|
// language should be a parameter to \documentclass
|
2001-02-25 10:22:54 +00:00
|
|
|
|
use_babel = false;
|
2001-05-10 15:53:10 +00:00
|
|
|
|
ostringstream language_options;
|
2001-01-20 14:16:01 +00:00
|
|
|
|
if (params.language->babel() == "hebrew"
|
|
|
|
|
&& default_language->babel() != "hebrew")
|
|
|
|
|
// This seems necessary
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.useLanguage(default_language);
|
2001-02-25 10:22:54 +00:00
|
|
|
|
|
|
|
|
|
if (lyxrc.language_use_babel ||
|
|
|
|
|
params.language->lang() != lyxrc.default_language ||
|
2001-11-19 15:34:11 +00:00
|
|
|
|
!features.hasLanguages()) {
|
2000-03-17 10:14:46 +00:00
|
|
|
|
use_babel = true;
|
2001-11-19 15:34:11 +00:00
|
|
|
|
language_options << features.getLanguages();
|
2001-05-10 15:53:10 +00:00
|
|
|
|
language_options << params.language->babel();
|
2001-02-25 10:22:54 +00:00
|
|
|
|
if (lyxrc.language_global_options)
|
2001-05-10 15:53:10 +00:00
|
|
|
|
options << language_options.str() << ',';
|
2000-03-10 13:22:20 +00:00
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// the user-defined options
|
|
|
|
|
if (!params.options.empty()) {
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << params.options << ',';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
|
|
|
|
string strOptions(options.str().c_str());
|
|
|
|
|
if (!strOptions.empty()){
|
|
|
|
|
strOptions = strip(strOptions, ',');
|
|
|
|
|
ofs << '[' << strOptions << ']';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << '{'
|
|
|
|
|
<< textclasslist.LatexnameOfClass(params.textclass)
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
// end of \documentclass defs
|
|
|
|
|
|
|
|
|
|
// font selection must be done before loading fontenc.sty
|
2001-01-23 12:53:05 +00:00
|
|
|
|
// The ae package is not needed when using OT1 font encoding.
|
|
|
|
|
if (params.fonts != "default" &&
|
|
|
|
|
(params.fonts != "ae" || lyxrc.fontenc != "default")) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
ofs << "\\usepackage{" << params.fonts << "}\n";
|
|
|
|
|
texrow.newline();
|
2001-01-23 12:53:05 +00:00
|
|
|
|
if (params.fonts == "ae") {
|
|
|
|
|
ofs << "\\usepackage{aecompl}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
// this one is not per buffer
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (lyxrc.fontenc != "default") {
|
|
|
|
|
ofs << "\\usepackage[" << lyxrc.fontenc
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "]{fontenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
if (params.inputenc == "auto") {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const doc_encoding =
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->encoding()->LatexName();
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
// Create a list with all the input encodings used
|
|
|
|
|
// in the document
|
2001-11-19 15:34:11 +00:00
|
|
|
|
set<string> encodings = features.getEncodingSet(doc_encoding);
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
ofs << "\\usepackage[";
|
2000-10-12 15:17:42 +00:00
|
|
|
|
std::copy(encodings.begin(), encodings.end(),
|
|
|
|
|
std::ostream_iterator<string>(ofs, ","));
|
2000-07-04 20:32:37 +00:00
|
|
|
|
ofs << doc_encoding << "]{inputenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
} else if (params.inputenc != "default") {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
ofs << "\\usepackage[" << params.inputenc
|
|
|
|
|
<< "]{inputenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// At the very beginning the text parameters.
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.paperpackage != BufferParams::PACKAGE_NONE) {
|
|
|
|
|
switch (params.paperpackage) {
|
|
|
|
|
case BufferParams::PACKAGE_A4:
|
|
|
|
|
ofs << "\\usepackage{a4}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_A4WIDE:
|
|
|
|
|
ofs << "\\usepackage{a4wide}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_WIDEMARGINSA4:
|
|
|
|
|
ofs << "\\usepackage[widemargins]{a4}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (params.use_geometry) {
|
|
|
|
|
ofs << "\\usepackage{geometry}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
ofs << "\\geometry{verbose";
|
|
|
|
|
if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
|
|
|
|
ofs << ",landscape";
|
|
|
|
|
switch (params.papersize2) {
|
|
|
|
|
case BufferParams::VM_PAPER_CUSTOM:
|
|
|
|
|
if (!params.paperwidth.empty())
|
|
|
|
|
ofs << ",paperwidth="
|
|
|
|
|
<< params.paperwidth;
|
|
|
|
|
if (!params.paperheight.empty())
|
|
|
|
|
ofs << ",paperheight="
|
|
|
|
|
<< params.paperheight;
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLETTER:
|
|
|
|
|
ofs << ",letterpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLEGAL:
|
|
|
|
|
ofs << ",legalpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USEXECUTIVE:
|
|
|
|
|
ofs << ",executivepaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A3:
|
|
|
|
|
ofs << ",a3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A4:
|
|
|
|
|
ofs << ",a4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A5:
|
|
|
|
|
ofs << ",a5paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B3:
|
|
|
|
|
ofs << ",b3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B4:
|
|
|
|
|
ofs << ",b4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B5:
|
|
|
|
|
ofs << ",b5paper";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// default papersize ie BufferParams::VM_PAPER_DEFAULT
|
2000-03-12 10:35:05 +00:00
|
|
|
|
switch (lyxrc.default_papersize) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
case BufferParams::PAPER_DEFAULT: // keep compiler happy
|
|
|
|
|
case BufferParams::PAPER_USLETTER:
|
|
|
|
|
ofs << ",letterpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
|
|
|
|
ofs << ",legalpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
|
|
|
|
ofs << ",executivepaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A3PAPER:
|
|
|
|
|
ofs << ",a3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
|
|
|
|
ofs << ",a4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
|
|
|
|
ofs << ",a5paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_B5PAPER:
|
|
|
|
|
ofs << ",b5paper";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!params.topmargin.empty())
|
|
|
|
|
ofs << ",tmargin=" << params.topmargin;
|
|
|
|
|
if (!params.bottommargin.empty())
|
|
|
|
|
ofs << ",bmargin=" << params.bottommargin;
|
|
|
|
|
if (!params.leftmargin.empty())
|
|
|
|
|
ofs << ",lmargin=" << params.leftmargin;
|
|
|
|
|
if (!params.rightmargin.empty())
|
|
|
|
|
ofs << ",rmargin=" << params.rightmargin;
|
|
|
|
|
if (!params.headheight.empty())
|
|
|
|
|
ofs << ",headheight=" << params.headheight;
|
|
|
|
|
if (!params.headsep.empty())
|
|
|
|
|
ofs << ",headsep=" << params.headsep;
|
|
|
|
|
if (!params.footskip.empty())
|
|
|
|
|
ofs << ",footskip=" << params.footskip;
|
|
|
|
|
ofs << "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2001-11-19 15:34:11 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
if (tokenPos(tclass.opt_pagestyle(),
|
|
|
|
|
'|', params.pagestyle) >= 0) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.pagestyle == "fancy") {
|
|
|
|
|
ofs << "\\usepackage{fancyhdr}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
ofs << "\\pagestyle{" << params.pagestyle << "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.secnumdepth != tclass.secnumdepth()) {
|
|
|
|
|
ofs << "\\setcounter{secnumdepth}{"
|
|
|
|
|
<< params.secnumdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (params.tocdepth != tclass.tocdepth()) {
|
|
|
|
|
ofs << "\\setcounter{tocdepth}{"
|
|
|
|
|
<< params.tocdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.paragraph_separation) {
|
|
|
|
|
switch (params.defskip.kind()) {
|
|
|
|
|
case VSpace::SMALLSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\smallskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::MEDSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\medskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::BIGSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\bigskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::LENGTH:
|
|
|
|
|
ofs << "\\setlength\\parskip{"
|
|
|
|
|
<< params.defskip.length().asLatexString()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
break;
|
|
|
|
|
default: // should never happen // Then delete it.
|
|
|
|
|
ofs << "\\setlength\\parskip{\\medskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
|
|
|
|
ofs << "\\setlength\\parindent{0pt}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now insert the LyX specific LaTeX commands...
|
|
|
|
|
|
|
|
|
|
// The optional packages;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
string preamble(features.getPackages());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// this might be useful...
|
2000-07-04 19:16:35 +00:00
|
|
|
|
preamble += "\n\\makeatletter\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// Some macros LyX will need
|
2000-07-04 19:16:35 +00:00
|
|
|
|
string tmppreamble(features.getMacros());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
if (!tmppreamble.empty()) {
|
|
|
|
|
preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"LyX specific LaTeX commands.\n"
|
|
|
|
|
+ tmppreamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the text class specific preamble
|
2000-04-10 21:40:13 +00:00
|
|
|
|
tmppreamble = features.getTClassPreamble();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!tmppreamble.empty()) {
|
|
|
|
|
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"Textclass specific LaTeX commands.\n"
|
|
|
|
|
+ tmppreamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the user-defined preamble */
|
|
|
|
|
if (!params.preamble.empty()) {
|
|
|
|
|
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"User specified LaTeX commands.\n"
|
|
|
|
|
+ params.preamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
preamble += "\\makeatother\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// Itemize bullet settings need to be last in case the user
|
|
|
|
|
// defines their own bullets that use a package included
|
|
|
|
|
// in the user-defined preamble -- ARRae
|
|
|
|
|
// Actually it has to be done much later than that
|
|
|
|
|
// since some packages like frenchb make modifications
|
|
|
|
|
// at \begin{document} time -- JMarc
|
|
|
|
|
string bullets_def;
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
|
|
|
|
|
if (bullets_def.empty())
|
|
|
|
|
bullets_def="\\AtBeginDocument{\n";
|
|
|
|
|
bullets_def += " \\renewcommand{\\labelitemi";
|
|
|
|
|
switch (i) {
|
|
|
|
|
// `i' is one less than the item to modify
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
bullets_def += 'i';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
bullets_def += "ii";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
bullets_def += 'v';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bullets_def += "}{" +
|
|
|
|
|
params.user_defined_bullets[i].getText()
|
|
|
|
|
+ "}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bullets_def.empty())
|
|
|
|
|
preamble += bullets_def + "}\n\n";
|
|
|
|
|
|
|
|
|
|
for (int j = countChar(preamble, '\n'); j-- ;) {
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << preamble;
|
|
|
|
|
|
2001-10-04 13:00:25 +00:00
|
|
|
|
// We try to load babel late, in case it interferes
|
|
|
|
|
// with other packages.
|
|
|
|
|
if (use_babel) {
|
|
|
|
|
string tmp = lyxrc.language_package;
|
|
|
|
|
if (!lyxrc.language_global_options
|
|
|
|
|
&& tmp == "\\usepackage{babel}")
|
|
|
|
|
tmp = string("\\usepackage[") +
|
|
|
|
|
language_options.str().c_str() +
|
|
|
|
|
"]{babel}";
|
|
|
|
|
ofs << tmp << "\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// make the body.
|
2000-07-04 19:16:35 +00:00
|
|
|
|
ofs << "\\begin{document}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
} // only_body
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
|
2001-03-01 15:57:10 +00:00
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (!lyxrc.language_auto_begin) {
|
2000-03-17 10:14:46 +00:00
|
|
|
|
ofs << subst(lyxrc.language_command_begin, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-03-17 10:14:46 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
latexParagraphs(ofs, paragraph, 0, texrow);
|
|
|
|
|
|
|
|
|
|
// add this just in case after all the paragraphs
|
|
|
|
|
ofs << endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2001-03-01 15:57:10 +00:00
|
|
|
|
if (!lyxrc.language_auto_end) {
|
2000-05-04 08:14:34 +00:00
|
|
|
|
ofs << subst(lyxrc.language_command_end, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-05-04 08:14:34 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!only_body) {
|
|
|
|
|
ofs << "\\end{document}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
|
|
|
|
|
<< 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;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Finished making latex file." << endl;
|
2001-12-11 14:33:52 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
//
|
|
|
|
|
// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
|
|
|
|
|
//
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
|
2002-01-08 14:24:49 +00:00
|
|
|
|
Paragraph * endpar, TexRow & texrow) const
|
2000-05-04 08:14:34 +00:00
|
|
|
|
{
|
2000-03-06 02:42:40 +00:00
|
|
|
|
bool was_title = false;
|
|
|
|
|
bool already_title = false;
|
|
|
|
|
|
|
|
|
|
// if only_body
|
2000-05-04 08:14:34 +00:00
|
|
|
|
while (par != endpar) {
|
2002-01-08 14:24:49 +00:00
|
|
|
|
Inset * in = par->inInset();
|
|
|
|
|
// well we have to check if we are in an inset with unlimited
|
|
|
|
|
// lenght (all in one row) if that is true then we don't allow
|
|
|
|
|
// any special options in the paragraph and also we don't allow
|
|
|
|
|
// any environment other then "Standard" to be valid!
|
|
|
|
|
if ((in == 0) || !in->forceDefaultParagraphs(in)) {
|
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass, par->layout);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
if (layout.intitle) {
|
2002-01-08 14:24:49 +00:00
|
|
|
|
if (already_title) {
|
|
|
|
|
lyxerr <<"Error in latexParagraphs: You"
|
|
|
|
|
" should not mix title layouts"
|
|
|
|
|
" with normal ones." << endl;
|
|
|
|
|
} else
|
|
|
|
|
was_title = true;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
} else if (was_title && !already_title) {
|
2002-01-08 14:24:49 +00:00
|
|
|
|
ofs << "\\maketitle\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
already_title = true;
|
|
|
|
|
was_title = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (layout.isEnvironment()) {
|
|
|
|
|
par = par->TeXEnvironment(this, params, ofs, texrow);
|
|
|
|
|
} else {
|
|
|
|
|
par = par->TeXOnePar(this, params, ofs, texrow, false);
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
} else {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
par = par->TeXOnePar(this, params, ofs, texrow, false);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// It might be that we only have a title in this document
|
|
|
|
|
if (was_title && !already_title) {
|
|
|
|
|
ofs << "\\maketitle\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLatex() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLinuxDoc() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLiterate() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isDocBook() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isSGML() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
|
|
|
|
|
textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth,
|
1999-12-07 00:44:53 +00:00
|
|
|
|
string const & latexname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (!latexname.empty() && latexname != "!-- --")
|
2001-11-07 13:22:43 +00:00
|
|
|
|
//os << "<!-- " << depth << " -->" << "<" << latexname << ">";
|
|
|
|
|
os << string(depth, ' ') << "<" << latexname << ">\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
string const & latexname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (!latexname.empty() && latexname != "!-- --")
|
2001-11-07 13:22:43 +00:00
|
|
|
|
//os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
|
|
|
|
|
os << string(depth, ' ') << "</" << latexname << ">\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-21 06:10:21 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
if (!ofs) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
niceFile = nice; // this will be used by included files.
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
|
|
|
|
|
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
|
|
|
|
validate(features);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
string top_element = textclasslist.LatexnameOfClass(params.textclass);
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << "<!doctype linuxdoc system";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
string preamble = params.preamble;
|
|
|
|
|
preamble += features.getIncludedFiles(fname);
|
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
|
|
|
|
|
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << " [ " << preamble << " ]";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << ">\n\n";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (params.options.empty())
|
2000-07-01 12:54:45 +00:00
|
|
|
|
sgmlOpenTag(ofs, 0, top_element);
|
|
|
|
|
else {
|
|
|
|
|
string top = top_element;
|
|
|
|
|
top += " ";
|
|
|
|
|
top += params.options;
|
|
|
|
|
sgmlOpenTag(ofs, 0, top);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-03 15:49:32 +00:00
|
|
|
|
ofs << "<!-- " << lyx_docversion
|
2000-01-19 14:07:39 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/"
|
|
|
|
|
<< " -->\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
|
|
|
|
Paragraph * par = paragraph;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
string item_name;
|
|
|
|
|
vector<string> environment_stack(5);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXLayout const & style =
|
2000-07-01 12:54:45 +00:00
|
|
|
|
textclasslist.Style(params.textclass,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
par->layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// treat <toc> as a special case for compatibility with old code
|
2001-11-23 10:16:02 +00:00
|
|
|
|
if (par->isInset(0)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (lyx_code == Inset::TOC_CODE){
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const temp = "toc";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, temp);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// environment tag closing
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (; depth > par->params().depth(); --depth) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// write opening SGML tags
|
2000-09-26 13:54:57 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
--depth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (depth!= 0)
|
2001-11-07 13:22:43 +00:00
|
|
|
|
sgmlError(par, 0,
|
|
|
|
|
_("Error : Wrong depth for"
|
|
|
|
|
" LatexType Command.\n"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (!environment_stack[depth].empty()){
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth,
|
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
2001-03-21 23:38:07 +00:00
|
|
|
|
&& environment_stack[depth] != style.latexname()) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth < par->params().depth()) {
|
|
|
|
|
depth = par->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (environment_stack[depth] != style.latexname()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth == 0) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, "p");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1)
|
2001-03-21 23:38:07 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
1999-11-04 01:40:20 +00:00
|
|
|
|
environment_stack[depth] = style.latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "<![CDATA[";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latextype == LATEX_ENVIRONMENT) break;
|
|
|
|
|
|
|
|
|
|
if (style.labeltype == LABEL_MANUAL)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "tag";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "item";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
simpleLinuxDocOnePar(ofs, par, depth);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "\n";
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "]]>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Close open tags
|
2001-03-21 23:38:07 +00:00
|
|
|
|
for (int i=depth; i >= 0; --i)
|
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[i]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
|
|
|
|
ofs << "\n\n";
|
|
|
|
|
sgmlCloseTag(ofs, 0, top_element);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// checks, if newcol chars should be put into this line
|
|
|
|
|
// writes newline, if necessary.
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2001-11-08 11:32:18 +00:00
|
|
|
|
void sgmlLineBreak(ostream & os, string::size_type & colcount,
|
2000-09-27 17:07:33 +00:00
|
|
|
|
string::size_type newcol)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
colcount += newcol;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (colcount > lyxrc.ascii_linelen) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
colcount = newcol; // assume write after this call
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
enum PAR_TAG {
|
|
|
|
|
NONE=0,
|
|
|
|
|
TT = 1,
|
|
|
|
|
SF = 2,
|
|
|
|
|
BF = 4,
|
|
|
|
|
IT = 8,
|
|
|
|
|
SL = 16,
|
|
|
|
|
EM = 32
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string tag_name(PAR_TAG const & pt) {
|
|
|
|
|
switch (pt) {
|
2001-03-23 16:46:39 +00:00
|
|
|
|
case NONE: return "!-- --";
|
|
|
|
|
case TT: return "tt";
|
|
|
|
|
case SF: return "sf";
|
|
|
|
|
case BF: return "bf";
|
|
|
|
|
case IT: return "it";
|
|
|
|
|
case SL: return "sl";
|
|
|
|
|
case EM: return "em";
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 | p2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void reset(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
|
|
|
|
p1 = static_cast<PAR_TAG>( p1 & ~p2);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
// Handle internal paragraph parsing -- layout already processed.
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::simpleLinuxDocOnePar(ostream & os,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par,
|
|
|
|
|
Paragraph::depth_type /*depth*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXLayout const & style = textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2001-11-29 17:12:21 +00:00
|
|
|
|
string::size_type char_line_count = 5; // Heuristic choice ;-)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// gets paragraph main font
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont font_old;
|
|
|
|
|
bool desc_on;
|
|
|
|
|
if (style.labeltype == LABEL_MANUAL) {
|
|
|
|
|
font_old = style.labelfont;
|
|
|
|
|
desc_on = true;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
} else {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = style.font;
|
|
|
|
|
desc_on = false;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
|
|
|
|
|
LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
|
|
|
|
|
LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
|
|
|
|
|
bool is_em = false;
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
stack<PAR_TAG> tag_state;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// parsing main loop
|
2001-11-27 10:34:16 +00:00
|
|
|
|
for (pos_type i = 0; i < par->size(); ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
PAR_TAG tag_close = NONE;
|
|
|
|
|
list < PAR_TAG > tag_open;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont const font = par->getFont(params, i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.family() != font.family()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (family_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SANS_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SF;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= TT;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
family_type = font.family();
|
|
|
|
|
|
|
|
|
|
switch (family_type) {
|
|
|
|
|
case LyXFont::SANS_FAMILY:
|
|
|
|
|
tag_open.push_back(SF);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
|
|
|
|
tag_open.push_back(TT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.series() != font.series()) {
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= BF;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series_type = font.series();
|
|
|
|
|
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
|
|
|
|
tag_open.push_back(BF);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.shape() != font.shape()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (shape_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= IT;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SL;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shape_type = font.shape();
|
|
|
|
|
|
|
|
|
|
switch (shape_type) {
|
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
|
|
|
|
tag_open.push_back(IT);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
|
|
|
|
tag_open.push_back(SL);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// handle <em> tag
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
|
|
|
|
tag_open.push_back(EM);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = true;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (is_em) {
|
|
|
|
|
tag_close |= EM;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
list < PAR_TAG > temp;
|
2001-12-05 08:04:20 +00:00
|
|
|
|
while (!tag_state.empty() && tag_close ) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
PAR_TAG k = tag_state.top();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "</" << tag_name(k) << ">";
|
|
|
|
|
if (tag_close & k)
|
|
|
|
|
reset(tag_close,k);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
else
|
|
|
|
|
temp.push_back(k);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = temp.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != temp.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "<" << tag_name(*j) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = tag_open.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != tag_open.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "<" << tag_name(*j) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getChar(i);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (c == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(i);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->linuxdoc(this, os);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
|
|
|
|
continue;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-03 18:28:11 +00:00
|
|
|
|
if (style.latexparam() == "CDATA") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
// "TeX"-Mode on == > SGML-Mode on.
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (c != '\0')
|
2001-03-21 23:38:07 +00:00
|
|
|
|
os << c;
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
2000-03-09 23:58:55 +00:00
|
|
|
|
} else {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string sgml_string;
|
2001-11-08 11:32:18 +00:00
|
|
|
|
if (par->sgmlConvertChar(c, sgml_string)
|
2001-11-29 16:29:30 +00:00
|
|
|
|
&& !style.free_spacing && !par->isFreeSpacing())
|
|
|
|
|
{
|
2001-03-21 23:38:07 +00:00
|
|
|
|
// in freespacing mode, spaces are
|
|
|
|
|
// non-breaking characters
|
|
|
|
|
if (desc_on) {// if char is ' ' then...
|
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 6);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "</tag>";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = false;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 1);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << c;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << sgml_string;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
char_line_count += sgml_string.length();
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
while (!tag_state.empty()) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "</" << tag_name(tag_state.top()) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (desc_on) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <tag> not closed...
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 6);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "</tag>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Print an error message.
|
2001-11-07 13:22:43 +00:00
|
|
|
|
void Buffer::sgmlError(Paragraph * par, int pos,
|
|
|
|
|
string const & message) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// insert an error marker in text
|
2000-06-28 13:35:52 +00:00
|
|
|
|
InsetError * new_inset = new InsetError(message);
|
2001-12-15 15:03:06 +00:00
|
|
|
|
par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
|
|
|
|
|
params.language));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-23 08:37:44 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
|
|
|
|
validate(features);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
texrow.reset();
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string top_element = textclasslist.LatexnameOfClass(params.textclass);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!only_body) {
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << "<!DOCTYPE " << top_element
|
2001-10-24 13:08:52 +00:00
|
|
|
|
<< " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
string preamble = params.preamble;
|
|
|
|
|
preamble += features.getIncludedFiles(fname);
|
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << "\n [ " << preamble << " ]";
|
|
|
|
|
}
|
|
|
|
|
ofs << ">\n\n";
|
2000-11-13 15:43:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-01-28 21:54:15 +00:00
|
|
|
|
string top = top_element;
|
|
|
|
|
top += " lang=\"";
|
|
|
|
|
top += params.language->code();
|
|
|
|
|
top += "\"";
|
|
|
|
|
|
|
|
|
|
if (!params.options.empty()) {
|
2000-11-13 15:43:36 +00:00
|
|
|
|
top += " ";
|
|
|
|
|
top += params.options;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlOpenTag(ofs, 0, top);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-03 15:49:32 +00:00
|
|
|
|
ofs << "<!-- DocBook file was created by " << lyx_docversion
|
2000-07-01 12:54:45 +00:00
|
|
|
|
<< "\n See http://www.lyx.org/ for more information -->\n";
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
vector<string> environment_stack(10);
|
|
|
|
|
vector<string> environment_inner(10);
|
|
|
|
|
vector<string> command_stack(10);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
bool command_flag = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type command_depth = 0;
|
|
|
|
|
Paragraph::depth_type command_base = 0;
|
|
|
|
|
Paragraph::depth_type cmd_depth = 0;
|
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string item_name;
|
|
|
|
|
string command_name;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string sgmlparam;
|
|
|
|
|
string c_depth;
|
|
|
|
|
string c_params;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int desc_on = 0; // description mode
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
LyXLayout const & style =
|
2000-07-01 12:54:45 +00:00
|
|
|
|
textclasslist.Style(params.textclass,
|
2000-02-29 02:19:17 +00:00
|
|
|
|
par->layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// environment tag closing
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (; depth > par->params().depth(); --depth) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth + depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth+command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
&& environment_stack[depth] != style.latexname()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth+depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
|
|
|
|
depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write opening SGML tags.
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2001-04-04 21:47:26 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (depth != 0)
|
2001-11-07 13:22:43 +00:00
|
|
|
|
sgmlError(par, 0,
|
|
|
|
|
_("Error : Wrong depth for "
|
|
|
|
|
"LatexType Command.\n"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
command_name = style.latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlparam = style.latexparam();
|
|
|
|
|
c_params = split(sgmlparam, c_depth,'|');
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cmd_depth = lyx::atoi(c_depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (command_flag) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (cmd_depth < command_base) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
} else if (cmd_depth <= command_depth) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= int(cmd_depth); --j)
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
|
|
|
|
command_flag = true;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (command_stack.size() == command_depth + 1)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
command_stack.push_back(string());
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_stack[command_depth] = command_name;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// treat label as a special case for
|
|
|
|
|
// more WYSIWYM handling.
|
2001-11-30 11:56:04 +00:00
|
|
|
|
// This is a hack while paragraphs can't have
|
|
|
|
|
// attributes, like id in this case.
|
2001-11-23 10:16:02 +00:00
|
|
|
|
if (par->isInset(0)) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (lyx_code == Inset::LABEL_CODE){
|
1999-12-07 00:44:53 +00:00
|
|
|
|
command_name += " id=\"";
|
|
|
|
|
command_name += (static_cast<InsetCommand *>(inset))->getContents();
|
|
|
|
|
command_name += "\"";
|
|
|
|
|
desc_on = 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth, command_name);
|
2001-02-11 21:25:34 +00:00
|
|
|
|
if (c_params.empty())
|
|
|
|
|
item_name = "title";
|
|
|
|
|
else
|
|
|
|
|
item_name = c_params;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth < par->params().depth()) {
|
|
|
|
|
depth = par->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (environment_stack[depth] != style.latexname()) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if(environment_stack.size() == depth + 1) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
environment_stack[depth] = style.latexname();
|
|
|
|
|
environment_inner[depth] = "!-- --";
|
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
} else {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
command_depth + depth,
|
|
|
|
|
item_name);
|
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
|
|
|
|
depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (style.latextype == LATEX_ENVIRONMENT) {
|
2001-01-28 21:54:15 +00:00
|
|
|
|
if (!style.latexparam().empty()) {
|
|
|
|
|
if(style.latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "<![CDATA[";
|
2001-01-28 21:54:15 +00:00
|
|
|
|
else
|
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexparam());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
desc_on = (style.labeltype == LABEL_MANUAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_inner[depth]= "varlistentry";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_inner[depth]= "listitem";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on) {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "term";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "para";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-14 09:46:05 +00:00
|
|
|
|
simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string end_tag;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2001-02-11 21:25:34 +00:00
|
|
|
|
if (c_params.empty())
|
|
|
|
|
end_tag = "title";
|
|
|
|
|
else
|
|
|
|
|
end_tag = c_params;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
2001-01-28 21:54:15 +00:00
|
|
|
|
if (!style.latexparam().empty()) {
|
|
|
|
|
if(style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "]]>";
|
|
|
|
|
else
|
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexparam());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on == 1) break;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
end_tag= "para";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_PARAGRAPH:
|
2000-11-13 15:43:36 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-11-13 15:43:36 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close open tags
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int d = depth; d >= 0; --d) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!environment_stack[depth].empty()) {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth + depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= 0 ; --j)
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!command_stack[j].empty())
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-13 15:43:36 +00:00
|
|
|
|
ofs << "\n\n";
|
|
|
|
|
sgmlCloseTag(ofs, 0, top_element);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-14 09:46:05 +00:00
|
|
|
|
void Buffer::simpleDocBookOnePar(ostream & os,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par, int & desc_on,
|
|
|
|
|
Paragraph::depth_type depth) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
bool emph_flag = false;
|
|
|
|
|
|
|
|
|
|
LyXLayout const & style = textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
int char_line_count = depth;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
//if (!style.free_spacing)
|
|
|
|
|
// os << string(depth,' ');
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// parsing main loop
|
2001-11-27 10:34:16 +00:00
|
|
|
|
for (pos_type i = 0; i < par->size(); ++i) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
LyXFont font = par->getFont(params, i);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// handle <emphasis> tag
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "<emphasis>";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = true;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}else if(i) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = false;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-30 11:56:04 +00:00
|
|
|
|
if ( par->isInset(i) ) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset * inset = par->getInset(i);
|
2001-11-30 11:56:04 +00:00
|
|
|
|
// don't print the inset in position 0 if desc_on == 3 (label)
|
|
|
|
|
if ( i || desc_on != 3)
|
|
|
|
|
inset->docbook(this, os);
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2001-11-30 11:56:04 +00:00
|
|
|
|
char c = par->getChar(i);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string sgml_string;
|
2001-11-08 11:32:18 +00:00
|
|
|
|
par->sgmlConvertChar(c, sgml_string);
|
2001-10-03 17:28:08 +00:00
|
|
|
|
|
|
|
|
|
if (style.pass_thru) {
|
|
|
|
|
os << c;
|
2001-11-29 16:29:30 +00:00
|
|
|
|
} else if(style.free_spacing || par->isFreeSpacing() || c != ' ') {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
os << sgml_string;
|
|
|
|
|
} else if (desc_on ==1) {
|
|
|
|
|
++char_line_count;
|
|
|
|
|
os << "\n</term><listitem><para>";
|
|
|
|
|
desc_on = 2;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
os << ' ';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-23 08:37:44 +00:00
|
|
|
|
font_old = font;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (emph_flag) {
|
|
|
|
|
os << "</emphasis>";
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (desc_on == 1) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <term> not closed...
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</term>";
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if(style.free_spacing) os << '\n';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This should be enabled when the Chktex class is implemented. (Asger)
|
|
|
|
|
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
|
|
|
|
|
// Other flags: -wall -v0 -x
|
|
|
|
|
int Buffer::runChktex()
|
|
|
|
|
{
|
1999-12-10 00:07:59 +00:00
|
|
|
|
if (!users->text) return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
|
users->owner()->prohibitInput();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// get LaTeX-Filename
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const name = getLatexName();
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string path = OnlyPath(filename);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const org_path = path;
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
path = tmppath;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
|
Path p(path); // path to LaTeX file
|
2001-04-24 17:33:01 +00:00
|
|
|
|
users->owner()->message(_("Running chktex..."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Remove all error insets
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool const removedErrorInsets = users->removeAutoInsets();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Generate the LaTeX file if neccessary
|
2000-06-20 12:49:14 +00:00
|
|
|
|
makeLaTeXFile(name, org_path, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
TeXErrors terr;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Chktex chktex(lyxrc.chktex_command, name, filepath);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int res = chktex.run(terr); // run chktex
|
|
|
|
|
|
|
|
|
|
if (res == -1) {
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("chktex did not work!"),
|
1999-09-27 18:44:28 +00:00
|
|
|
|
_("Could not run with file:"), name);
|
|
|
|
|
} else if (res > 0) {
|
|
|
|
|
// Insert all errors as errors boxes
|
2000-01-08 21:02:58 +00:00
|
|
|
|
users->insertErrors(terr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we removed error insets before we ran chktex or if we inserted
|
|
|
|
|
// error insets after we ran chktex, this must be run:
|
2000-06-20 12:49:14 +00:00
|
|
|
|
if (removedErrorInsets || res){
|
1999-09-27 18:44:28 +00:00
|
|
|
|
users->redraw();
|
2001-08-02 14:55:06 +00:00
|
|
|
|
users->fitCursor();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-03 15:19:04 +00:00
|
|
|
|
users->owner()->allowInput();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
void Buffer::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
1999-11-04 01:40:20 +00:00
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// AMS Style is at document level
|
2001-11-19 15:34:11 +00:00
|
|
|
|
if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("amsmath");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
while (par) {
|
|
|
|
|
// We don't use "lyxerr.debug" because of speed. (Asger)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX))
|
|
|
|
|
lyxerr << "Paragraph: " << par << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now just follow the list of paragraphs and run
|
|
|
|
|
// validate on each of them.
|
|
|
|
|
par->validate(features);
|
|
|
|
|
|
|
|
|
|
// and then the next paragraph
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the bullet shapes are buffer level not paragraph level
|
|
|
|
|
// so they are tested here
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const font = params.user_defined_bullets[i].getFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (font == 0) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const c = params
|
1999-11-04 01:40:20 +00:00
|
|
|
|
.user_defined_bullets[i]
|
|
|
|
|
.getCharacter();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (c == 16
|
|
|
|
|
|| c == 17
|
|
|
|
|
|| c == 25
|
|
|
|
|
|| c == 26
|
|
|
|
|
|| c == 31) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("latexsym");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if (font == 1) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("amssymb");
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if ((font >= 2 && font <= 5)) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("pifont");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX)) {
|
2000-04-10 21:40:13 +00:00
|
|
|
|
features.showStruct();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This function should be in Buffer because it's a buffer's property (ale)
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getIncludeonlyList(char delim)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
string lst;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
|
|
|
|
it != inset_iterator_end(); ++it) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
InsetInclude * insetinc =
|
|
|
|
|
static_cast<InsetInclude *>(*it);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (insetinc->isIncludeOnly()) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
if (!lst.empty())
|
|
|
|
|
lst += delim;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
lst += insetinc->getRelFileBaseName();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return lst;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
vector<string> const Buffer::getLabelList()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990407]
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (!params.parentname.empty()
|
|
|
|
|
&& bufferlist.exists(params.parentname)) {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(params.parentname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tmp)
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return tmp->getLabelList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
|
vector<string> label_list;
|
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
|
|
|
|
it != inset_iterator_end(); ++it) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
vector<string> const l = (*it)->getLabelList();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
label_list.insert(label_list.end(), l.begin(), l.end());
|
|
|
|
|
}
|
|
|
|
|
return label_list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-12 01:43:12 +00:00
|
|
|
|
Buffer::Lists const Buffer::getLists() const
|
2000-05-19 16:46:01 +00:00
|
|
|
|
{
|
2001-03-12 01:43:12 +00:00
|
|
|
|
Lists l;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2001-09-02 14:43:59 +00:00
|
|
|
|
|
|
|
|
|
#if 1
|
2001-11-29 17:12:21 +00:00
|
|
|
|
std::pair<bool, textclass_type> const tmp =
|
2001-09-02 14:43:59 +00:00
|
|
|
|
textclasslist.NumberOfLayout(params.textclass, "Caption");
|
|
|
|
|
bool const found = tmp.first;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
textclass_type const cap = tmp.second;
|
2001-09-02 14:43:59 +00:00
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
// This is the prefered way to to this, but boost::tie can break
|
|
|
|
|
// some compilers
|
2001-03-12 13:08:03 +00:00
|
|
|
|
bool found;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
textclass_type cap;
|
2001-03-15 16:04:46 +00:00
|
|
|
|
boost::tie(found, cap) = textclasslist
|
|
|
|
|
.NumberOfLayout(params.textclass, "Caption");
|
2001-09-02 14:43:59 +00:00
|
|
|
|
#endif
|
2001-03-12 13:08:03 +00:00
|
|
|
|
|
2000-01-25 12:35:27 +00:00
|
|
|
|
while (par) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
char const labeltype =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout()).labeltype;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
|
|
if (labeltype >= LABEL_COUNTER_CHAPTER
|
|
|
|
|
&& labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
// insert this into the table of contents
|
2001-05-04 10:36:36 +00:00
|
|
|
|
SingleList & item = l["TOC"];
|
|
|
|
|
int depth = max(0,
|
|
|
|
|
labeltype -
|
|
|
|
|
textclasslist.TextClass(params.textclass).maxcounter());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
item.push_back(TocItem(par, depth, par->asString(this, true)));
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
// For each paragrph, traverse its insets and look for
|
|
|
|
|
// FLOAT_CODE
|
|
|
|
|
|
|
|
|
|
if (found) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::inset_iterator it =
|
2001-05-04 10:36:36 +00:00
|
|
|
|
par->inset_iterator_begin();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::inset_iterator end =
|
2001-05-04 10:36:36 +00:00
|
|
|
|
par->inset_iterator_end();
|
2001-03-12 01:43:12 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
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...
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Paragraph * tmp = il->inset.paragraph();
|
2001-05-04 10:36:36 +00:00
|
|
|
|
while (tmp) {
|
|
|
|
|
if (tmp->layout == cap) {
|
|
|
|
|
SingleList & item = l[type];
|
|
|
|
|
string const str =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tostr(item.size()+1) + ". " + tmp->asString(this, false);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
item.push_back(TocItem(tmp, 0 , str));
|
2001-03-11 20:04:33 +00:00
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
tmp = tmp->next();
|
2001-03-11 20:04:33 +00:00
|
|
|
|
}
|
2001-03-11 18:39:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "caption not found" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return l;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This is also a buffer property (ale)
|
2001-03-12 01:43:12 +00:00
|
|
|
|
vector<pair<string, string> > const Buffer::getBibkeyList()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990412]
|
|
|
|
|
if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(params.parentname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tmp)
|
2000-06-07 08:53:40 +00:00
|
|
|
|
return tmp->getBibkeyList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
vector<pair<string, string> > keys;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2000-06-07 08:53:40 +00:00
|
|
|
|
if (par->bibkey)
|
2000-07-19 17:16:27 +00:00
|
|
|
|
keys.push_back(pair<string, string>(par->bibkey->getContents(),
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->asString(this, false)));
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Might be either using bibtex or a child has bibliography
|
2000-06-07 08:53:40 +00:00
|
|
|
|
if (keys.empty()) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
2000-06-07 08:53:40 +00:00
|
|
|
|
it != inset_iterator_end(); ++it) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Search for Bibtex or Include inset
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
|
2000-06-07 08:53:40 +00:00
|
|
|
|
vector<pair<string,string> > tmp =
|
2000-10-03 09:13:34 +00:00
|
|
|
|
static_cast<InsetBibtex*>(*it)->getKeys(this);
|
2000-06-07 08:53:40 +00:00
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
2001-06-28 10:25:20 +00:00
|
|
|
|
} else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
vector<pair<string,string> > const tmp =
|
2000-06-07 08:53:40 +00:00
|
|
|
|
static_cast<InsetInclude*>(*it)->getKeys();
|
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-07 08:53:40 +00:00
|
|
|
|
return keys;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool Buffer::isDepClean(string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
DEPCLEAN * item = dep_clean;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (item && item->master != name)
|
|
|
|
|
item = item->next;
|
|
|
|
|
if (!item) return true;
|
|
|
|
|
return item->clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void Buffer::markDepClean(string const & name)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (!dep_clean) {
|
|
|
|
|
dep_clean = new DEPCLEAN;
|
|
|
|
|
dep_clean->clean = true;
|
|
|
|
|
dep_clean->master = name;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
dep_clean->next = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
DEPCLEAN * item = dep_clean;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (item && item->master != name)
|
|
|
|
|
item = item->next;
|
|
|
|
|
if (item) {
|
|
|
|
|
item->clean = true;
|
|
|
|
|
} else {
|
|
|
|
|
item = new DEPCLEAN;
|
|
|
|
|
item->clean = true;
|
|
|
|
|
item->master = name;
|
2000-05-26 00:00:02 +00:00
|
|
|
|
item->next = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool Buffer::dispatch(string const & command)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
// Split command string into command and argument
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string cmd;
|
|
|
|
|
string line = frontStrip(command);
|
|
|
|
|
string const arg = strip(frontStrip(split(line, cmd, ' ')));
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return dispatch(lyxaction.LookupFunc(cmd), arg);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool Buffer::dispatch(int action, string const & argument)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2000-04-28 11:18:04 +00:00
|
|
|
|
bool dispatched = true;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
switch (action) {
|
1999-12-15 17:42:22 +00:00
|
|
|
|
case LFUN_EXPORT:
|
2000-08-30 03:40:51 +00:00
|
|
|
|
Exporter::Export(this, argument, false);
|
1999-12-15 17:42:22 +00:00
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2000-04-28 11:18:04 +00:00
|
|
|
|
dispatched = false;
|
|
|
|
|
}
|
|
|
|
|
return dispatched;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
|
void Buffer::resizeInsets(BufferView * bv)
|
|
|
|
|
{
|
2000-06-23 15:02:46 +00:00
|
|
|
|
/// then remove all LyXText in text-insets
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
for (; par; par = par->next()) {
|
2000-07-14 14:57:20 +00:00
|
|
|
|
par->resizeInsetsLyXText(bv);
|
2000-06-23 15:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::redraw()
|
|
|
|
|
{
|
|
|
|
|
users->redraw();
|
2001-08-02 14:55:06 +00:00
|
|
|
|
users->fitCursor();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::changeLanguage(Language const * from, Language const * to)
|
2000-04-10 21:40:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator end = par_iterator_end();
|
|
|
|
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
|
|
|
|
(*it)->changeLanguage(params, from, to);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
bool Buffer::isMultiLingual()
|
|
|
|
|
{
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator end = par_iterator_end();
|
|
|
|
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
|
|
|
|
if ((*it)->isMultiLingual(params))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return true;
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
|
2000-09-26 13:54:57 +00:00
|
|
|
|
: par(paragraph)
|
|
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
|
it = par->InsetIterator(pos);
|
|
|
|
|
if (it == par->inset_iterator_end()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2001-06-28 10:25:20 +00:00
|
|
|
|
setParagraph();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::inset_iterator::setParagraph()
|
2000-09-26 13:54:57 +00:00
|
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
|
while (par) {
|
|
|
|
|
it = par->inset_iterator_begin();
|
|
|
|
|
if (it != par->inset_iterator_end())
|
|
|
|
|
return;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
//it = 0;
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// We maintain an invariant that whenever par = 0 then it = 0
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * Buffer::getInsetFromID(int id_arg) const
|
|
|
|
|
{
|
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if ((*it)->id() == id_arg)
|
|
|
|
|
return *it;
|
|
|
|
|
Inset * in = (*it)->getInsetFromID(id_arg);
|
|
|
|
|
if (in)
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph * Buffer::getParFromID(int id) const
|
|
|
|
|
{
|
|
|
|
|
if (id < 0) return 0;
|
|
|
|
|
Paragraph * par = paragraph;
|
|
|
|
|
while (par) {
|
|
|
|
|
if (par->id() == id) {
|
|
|
|
|
return par;
|
|
|
|
|
}
|
|
|
|
|
Paragraph * tmp = par->getParFromID(id);
|
|
|
|
|
if (tmp) {
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
par = par->next();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_begin()
|
|
|
|
|
{
|
|
|
|
|
return ParIterator(paragraph);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_end()
|
|
|
|
|
{
|
|
|
|
|
return ParIterator();
|
|
|
|
|
}
|