1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
2002-03-21 16:55:34 +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
|
|
|
|
|
*
|
2002-03-21 16:55:34 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.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 "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"
|
2002-08-09 00:42:12 +00:00
|
|
|
|
#include "sgml.h"
|
2002-08-20 19:41:13 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
|
|
|
|
|
|
|
|
|
#include "frontends/LyXView.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"
|
2002-03-21 16:55:34 +00:00
|
|
|
|
#include "insets/insetbib.h"
|
|
|
|
|
#include "insets/insetcite.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
#include "insets/insetexternal.h"
|
2002-03-21 16:55:34 +00:00
|
|
|
|
#include "insets/insetindex.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetinclude.h"
|
|
|
|
|
#include "insets/insettoc.h"
|
|
|
|
|
#include "insets/insetparent.h"
|
|
|
|
|
#include "insets/insetspecialchar.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"
|
2002-08-23 09:05:32 +00:00
|
|
|
|
#include "insets/insetoptarg.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "insets/insetminipage.h"
|
|
|
|
|
#include "insets/insetfloat.h"
|
2002-09-10 10:18:58 +00:00
|
|
|
|
#include "insets/insetwrap.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"
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.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/lyxlib.h"
|
|
|
|
|
#include "support/FileInfo.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#include "support/lyxmanip.h"
|
2002-01-14 13:04:06 +00:00
|
|
|
|
#include "support/lyxalgo.h" // for lyx::count
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-08-14 22:15:18 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
2002-11-21 18:33:09 +00:00
|
|
|
|
#include "BoostFormat.h"
|
2002-08-14 22:15:18 +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
|
|
|
|
|
|
2002-06-10 07:57:39 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
|
using std::pow;
|
|
|
|
|
#endif
|
2001-12-08 14:20:11 +00:00
|
|
|
|
|
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;
|
2002-08-14 22:15:18 +00:00
|
|
|
|
using std::for_each;
|
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::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;
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2002-08-27 20:30:20 +00:00
|
|
|
|
const int LYX_FORMAT = 221;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer::Buffer(string const & file, bool ronly)
|
2002-08-12 00:15:19 +00:00
|
|
|
|
: niceFile(true), lyx_clean(true), bak_clean(true),
|
2002-01-13 00:33:21 +00:00
|
|
|
|
unnamed(false), dep_clean(0), read_only(ronly),
|
2002-09-06 14:48:01 +00:00
|
|
|
|
filename_(file), users(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
2002-01-14 23:31:23 +00:00
|
|
|
|
filepath_ = OnlyPath(file);
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxvc.buffer(this);
|
2002-01-13 00:33:21 +00:00
|
|
|
|
if (read_only || lyxrc.use_tempdir) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppath = CreateBufferTmpDir();
|
2002-01-13 00:33:21 +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);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!tmppath.empty()) {
|
|
|
|
|
DestroyBufferTmpDir(tmppath);
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.clear();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
|
|
// Remove any previewed LaTeX snippets assocoated with this buffer.
|
|
|
|
|
grfx::Previews::get().removeLoader(this);
|
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
|
|
|
|
{
|
2002-01-14 23:31:23 +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
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
pair<Buffer::LogType, string> const Buffer::getLogName() 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())) {
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::buildlog, bname);
|
|
|
|
|
}
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
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) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
read_only = flag;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
updateTitles();
|
2002-08-13 14:40:38 +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
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
filename_ = MakeAbsPath(newfile);
|
|
|
|
|
filepath_ = OnlyPath(filename_);
|
|
|
|
|
setReadonly(IsFileWriteable(filename_) == 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
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
|
|
|
|
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2001-08-03 18:28:11 +00:00
|
|
|
|
#warning And _why_ is this here? (Lgb)
|
2002-02-26 10:50:48 +00:00
|
|
|
|
#endif
|
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;
|
2002-08-21 07:30:57 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int pos = 0;
|
2002-03-21 16:55:34 +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);
|
2002-05-22 12:33:02 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
2001-01-11 11:06:10 +00:00
|
|
|
|
if (file_format < 216 && params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
2002-05-22 12:33:02 +00:00
|
|
|
|
#endif
|
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;
|
2002-07-21 21:21:06 +00:00
|
|
|
|
par->layout(params.getLyXTextClass().defaultLayout());
|
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);
|
2002-01-13 00:33:21 +00:00
|
|
|
|
first_par = users->text->ownerParagraph();
|
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: `"
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< token << '\'' << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
if (!first_par)
|
|
|
|
|
first_par = par;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.set(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
|
|
|
|
}
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
2002-11-21 18:33:09 +00:00
|
|
|
|
boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#else
|
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
|
|
|
|
_("When reading ") + fileName());
|
|
|
|
|
#endif
|
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");
|
|
|
|
|
}
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
2002-11-21 18:33:09 +00:00
|
|
|
|
boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#else
|
|
|
|
|
Alert::alert(_("Textclass Loading Error!"), s,
|
|
|
|
|
_("When reading ") + fileName());
|
|
|
|
|
#endif
|
2001-11-25 17:58:05 +00:00
|
|
|
|
}
|
2001-07-16 14:11:35 +00:00
|
|
|
|
|
2000-03-01 14:13:21 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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,
|
2002-03-21 16:55:34 +00:00
|
|
|
|
Paragraph::depth_type & depth,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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;
|
2002-05-29 14:32:11 +00:00
|
|
|
|
|
|
|
|
|
// The order of the tags tested may seem unnatural, but this
|
|
|
|
|
// has been done in order to reduce the number of string
|
|
|
|
|
// comparisons needed to recognize a given token. This leads
|
|
|
|
|
// on large documents like UserGuide to a reduction of a
|
|
|
|
|
// factor 5! (JMarc)
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (token[0] != '\\') {
|
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
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\layout") {
|
2002-05-02 12:21:42 +00:00
|
|
|
|
// reset the font as we start a new layout and if the font is
|
|
|
|
|
// not ALL_INHERIT,document_language then it will be set to the
|
|
|
|
|
// right values after this tag (Jug 20020420)
|
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT, params.language);
|
2002-05-22 12:33:02 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
2002-05-02 12:21:42 +00:00
|
|
|
|
if (file_format < 216 && params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
2002-05-22 12:33:02 +00:00
|
|
|
|
#endif
|
2002-05-02 12:21:42 +00:00
|
|
|
|
|
2001-11-29 17:12:21 +00:00
|
|
|
|
lex.eatLine();
|
2002-03-06 14:24:34 +00:00
|
|
|
|
string layoutname = lex.getString();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-06 14:24:34 +00:00
|
|
|
|
|
|
|
|
|
if (layoutname.empty()) {
|
|
|
|
|
layoutname = tclass.defaultLayoutName();
|
|
|
|
|
}
|
2002-03-03 20:25:07 +00:00
|
|
|
|
bool hasLayout = tclass.hasLayout(layoutname);
|
|
|
|
|
if (!hasLayout) {
|
|
|
|
|
lyxerr << "Layout '" << layoutname << "' does not"
|
|
|
|
|
<< " exist in textclass '" << tclass.name()
|
|
|
|
|
<< "'." << endl;
|
2002-03-07 11:08:25 +00:00
|
|
|
|
lyxerr << "Trying to use default layout instead."
|
|
|
|
|
<< endl;
|
|
|
|
|
layoutname = tclass.defaultLayoutName();
|
2002-03-03 20:25:07 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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)
|
2002-07-16 21:17:10 +00:00
|
|
|
|
if (compare_ascii_no_case(layoutname, "caption") == 0) {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// 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)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
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";
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// 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);
|
2002-07-21 21:21:06 +00:00
|
|
|
|
par->layout(params.getLyXTextClass().defaultLayout());
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
pos = 0;
|
2002-07-21 21:21:06 +00:00
|
|
|
|
par->layout(params.getLyXTextClass()[layoutname]);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// Test whether the layout is obsolete.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
|
|
|
|
if (!layout->obsoleted_by().empty())
|
2002-07-21 21:21:06 +00:00
|
|
|
|
par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().depth(depth);
|
2001-03-14 14:54:30 +00:00
|
|
|
|
#if USE_CAPTION
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#endif
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2002-05-29 14:32:11 +00:00
|
|
|
|
} else if (token == "\\end_inset") {
|
|
|
|
|
lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
|
|
|
|
|
<< "Last inset read was: " << last_inset_read
|
|
|
|
|
<< endl;
|
|
|
|
|
// 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.
|
|
|
|
|
} else if (token == "\\begin_inset") {
|
|
|
|
|
readInset(lex, par, pos, font);
|
|
|
|
|
} else if (token == "\\family") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXFamily(lex.getString());
|
|
|
|
|
} else if (token == "\\series") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSeries(lex.getString());
|
|
|
|
|
} else if (token == "\\shape") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXShape(lex.getString());
|
|
|
|
|
} else if (token == "\\size") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSize(lex.getString());
|
|
|
|
|
} else if (token == "\\lang") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const tok = lex.getString();
|
|
|
|
|
Language const * lang = languages.getLanguage(tok);
|
|
|
|
|
if (lang) {
|
|
|
|
|
font.setLanguage(lang);
|
|
|
|
|
} else {
|
|
|
|
|
font.setLanguage(params.language);
|
|
|
|
|
lex.printError("Unknown language `$$Token'");
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\numeric") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setNumber(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\emph") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setEmph(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\bar") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const tok = lex.getString();
|
|
|
|
|
// 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();
|
|
|
|
|
font.setNoun(font.setLyXMisc(lex.getString()));
|
|
|
|
|
} else if (token == "\\color") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXColor(lex.getString());
|
|
|
|
|
} else if (token == "\\SpecialChar") {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2002-05-29 14:32:11 +00:00
|
|
|
|
|
|
|
|
|
// Insets don't make sense in a free-spacing context! ---Kayvan
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->free_spacing || par->isFreeSpacing()) {
|
2002-05-29 14:32:11 +00:00
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
string const next_token = lex.getString();
|
2002-05-29 14:32:11 +00:00
|
|
|
|
if (next_token == "\\-") {
|
|
|
|
|
par->insertChar(pos, '-', font);
|
2002-10-16 20:27:23 +00:00
|
|
|
|
} else if (next_token == "~") {
|
2002-05-29 14:32:11 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Token `$$Token' "
|
|
|
|
|
"is in free space "
|
|
|
|
|
"paragraph layout!");
|
|
|
|
|
--pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Inset * inset = new InsetSpecialChar;
|
|
|
|
|
inset->read(this, lex);
|
|
|
|
|
par->insertInset(pos, inset, font);
|
|
|
|
|
}
|
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\i") {
|
|
|
|
|
Inset * inset = new InsetLatexAccent;
|
|
|
|
|
inset->read(this, lex);
|
|
|
|
|
par->insertInset(pos, inset, font);
|
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\backslash") {
|
|
|
|
|
par->insertChar(pos, '\\', font);
|
|
|
|
|
++pos;
|
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();
|
2002-03-21 16:55:34 +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 {
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
2002-11-21 18:33:09 +00:00
|
|
|
|
Alert::alert(_("Textclass error"),
|
|
|
|
|
boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
|
2003-01-22 17:36:35 +00:00
|
|
|
|
_("-- substituting default."));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#else
|
|
|
|
|
Alert::alert(
|
|
|
|
|
_("Textclass error"),
|
|
|
|
|
_("The document uses an unknown textclass ")
|
|
|
|
|
+ lex.getString(),
|
2003-01-22 17:36:35 +00:00
|
|
|
|
_("-- substituting default."));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
2002-07-21 21:21:06 +00:00
|
|
|
|
if (!params.getLyXTextClass().load()) {
|
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
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
2001-11-26 10:19:58 +00:00
|
|
|
|
Alert::alert(_("Textclass Loading Error!"),
|
2002-11-21 18:33:09 +00:00
|
|
|
|
boost::io::str(boost::format(_("Can't load textclass %1$s")) %
|
|
|
|
|
params.getLyXTextClass().name()),
|
2003-01-23 16:23:43 +00:00
|
|
|
|
_("-- substituting default."));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#else
|
|
|
|
|
Alert::alert(_("Textclass Loading Error!"),
|
|
|
|
|
_("Can't load textclass ")
|
|
|
|
|
+ params.getLyXTextClass().name(),
|
2003-01-23 16:23:43 +00:00
|
|
|
|
_("-- substituting default."));
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
2003-11-13 15:51:44 +00:00
|
|
|
|
if (!params.getLyXTextClass().isTeXClassAvailable()) {
|
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
|
Alert::alert(_("Textclass error"),
|
|
|
|
|
boost::io::str(boost::format(_("The document uses a missing TeX class \"%1$s\".")) % lex.getString()),
|
|
|
|
|
_("LyX will not be able to produce output."));
|
|
|
|
|
#else
|
|
|
|
|
Alert::alert(
|
|
|
|
|
_("Textclass error"),
|
|
|
|
|
_("The document uses a missing TeX class ")
|
|
|
|
|
+ lex.getString(),
|
|
|
|
|
_("LyX will not be able to produce output."));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} 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") {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
params.readLanguage(lex);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} 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);
|
2002-05-08 12:58:16 +00:00
|
|
|
|
} else if (token == "\\leftindent") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
LyXLength value(lex.getString());
|
|
|
|
|
par->params().leftIndent(value);
|
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;
|
2002-08-06 22:38:44 +00:00
|
|
|
|
params.paragraph_separation =
|
|
|
|
|
static_cast<BufferParams::PARSEP>(tmpret);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\defskip") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
params.defskip = VSpace(lex.getString());
|
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;
|
2002-08-06 22:38:44 +00:00
|
|
|
|
InsetQuotes::quote_language tmpl =
|
|
|
|
|
InsetQuotes::EnglishQ;
|
|
|
|
|
switch (tmpret) {
|
|
|
|
|
case 0:
|
|
|
|
|
tmpl = InsetQuotes::EnglishQ;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
tmpl = InsetQuotes::SwedishQ;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
tmpl = InsetQuotes::GermanQ;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
tmpl = InsetQuotes::PolishQ;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
tmpl = InsetQuotes::FrenchQ;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
tmpl = InsetQuotes::DanishQ;
|
|
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
2002-08-06 22:38:44 +00:00
|
|
|
|
params.quotes_language = tmpl;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\quotes_times") {
|
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
switch (lex.getInteger()) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
case 1:
|
|
|
|
|
params.quotes_times = InsetQuotes::SingleQ;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
case 2:
|
|
|
|
|
params.quotes_times = InsetQuotes::DoubleQ;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
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") {
|
2004-07-15 11:13:10 +00:00
|
|
|
|
// string_paperpackages is missing the first entry "none".
|
|
|
|
|
// Therefore, the strings in the .lyx file are off by one,
|
|
|
|
|
// and the last setting PACKAGE_WIDEMARGINSA4 is written as
|
|
|
|
|
// an empty string.
|
|
|
|
|
// Since we cannot fix string_paperpackages because this
|
|
|
|
|
// would be a file format change, we have to recognize the
|
|
|
|
|
// empty argument of "\\paperpackage" as PACKAGE_WIDEMARGINSA4
|
|
|
|
|
// here.
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string const nextToken = lex.getString();
|
|
|
|
|
if (nextToken.empty()) {
|
|
|
|
|
params.paperpackage = BufferParams::PACKAGE_WIDEMARGINSA4;
|
|
|
|
|
} else {
|
|
|
|
|
lex.pushToken(nextToken);
|
|
|
|
|
int tmpret = lex.findToken(string_paperpackages);
|
|
|
|
|
if (tmpret == -1) {
|
|
|
|
|
++tmpret;
|
|
|
|
|
params.paperpackage = BufferParams::PACKAGE_NONE;
|
|
|
|
|
} else
|
|
|
|
|
params.paperpackage = tmpret;
|
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} 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;
|
2002-08-06 22:38:44 +00:00
|
|
|
|
params.orientation =
|
|
|
|
|
static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} 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();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
params.fontsize = rtrim(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();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
params.pagestyle = rtrim(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") {
|
2002-01-13 17:12:01 +00:00
|
|
|
|
// The bullet class should be able to read this.
|
2000-03-01 14:13:21 +00:00
|
|
|
|
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
|
|
|
|
}
|
2002-01-13 17:12:01 +00:00
|
|
|
|
|
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();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const tmp = rtrim(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();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string const tmp = rtrim(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 == "\\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;
|
2002-08-06 22:38:44 +00:00
|
|
|
|
int const tmpret2 = int(pow(2.0, tmpret));
|
|
|
|
|
par->params().align(LyXAlignment(tmpret2));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\added_space_top") {
|
|
|
|
|
lex.nextToken();
|
2002-02-08 14:32:17 +00:00
|
|
|
|
VSpace value = VSpace(lex.getString());
|
2002-05-31 12:17:28 +00:00
|
|
|
|
// only add the length when value > 0 or
|
|
|
|
|
// with option keep
|
2002-02-08 14:32:17 +00:00
|
|
|
|
if ((value.length().len().value() != 0) ||
|
2002-05-31 12:17:28 +00:00
|
|
|
|
value.keep() ||
|
2002-02-08 14:32:17 +00:00
|
|
|
|
(value.kind() != VSpace::LENGTH))
|
2002-05-31 12:17:28 +00:00
|
|
|
|
par->params().spaceTop(value);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\added_space_bottom") {
|
|
|
|
|
lex.nextToken();
|
2002-02-08 14:32:17 +00:00
|
|
|
|
VSpace value = VSpace(lex.getString());
|
2002-05-31 12:17:28 +00:00
|
|
|
|
// only add the length when value > 0 or
|
|
|
|
|
// with option keep
|
2002-02-08 14:32:17 +00:00
|
|
|
|
if ((value.length().len().value() != 0) ||
|
2002-06-24 20:28:12 +00:00
|
|
|
|
value.keep() ||
|
2002-02-08 14:32:17 +00:00
|
|
|
|
(value.kind() != VSpace::LENGTH))
|
2002-05-31 12:17:28 +00:00
|
|
|
|
par->params().spaceBottom(value);
|
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-04-24 20:58:23 +00:00
|
|
|
|
} else if (token == "\\newline") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, Paragraph::META_NEWLINE, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\LyXTable") {
|
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 == "\\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);
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
par->bibkey->read(this, lex);
|
2000-08-05 05:17:18 +00:00
|
|
|
|
} else if (token == "\\the_end") {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
the_end_read = true;
|
|
|
|
|
} else {
|
|
|
|
|
// This should be insurance for the future: (Asger)
|
2001-11-25 17:58:05 +00:00
|
|
|
|
++unknown_tokens;
|
|
|
|
|
lex.eatLine();
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#if USE_BOOST_FORMAT
|
|
|
|
|
boost::format fmt(_("Unknown token: %1$s %2$s\n"));
|
|
|
|
|
fmt % token % lex.text();
|
|
|
|
|
string const s = fmt.str();
|
|
|
|
|
#else
|
|
|
|
|
string const s = _("Unknown token: ") + token
|
2002-11-27 10:30:28 +00:00
|
|
|
|
+ ' ' + lex.text() + '\n';
|
2002-11-24 15:20:31 +00:00
|
|
|
|
#endif
|
2002-03-15 15:28:25 +00:00
|
|
|
|
// we can do this here this way because we're actually reading
|
|
|
|
|
// the buffer and don't care about LyXText right now.
|
2001-11-25 17:58:05 +00:00
|
|
|
|
InsetError * new_inset = new InsetError(s);
|
2001-12-15 15:03:06 +00:00
|
|
|
|
par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
|
2002-03-21 16:55:34 +00:00
|
|
|
|
params.language));
|
2001-11-25 17:58:05 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-25 22:25:48 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
|
|
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,
|
2002-03-21 16:55:34 +00:00
|
|
|
|
LyXFont const & fn,string const & str) const
|
2001-07-23 09:11:14 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
|
|
|
|
|
2001-10-22 09:45:31 +00:00
|
|
|
|
LyXFont font = fn;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
par->checkInsertChar(font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// insert the string, don't insert doublespace
|
|
|
|
|
bool space_inserted = true;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
bool autobreakrows = !par->inInset() ||
|
|
|
|
|
static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
for(string::const_iterator cit = str.begin();
|
2001-07-23 09:11:14 +00:00
|
|
|
|
cit != str.end(); ++cit) {
|
|
|
|
|
if (*cit == '\n') {
|
2002-08-10 15:21:07 +00:00
|
|
|
|
if (autobreakrows && (!par->empty() || layout->keepempty)) {
|
2002-08-20 19:41:13 +00:00
|
|
|
|
breakParagraph(params, par, pos,
|
|
|
|
|
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') &&
|
2002-06-24 20:28:12 +00:00
|
|
|
|
space_inserted && !layout->free_spacing &&
|
2001-11-29 16:29:30 +00:00
|
|
|
|
!par->isFreeSpacing())
|
2001-10-22 09:45:31 +00:00
|
|
|
|
{
|
2001-07-23 09:11:14 +00:00
|
|
|
|
continue;
|
|
|
|
|
} else if (*cit == '\t') {
|
2002-06-24 20:28:12 +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 == ' ');
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
2001-07-23 09:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-07-19 14:12:37 +00:00
|
|
|
|
// This strange command allows LyX to recognize "natbib" style
|
|
|
|
|
// citations: citet, citep, Citet etc.
|
2002-07-16 21:17:10 +00:00
|
|
|
|
if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 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
|
2002-01-29 09:26:24 +00:00
|
|
|
|
// inset = new InsetFig(100, 100, *this);
|
|
|
|
|
inset = new InsetGraphics;
|
2001-07-29 10:50:07 +00:00
|
|
|
|
} 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") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetNote(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Include") {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
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") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetERT(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} 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") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetText(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Foot") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetFoot(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Marginal") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetMarginal(params);
|
2002-08-23 09:05:32 +00:00
|
|
|
|
} else if (tmptok == "OptArg") {
|
|
|
|
|
inset = new InsetOptArg(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Minipage") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetMinipage(params);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Float") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string tmptok = lex.getString();
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetFloat(params, tmptok);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
} else if (tmptok == "Wrap") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string tmptok = lex.getString();
|
|
|
|
|
inset = new InsetWrap(params, 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") {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
inset = new InsetCaption(params);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (tmptok == "FloatList") {
|
|
|
|
|
inset = new InsetFloatList;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +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
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-25 12:19:13 +00:00
|
|
|
|
bool Buffer::readFile(LyXLex & lex, string const & filename, 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();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
|
2001-01-11 11:06:10 +00:00
|
|
|
|
// 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);
|
2002-08-28 08:30:27 +00:00
|
|
|
|
//lyxerr << "format: " << file_format << endl;
|
2001-01-11 11:06:10 +00:00
|
|
|
|
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!"),
|
2003-01-13 10:52:17 +00:00
|
|
|
|
_("The file was created with a newer version of "
|
2002-09-09 17:32:53 +00:00
|
|
|
|
"LyX. This is likely to cause problems."));
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-01-11 11:06:10 +00:00
|
|
|
|
} 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;
|
2002-09-25 12:19:13 +00:00
|
|
|
|
} else if (!filename.empty()) {
|
2002-09-06 14:48:01 +00:00
|
|
|
|
string command =
|
2002-09-03 16:13:35 +00:00
|
|
|
|
LibFileSearch("lyx2lyx", "lyx2lyx");
|
|
|
|
|
if (command.empty()) {
|
|
|
|
|
Alert::alert(_("ERROR!"),
|
|
|
|
|
_("Can't find conversion script."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-09-23 10:17:12 +00:00
|
|
|
|
string const tmpfile = lyx::tempName();
|
2002-09-03 16:13:35 +00:00
|
|
|
|
command += " -t"
|
2003-09-23 10:17:12 +00:00
|
|
|
|
+ tostr(LYX_FORMAT)
|
|
|
|
|
+ " -o " + tmpfile + ' '
|
2002-09-25 12:19:13 +00:00
|
|
|
|
+ QuoteName(filename);
|
|
|
|
|
lyxerr[Debug::INFO] << "Running '"
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< command << '\''
|
|
|
|
|
<< endl;
|
2002-07-22 17:11:41 +00:00
|
|
|
|
cmd_ret const ret = RunCommand(command);
|
|
|
|
|
if (ret.first) {
|
|
|
|
|
Alert::alert(_("ERROR!"),
|
2002-08-29 19:49:12 +00:00
|
|
|
|
_("An error occured while "
|
|
|
|
|
"running the conversion script."));
|
2002-07-22 17:11:41 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
LyXLex tmplex(0, 0);
|
2003-09-23 10:17:12 +00:00
|
|
|
|
tmplex.setFile(tmpfile);
|
2003-01-16 21:17:08 +00:00
|
|
|
|
return readFile(tmplex, string(), par);
|
2002-09-25 12:19:13 +00:00
|
|
|
|
} else {
|
|
|
|
|
// This code is reached if lyx2lyx failed (for
|
|
|
|
|
// some reason) to change the file format of
|
|
|
|
|
// the file.
|
|
|
|
|
lyx::Assert(false);
|
|
|
|
|
return false;
|
2001-01-11 11:06:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool the_end = readLyXformat2(lex, par);
|
2001-11-07 10:25:05 +00:00
|
|
|
|
params.setPaperStuff();
|
2002-05-22 12:33:02 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
2001-01-11 11:06:10 +00:00
|
|
|
|
// the_end was added in 213
|
|
|
|
|
if (file_format < 213)
|
|
|
|
|
the_end = true;
|
2002-05-22 12:33:02 +00:00
|
|
|
|
#endif
|
2001-01-11 11:06:10 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
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
|
|
|
|
// 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);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
if (writeFile(fileName())) {
|
2002-08-04 23:11:50 +00:00
|
|
|
|
markClean();
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
bool Buffer::writeFile(string const & fname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
if (read_only && (fname == fileName())) {
|
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()) {
|
|
|
|
|
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
|
|
|
|
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
|
2002-03-21 16:55:34 +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.
|
2002-08-20 17:29:37 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
for (; pit != pend; ++pit)
|
|
|
|
|
pit->write(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)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// 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
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
return status;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-07 18:59:07 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
pair<int, string> const addDepth(int depth, int ldepth)
|
|
|
|
|
{
|
|
|
|
|
int d = depth * 2;
|
|
|
|
|
if (ldepth > depth)
|
|
|
|
|
d += (ldepth - depth) * 2;
|
|
|
|
|
return make_pair(d, string(d, ' '));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const Buffer::asciiParagraph(Paragraph const & par,
|
2002-03-21 16:55:34 +00:00
|
|
|
|
unsigned int linelen,
|
|
|
|
|
bool noparbreak) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
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;
|
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
|
2002-08-20 17:18:21 +00:00
|
|
|
|
depth = par.params().depth();
|
2001-12-27 12:00:03 +00:00
|
|
|
|
#endif
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// First write the layout
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const & tmp = par.layout()->name();
|
2002-03-03 20:25:07 +00:00
|
|
|
|
if (compare_no_case(tmp, "itemize") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 1;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 2;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (contains(ascii_lowercase(tmp), "ection")) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 3;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (contains(ascii_lowercase(tmp), "aragraph")) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 4;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "description") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 5;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "abstract") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 6;
|
|
|
|
|
ltype_depth = 0;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 7;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ltype = 0;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
|
|
|
|
/* maybe some vertical spaces */
|
|
|
|
|
|
|
|
|
|
/* the labelwidthstring used in lists */
|
|
|
|
|
|
|
|
|
|
/* some lines? */
|
|
|
|
|
|
|
|
|
|
/* some pagebreaks? */
|
|
|
|
|
|
|
|
|
|
/* noindent ? */
|
|
|
|
|
|
|
|
|
|
/* what about the alignment */
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// } else {
|
|
|
|
|
// lyxerr << "Should this ever happen?" << endl;
|
|
|
|
|
// }
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
// linelen <= 0 is special and means we don't have paragraph breaks
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
string::size_type currlinelen = 0;
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (!noparbreak) {
|
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
buffer << string(depth * 2, ' ');
|
|
|
|
|
currlinelen += depth * 2;
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
//--
|
|
|
|
|
// 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)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
//--
|
2001-12-27 12:00:03 +00:00
|
|
|
|
switch (ltype) {
|
|
|
|
|
case 0: // Standard
|
|
|
|
|
case 4: // (Sub)Paragraph
|
|
|
|
|
case 5: // Description
|
|
|
|
|
break;
|
|
|
|
|
case 6: // Abstract
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("Abstract") << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen = 0;
|
|
|
|
|
} else {
|
|
|
|
|
string const abst = _("Abstract: ");
|
2002-03-21 16:55:34 +00:00
|
|
|
|
buffer << abst;
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen += abst.length();
|
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
case 7: // Bibliography
|
|
|
|
|
if (!ref_printed) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("References") << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen = 0;
|
|
|
|
|
} else {
|
|
|
|
|
string const refs = _("References: ");
|
|
|
|
|
buffer << refs;
|
|
|
|
|
currlinelen += refs.length();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ref_printed = true;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-03-07 18:59:07 +00:00
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const parlab = par.params().labelString();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
buffer << parlab << ' ';
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen += parlab.length() + 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (!currlinelen) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
pair<int, string> p = addDepth(depth, ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen += p.first;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-07 18:59:07 +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)
|
|
|
|
|
|
|
|
|
|
string word;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
for (pos_type i = 0; i < par.size(); ++i) {
|
|
|
|
|
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
|
|
|
|
{
|
2002-08-20 17:18:21 +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) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word;
|
|
|
|
|
currlinelen += word.length();
|
|
|
|
|
word.erase();
|
2002-01-10 10:38:49 +00:00
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-05-16 07:53:23 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_NEWLINE:
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word << "\n";
|
|
|
|
|
word.erase();
|
|
|
|
|
|
|
|
|
|
pair<int, string> p = addDepth(depth,
|
|
|
|
|
ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen = p.first;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
case Paragraph::META_HFILL:
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word << "\t";
|
|
|
|
|
currlinelen += word.length() + 1;
|
|
|
|
|
word.erase();
|
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 == ' ') {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0 &&
|
|
|
|
|
currlinelen + word.length() > linelen - 10) {
|
|
|
|
|
buffer << "\n";
|
|
|
|
|
pair<int, string> p =
|
|
|
|
|
addDepth(depth, ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen = p.first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer << word << ' ';
|
|
|
|
|
currlinelen += word.length() + 1;
|
|
|
|
|
word.erase();
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (c != '\0') {
|
2002-03-14 09:59:02 +00:00
|
|
|
|
word += c;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] <<
|
|
|
|
|
"writeAsciiFile: NULL char in structure." << endl;
|
|
|
|
|
}
|
|
|
|
|
if ((linelen > 0) &&
|
2002-03-07 18:59:07 +00:00
|
|
|
|
(currlinelen + word.length()) > linelen)
|
2001-12-27 12:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
buffer << "\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
pair<int, string> p =
|
|
|
|
|
addDepth(depth, ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen = p.first;
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
void Buffer::writeFileAscii(string const & fname, int linelen)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
void Buffer::writeFileAscii(ostream & os, int linelen)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
2002-08-14 22:15:18 +00:00
|
|
|
|
ParagraphList::iterator beg = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
ParagraphList::iterator it = beg;
|
|
|
|
|
for (; it != end; ++it) {
|
2002-08-20 17:18:21 +00:00
|
|
|
|
os << asciiParagraph(*it, linelen, it == beg);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2002-08-20 17:18:21 +00:00
|
|
|
|
os << "\n";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
void Buffer::makeLaTeXFile(string const & fname,
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string const & original_path,
|
2002-07-05 19:21:29 +00:00
|
|
|
|
bool nice, bool only_body, bool only_preamble)
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
if (ofs.fail()) {
|
|
|
|
|
lyxerr << "File was not closed properly." << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::makeLaTeXFile(ostream & os,
|
|
|
|
|
string const & original_path,
|
|
|
|
|
bool nice, bool only_body, bool only_preamble)
|
|
|
|
|
{
|
2002-03-07 16:03:36 +00:00
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// validate the buffer.
|
|
|
|
|
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.reset();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// The starting paragraph of the coming rows is the
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// first paragraph of the document. (Asger)
|
2002-08-12 00:15:19 +00:00
|
|
|
|
texrow.start(&*(paragraphs.begin()), 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
if (!only_body && nice) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "%% " << 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:
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// usual is \batchmode and has a
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// special input@path to allow the including of figures
|
|
|
|
|
// with either \input or \includegraphics (what figinsets do).
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// input@path is set when the actual parameter
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// original_path is set. This is done for usual tex-file, but not
|
|
|
|
|
// for nice-latex-file. (Matthias 250696)
|
|
|
|
|
if (!only_body) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!nice) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// code for usual, NOT nice-latex-file
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\batchmode\n"; // changed
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// from \nonstopmode
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (!original_path.empty()) {
|
2002-03-07 16:03:36 +00:00
|
|
|
|
string inputpath = os::external_path(original_path);
|
|
|
|
|
subst(inputpath, "~", "\\string~");
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\makeatletter\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\def\\input@path{{"
|
2002-03-07 16:03:36 +00:00
|
|
|
|
<< inputpath << "/}}\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\makeatother\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\documentclass";
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
ostringstream options; // the document class options.
|
2002-03-21 16:55:34 +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
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (!params.use_geometry
|
2000-03-06 02:42:40 +00:00
|
|
|
|
&& params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "landscape,";
|
2002-03-21 16:55:34 +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 ||
|
2002-04-29 20:41:51 +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
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
string strOptions(STRCONV(options.str()));
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!strOptions.empty()) {
|
2002-07-28 22:50:13 +00:00
|
|
|
|
strOptions = rtrim(strOptions, ",");
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << '[' << strOptions << ']';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << '{' << tclass.latexname() << "}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
// end of \documentclass defs
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// 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")) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{" << params.fonts << "}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
2001-01-23 12:53:05 +00:00
|
|
|
|
if (params.fonts == "ae") {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{aecompl}\n";
|
2001-01-23 12:53:05 +00:00
|
|
|
|
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") {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\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
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// Create a list with all the input encodings used
|
2000-07-04 20:32:37 +00:00
|
|
|
|
// 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
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage[";
|
2000-10-12 15:17:42 +00:00
|
|
|
|
std::copy(encodings.begin(), encodings.end(),
|
2002-07-05 19:21:29 +00:00
|
|
|
|
std::ostream_iterator<string>(os, ","));
|
|
|
|
|
os << doc_encoding << "]{inputenc}\n";
|
2000-07-04 20:32:37 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
} else if (params.inputenc != "default") {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage[" << params.inputenc
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "]{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:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{a4}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_A4WIDE:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{a4wide}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_WIDEMARGINSA4:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage[widemargins]{a4}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (params.use_geometry) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{geometry}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\geometry{verbose";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",landscape";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
switch (params.papersize2) {
|
|
|
|
|
case BufferParams::VM_PAPER_CUSTOM:
|
|
|
|
|
if (!params.paperwidth.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",paperwidth="
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< params.paperwidth;
|
|
|
|
|
if (!params.paperheight.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",paperheight="
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< params.paperheight;
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLETTER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",letterpaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLEGAL:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",legalpaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USEXECUTIVE:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",executivepaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A3:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a3paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A4:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a4paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A5:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a5paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B3:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",b3paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B4:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",b4paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B5:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",b5paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",letterpaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",legalpaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",executivepaper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A3PAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a3paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a4paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",a5paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_B5PAPER:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",b5paper";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!params.topmargin.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",tmargin=" << params.topmargin;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.bottommargin.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",bmargin=" << params.bottommargin;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.leftmargin.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",lmargin=" << params.leftmargin;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.rightmargin.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",rmargin=" << params.rightmargin;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.headheight.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",headheight=" << params.headheight;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.headsep.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",headsep=" << params.headsep;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!params.footskip.empty())
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << ",footskip=" << params.footskip;
|
|
|
|
|
os << "}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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") {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\usepackage{fancyhdr}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\pagestyle{" << params.pagestyle << "}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.secnumdepth != tclass.secnumdepth()) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setcounter{secnumdepth}{"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< params.secnumdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (params.tocdepth != tclass.tocdepth()) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setcounter{tocdepth}{"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< params.tocdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.paragraph_separation) {
|
|
|
|
|
switch (params.defskip.kind()) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
case VSpace::SMALLSKIP:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parskip{\\smallskipamount}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::MEDSKIP:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parskip{\\medskipamount}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::BIGSKIP:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parskip{\\bigskipamount}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case VSpace::LENGTH:
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parskip{"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< params.defskip.length().asLatexString()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
break;
|
|
|
|
|
default: // should never happen // Then delete it.
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parskip{\\medskipamount}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
texrow.newline();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\setlength\\parindent{0pt}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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';
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// 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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// at \begin{document} time -- JMarc
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
bullets_def += "}{" +
|
|
|
|
|
params.user_defined_bullets[i].getText()
|
2000-03-06 02:42:40 +00:00
|
|
|
|
+ "}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bullets_def.empty())
|
|
|
|
|
preamble += bullets_def + "}\n\n";
|
|
|
|
|
|
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[") +
|
2002-11-04 02:12:42 +00:00
|
|
|
|
STRCONV(language_options.str()) +
|
2001-10-04 13:00:25 +00:00
|
|
|
|
"]{babel}";
|
2002-05-10 12:58:07 +00:00
|
|
|
|
preamble += tmp + "\n";
|
|
|
|
|
preamble += features.getBabelOptions();
|
2001-10-04 13:00:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-10 12:58:07 +00:00
|
|
|
|
preamble += "\\makeatother\n";
|
|
|
|
|
|
2003-02-14 21:37:51 +00:00
|
|
|
|
int const nlines =
|
|
|
|
|
int(lyx::count(preamble.begin(), preamble.end(), '\n'));
|
|
|
|
|
for (int j = 0; j != nlines; ++j) {
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << preamble;
|
|
|
|
|
|
|
|
|
|
if (only_preamble)
|
|
|
|
|
return;
|
2002-05-10 12:58:07 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// make the body.
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\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) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << 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();
|
|
|
|
|
}
|
2004-04-18 15:36:05 +00:00
|
|
|
|
|
|
|
|
|
// if we are doing a real file with body, even if this is the
|
|
|
|
|
// child of some other buffer, let's cut the link here.
|
|
|
|
|
string save_parentname;
|
|
|
|
|
if (!only_body) {
|
|
|
|
|
save_parentname = params.parentname;
|
|
|
|
|
params.parentname.erase();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2004-04-18 15:36:05 +00:00
|
|
|
|
// the real stuff
|
2002-08-12 00:15:19 +00:00
|
|
|
|
latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
2004-04-18 15:36:05 +00:00
|
|
|
|
// Restore the parenthood if needed
|
|
|
|
|
if (!only_body) {
|
|
|
|
|
params.parentname = save_parentname;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
// add this just in case after all the paragraphs
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << endl;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2001-03-01 15:57:10 +00:00
|
|
|
|
if (!lyxrc.language_auto_end) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << 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) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\end{document}\n";
|
2000-05-04 08:14:34 +00:00
|
|
|
|
texrow.newline();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just to be sure. (Asger)
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
|
|
|
|
|
<< '.' << endl;
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
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-05-14 14:22:11 +00:00
|
|
|
|
Paragraph * endpar, TexRow & texrow,
|
|
|
|
|
bool moving_arg) 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;
|
2003-02-12 21:01:18 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// 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
|
2002-08-20 17:18:21 +00:00
|
|
|
|
// length (all in one row) if that is true then we don't allow
|
2002-01-08 14:24:49 +00:00
|
|
|
|
// 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)) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +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;
|
2003-02-12 21:01:18 +00:00
|
|
|
|
} else if (!was_title) {
|
2002-01-08 14:24:49 +00:00
|
|
|
|
was_title = true;
|
2003-02-12 21:01:18 +00:00
|
|
|
|
if (tclass.titletype() == TITLE_ENVIRONMENT) {
|
|
|
|
|
ofs << "\\begin{"
|
|
|
|
|
<< tclass.titlename()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-19 20:24:04 +00:00
|
|
|
|
} else if (was_title && !already_title) {
|
2003-02-12 21:01:18 +00:00
|
|
|
|
if (tclass.titletype() == TITLE_ENVIRONMENT) {
|
|
|
|
|
ofs << "\\end{" << tclass.titlename()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ofs << "\\" << tclass.titlename()
|
|
|
|
|
<< "\n";
|
|
|
|
|
}
|
2002-01-08 14:24:49 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
already_title = true;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
was_title = false;
|
2002-01-08 14:24:49 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (layout->isEnvironment() ||
|
2002-05-08 12:58:16 +00:00
|
|
|
|
!par->params().leftIndent().zero())
|
|
|
|
|
{
|
2002-01-08 14:24:49 +00:00
|
|
|
|
par = par->TeXEnvironment(this, params, ofs, texrow);
|
|
|
|
|
} else {
|
2002-05-14 14:22:11 +00:00
|
|
|
|
par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
|
2002-01-08 14:24:49 +00:00
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
} else {
|
2002-05-14 14:22:11 +00:00
|
|
|
|
par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
|
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) {
|
2003-02-12 21:01:18 +00:00
|
|
|
|
if (tclass.titletype() == TITLE_ENVIRONMENT) {
|
|
|
|
|
ofs << "\\end{" << tclass.titlename()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ofs << "\\" << tclass.titlename()
|
|
|
|
|
<< "\n";
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
return tclass.outputType() == LINUXDOC ||
|
|
|
|
|
tclass.outputType() == DOCBOOK;
|
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.
|
|
|
|
|
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
|
|
|
|
|
string top_element = tclass.latexname();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
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;
|
2002-03-05 13:38:40 +00:00
|
|
|
|
const string name = nice ? ChangeExtension(filename_, ".sgml")
|
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
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())
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
else {
|
|
|
|
|
string top = top_element;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2000-07-01 12:54:45 +00:00
|
|
|
|
top += params.options;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
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
|
2002-08-12 00:15:19 +00:00
|
|
|
|
Paragraph * par = &*(paragraphs.begin());
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string item_name;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
vector<string> environment_stack(5);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
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)) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (lyx_code == Inset::TOC_CODE) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const temp = "toc";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, 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) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, 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
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (depth == par->params().depth()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (depth)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
--depth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-03-21 16:55:34 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, 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,
|
2003-01-06 14:02:24 +00:00
|
|
|
|
_("Error: Wrong depth for LatexType Command.\n"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!environment_stack[depth].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
{
|
|
|
|
|
string const & latexname = style->latexname();
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (depth == par->params().depth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& environment_stack[depth] != latexname) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false,
|
2002-06-24 20:28:12 +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
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (environment_stack[depth] != latexname) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth == 0) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, "p");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, latexname);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
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("!-- --");
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth] = latexname;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "<![CDATA[";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latextype == LATEX_ENVIRONMENT) break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
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
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1, false, item_name);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, 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
|
2002-06-24 20:28: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:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "]]>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Close open tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
for (int i = depth; i >= 0; --i)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, 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";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
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)
|
|
|
|
|
{
|
2002-03-21 16:55:34 +00:00
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 | p2);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void reset(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 & ~p2);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-25 11:15:27 +00:00
|
|
|
|
} // anon
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
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,
|
2002-03-25 11:15:27 +00:00
|
|
|
|
Paragraph * par,
|
|
|
|
|
Paragraph::depth_type /*depth*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
|
|
|
|
|
2002-03-21 16:55:34 +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;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->labeltype == LABEL_MANUAL) {
|
|
|
|
|
font_old = style->labelfont;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = true;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
font_old = style->font;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
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;
|
2002-02-16 15:59:55 +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();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "</" << tag_name(k) << '>';
|
2001-03-23 08:37:44 +00:00
|
|
|
|
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);
|
2002-11-27 10:30:28 +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);
|
2002-11-27 10:30:28 +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
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +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 {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
bool ws;
|
|
|
|
|
string str;
|
|
|
|
|
boost::tie(ws, str) = sgml::escapeChar(c);
|
|
|
|
|
if (ws && !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 {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
os << str;
|
|
|
|
|
char_line_count += str.length();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
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()) {
|
2002-11-27 10:30:28 +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.
|
2002-03-25 11:15:27 +00:00
|
|
|
|
void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
|
|
|
|
|
string const & /*message*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-07 15:49:38 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2002-03-15 15:28:25 +00:00
|
|
|
|
#warning This is wrong we cannot insert an inset like this!!!
|
|
|
|
|
// I guess this was Jose' so I explain you more or less why this
|
|
|
|
|
// is wrong. This way you insert something in the paragraph and
|
|
|
|
|
// don't tell it to LyXText (row rebreaking and undo handling!!!)
|
|
|
|
|
// I deactivate this code, have a look at BufferView::insertErrors
|
|
|
|
|
// how you should do this correctly! (Jug 20020315)
|
2002-06-07 15:49:38 +00:00
|
|
|
|
#endif
|
2002-03-15 15:28:25 +00:00
|
|
|
|
#if 0
|
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);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
|
|
|
|
|
params.language));
|
2002-03-15 15:28:25 +00:00
|
|
|
|
#endif
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
|
Paragraph * par = &*(paragraphs.begin());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
string top_element = tclass.latexname();
|
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;
|
2002-03-05 13:38:40 +00:00
|
|
|
|
const string name = nice ? ChangeExtension(filename_, ".sgml")
|
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
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
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string top = top_element;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
top += " lang=\"";
|
|
|
|
|
top += params.language->code();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += '"';
|
2001-01-28 21:54:15 +00:00
|
|
|
|
|
|
|
|
|
if (!params.options.empty()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2000-11-13 15:43:36 +00:00
|
|
|
|
top += params.options;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, 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
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string item_name;
|
2001-04-04 21:47:26 +00:00
|
|
|
|
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
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = 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) {
|
2003-06-06 13:04:47 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, 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()
|
2002-06-24 20:28:12 +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";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth+depth, false, item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write opening SGML tags.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, 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,
|
2003-01-06 14:02:24 +00:00
|
|
|
|
_("Error: Wrong depth for LatexType Command.\n"));
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
command_name = style->latexname();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
sgmlparam = style->latexparam();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
c_params = split(sgmlparam, c_depth,'|');
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cmd_depth = lyx::atoi(c_depth);
|
2002-03-21 16:55:34 +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) {
|
2002-05-03 11:56:49 +00:00
|
|
|
|
for (Paragraph::depth_type j = command_depth;
|
|
|
|
|
j >= command_base; --j) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
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) {
|
2002-05-03 11:56:49 +00:00
|
|
|
|
for (int j = command_depth;
|
|
|
|
|
j >= int(cmd_depth); --j) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
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)) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
2002-02-16 15:59:55 +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();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
command_name += '"';
|
1999-12-07 00:44:53 +00:00
|
|
|
|
desc_on = 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, command_name);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
item_name = c_params.empty() ? "title" : c_params;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth, false, 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
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (environment_stack[depth] != style->latexname()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth] = style->latexname();
|
1999-12-07 00:44:53 +00:00
|
|
|
|
environment_inner[depth] = "!-- --";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latextype == LATEX_ENVIRONMENT) {
|
|
|
|
|
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
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
|
2001-01-28 21:54:15 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
desc_on = (style->labeltype == LABEL_MANUAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
item_name = desc_on ? "term" : "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +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
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
end_tag = c_params.empty() ? "title" : c_params;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!style->latexparam().empty()) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-01-28 21:54:15 +00:00
|
|
|
|
ofs << "]]>";
|
|
|
|
|
else
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
|
2001-01-28 21:54:15 +00:00
|
|
|
|
}
|
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;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
end_tag = "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, 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";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-10-02 14:01:04 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
1999-10-02 14:01:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= 0 ; --j)
|
2002-05-03 11:56:49 +00:00
|
|
|
|
if (!command_stack[j].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-13 15:43:36 +00:00
|
|
|
|
ofs << "\n\n";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, 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
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
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;
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +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) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "<emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = true;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
} else if (i) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = false;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-06-06 19:17:59 +00:00
|
|
|
|
char c = par->getChar(i);
|
|
|
|
|
switch (c) {
|
|
|
|
|
case Paragraph::META_INSET:
|
|
|
|
|
{
|
|
|
|
|
Inset const * 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)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (i || desc_on != 3) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-02-18 17:33:14 +00:00
|
|
|
|
os << "]]>";
|
2002-06-18 15:44:30 +00:00
|
|
|
|
inset->docbook(this, os, false);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-02-18 17:33:14 +00:00
|
|
|
|
os << "<![CDATA[";
|
|
|
|
|
}
|
2003-06-06 19:17:59 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Paragraph::META_NEWLINE:
|
|
|
|
|
os << "\n";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Paragraph::META_HFILL:
|
|
|
|
|
os << " ";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2002-08-09 00:42:12 +00:00
|
|
|
|
bool ws;
|
|
|
|
|
string str;
|
|
|
|
|
boost::tie(ws, str) = sgml::escapeChar(c);
|
2001-10-03 17:28:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->pass_thru) {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
os << c;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
} else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
os << str;
|
2001-10-03 17:28:08 +00:00
|
|
|
|
} 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) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
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...
|
2002-03-12 08:44:04 +00:00
|
|
|
|
os << "</term>\n<listitem><para> </para>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->free_spacing)
|
|
|
|
|
os << '\n';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string path = filePath();
|
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)) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
path = tmppath;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2002-01-14 23:31:23 +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:
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (removedErrorInsets || res) {
|
2004-05-04 09:15:49 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2002-06-21 02:22:13 +00:00
|
|
|
|
#warning repaint needed here, or do you mean update() ?
|
2004-05-04 09:15:49 +00:00
|
|
|
|
#endif
|
2002-06-21 02:22:13 +00:00
|
|
|
|
users->repaint();
|
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
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
|
|
|
|
// AMS Style is at document level
|
|
|
|
|
if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("amsmath");
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-14 22:15:18 +00:00
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(),
|
|
|
|
|
boost::bind(&Paragraph::validate, _1, boost::ref(features)));
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
|
vector<string> const Buffer::getLabelList() const
|
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]
|
2004-04-18 15:36:05 +00:00
|
|
|
|
Buffer const * tmp = getMasterBuffer();
|
|
|
|
|
if (tmp != this)
|
|
|
|
|
return tmp->getLabelList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
|
vector<string> label_list;
|
2002-08-12 20:17:41 +00:00
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it) {
|
2002-08-20 17:18:21 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This is also a buffer property (ale)
|
2002-04-16 09:12:36 +00:00
|
|
|
|
vector<pair<string, string> > const Buffer::getBibkeyList() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-04-16 09:12:36 +00:00
|
|
|
|
typedef pair<string, string> StringPair;
|
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]
|
2004-04-18 15:36:05 +00:00
|
|
|
|
Buffer const * tmp = getMasterBuffer();
|
|
|
|
|
if (tmp != this)
|
|
|
|
|
return tmp->getBibkeyList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-04-16 09:12:36 +00:00
|
|
|
|
vector<StringPair> keys;
|
2002-08-14 22:15:18 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
|
if (pit->bibkey) {
|
|
|
|
|
string const key = pit->bibkey->getContents();
|
|
|
|
|
string const opt = pit->bibkey->getOptions();
|
|
|
|
|
string const ref = pit->asString(this, false);
|
2002-04-24 10:00:39 +00:00
|
|
|
|
string const info = opt + "TheBibliographyRef" + ref;
|
2002-05-01 22:17:09 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
keys.push_back(StringPair(key, info));
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
|
if (!keys.empty())
|
|
|
|
|
return keys;
|
2002-09-06 14:48:01 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Might be either using bibtex or a child has bibliography
|
2002-08-24 22:02:30 +00:00
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it) {
|
|
|
|
|
// Search for Bibtex or Include inset
|
|
|
|
|
if (it->lyxCode() == Inset::BIBTEX_CODE) {
|
|
|
|
|
vector<StringPair> tmp =
|
|
|
|
|
static_cast<InsetBibtex &>(*it).getKeys(this);
|
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
|
|
|
|
} else if (it->lyxCode() == Inset::INCLUDE_CODE) {
|
|
|
|
|
vector<StringPair> const tmp =
|
|
|
|
|
static_cast<InsetInclude &>(*it).getKeys();
|
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +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
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
bool Buffer::dispatch(string const & command, bool * result)
|
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;
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string line = ltrim(command);
|
|
|
|
|
string const arg = trim(split(line, cmd, ' '));
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
return dispatch(lyxaction.LookupFunc(cmd), arg, result);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
bool Buffer::dispatch(int action, string const & argument, bool * result)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2000-04-28 11:18:04 +00:00
|
|
|
|
bool dispatched = true;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
switch (action) {
|
2002-05-30 19:49:00 +00:00
|
|
|
|
case LFUN_EXPORT: {
|
|
|
|
|
bool const tmp = Exporter::Export(this, argument, false);
|
|
|
|
|
if (result)
|
|
|
|
|
*result = tmp;
|
1999-12-15 17:42:22 +00:00
|
|
|
|
break;
|
2002-05-30 19:49:00 +00:00
|
|
|
|
}
|
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
|
2002-08-14 22:15:18 +00:00
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(),
|
|
|
|
|
boost::bind(&Paragraph::resizeInsetsLyXText, _1, 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()
|
|
|
|
|
{
|
2004-05-04 09:15:49 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
2002-06-21 02:22:13 +00:00
|
|
|
|
#warning repaint needed here, or do you mean update() ?
|
2004-05-04 09:15:49 +00:00
|
|
|
|
#endif
|
2002-06-21 02:22:13 +00:00
|
|
|
|
users->repaint();
|
2002-03-21 16:55:34 +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-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::inset_iterator::setParagraph()
|
2000-09-26 13:54:57 +00:00
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
while (pit != pend) {
|
|
|
|
|
it = pit->insetlist.begin();
|
|
|
|
|
if (it != pit->insetlist.end())
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
++pit;
|
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)
|
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
if (it->id() == id_arg)
|
|
|
|
|
return &(*it);
|
|
|
|
|
Inset * in = it->getInsetFromID(id_arg);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
if (in)
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph * Buffer::getParFromID(int id) const
|
|
|
|
|
{
|
2002-08-14 22:15:18 +00:00
|
|
|
|
if (id < 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
ParagraphList::iterator it = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (it->id() == id) {
|
|
|
|
|
return &*it;
|
2001-07-09 09:16:00 +00:00
|
|
|
|
}
|
2002-08-14 22:15:18 +00:00
|
|
|
|
Paragraph * tmp = it->getParFromID(id);
|
2001-07-09 09:16:00 +00:00
|
|
|
|
if (tmp) {
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_begin()
|
|
|
|
|
{
|
2002-08-12 00:15:19 +00:00
|
|
|
|
return ParIterator(&*(paragraphs.begin()));
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_end()
|
|
|
|
|
{
|
2002-03-21 16:55:34 +00:00
|
|
|
|
return ParIterator();
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
2002-11-08 01:08:27 +00:00
|
|
|
|
ParConstIterator Buffer::par_iterator_begin() const
|
|
|
|
|
{
|
|
|
|
|
return ParConstIterator(&*(paragraphs.begin()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParConstIterator Buffer::par_iterator_end() const
|
|
|
|
|
{
|
|
|
|
|
return ParConstIterator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
|
|
|
|
void Buffer::addUser(BufferView * u)
|
|
|
|
|
{
|
|
|
|
|
users = u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::delUser(BufferView *)
|
|
|
|
|
{
|
|
|
|
|
users = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Language const * Buffer::getLanguage() const
|
|
|
|
|
{
|
|
|
|
|
return params.language;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isClean() const
|
|
|
|
|
{
|
|
|
|
|
return lyx_clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isBakClean() const
|
|
|
|
|
{
|
|
|
|
|
return bak_clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markClean() const
|
|
|
|
|
{
|
|
|
|
|
if (!lyx_clean) {
|
|
|
|
|
lyx_clean = true;
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
// if the .lyx file has been saved, we don't need an
|
|
|
|
|
// autosave
|
|
|
|
|
bak_clean = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markBakClean()
|
|
|
|
|
{
|
|
|
|
|
bak_clean = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setUnnamed(bool flag)
|
|
|
|
|
{
|
|
|
|
|
unnamed = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isUnnamed()
|
|
|
|
|
{
|
|
|
|
|
return unnamed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markDirty()
|
|
|
|
|
{
|
|
|
|
|
if (lyx_clean) {
|
|
|
|
|
lyx_clean = false;
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
bak_clean = false;
|
|
|
|
|
DEPCLEAN * tmp = dep_clean;
|
|
|
|
|
while (tmp) {
|
|
|
|
|
tmp->clean = false;
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::fileName() const
|
|
|
|
|
{
|
|
|
|
|
return filename_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return filepath_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isReadonly() const
|
|
|
|
|
{
|
|
|
|
|
return read_only;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * Buffer::getUser() const
|
|
|
|
|
{
|
|
|
|
|
return users;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setParentName(string const & name)
|
|
|
|
|
{
|
|
|
|
|
params.parentname = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-18 15:36:05 +00:00
|
|
|
|
Buffer const * Buffer::getMasterBuffer() const
|
|
|
|
|
{
|
|
|
|
|
if (!params.parentname.empty()
|
|
|
|
|
&& bufferlist.exists(params.parentname)) {
|
|
|
|
|
Buffer const * buf = bufferlist.getBuffer(params.parentname);
|
|
|
|
|
if (buf)
|
|
|
|
|
return buf->getMasterBuffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
Buffer::inset_iterator::inset_iterator()
|
|
|
|
|
: pit(0), pend(0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
|
|
|
|
|
: pit(p), pend(e)
|
|
|
|
|
{
|
|
|
|
|
setParagraph();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator & Buffer::inset_iterator::operator++()
|
|
|
|
|
{
|
|
|
|
|
if (pit != pend) {
|
|
|
|
|
++it;
|
|
|
|
|
if (it == pit->insetlist.end()) {
|
|
|
|
|
++pit;
|
|
|
|
|
setParagraph();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
|
|
|
|
|
{
|
|
|
|
|
inset_iterator tmp = *this;
|
|
|
|
|
++*this;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
|
|
|
|
|
{
|
|
|
|
|
return *it.getInset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
|
|
|
|
|
{
|
|
|
|
|
return it.getInset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph * Buffer::inset_iterator::getPar()
|
|
|
|
|
{
|
|
|
|
|
return &(*pit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lyx::pos_type Buffer::inset_iterator::getPos() const
|
|
|
|
|
{
|
|
|
|
|
return it.getPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(Buffer::inset_iterator const & iter1,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
Buffer::inset_iterator const & iter2)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
|
|
|
|
return iter1.pit == iter2.pit
|
|
|
|
|
&& (iter1.pit == iter1.pend || iter1.it == iter2.it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(Buffer::inset_iterator const & iter1,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
Buffer::inset_iterator const & iter2)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
|
|
|
|
return !(iter1 == iter2);
|
|
|
|
|
}
|