namespace {
-// Do not remove the comment below, so we get merge conflict in
-// independent branches. Instead add your own.
-int const LYX_FORMAT = 416; //uwestoehr : support for horizontal spaces (bug 7728)
+int const LYX_FORMAT = LYX_FORMAT_LYX;
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
bibfile_cache_valid_ = cloned_buffer_->d->bibfile_cache_valid_;
bibfile_status_ = cloned_buffer_->d->bibfile_status_;
cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
+ unnamed = cloned_buffer_->d->unnamed;
}
bool Buffer::makeLaTeXFile(FileName const & fname,
+ string const & original_path,
OutputParams const & runparams_in,
bool output_preamble, bool output_body) const
{
runparams.encoding = encodings.fromLyXName("utf8-plain");
string const encoding = runparams.encoding->iconvName();
- LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << "...");
+ LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << ", fname=" << fname.realPath());
ofdocstream ofs;
try { ofs.reset(encoding); }
try {
os.texrow().reset();
- writeLaTeXSource(os, runparams, output_preamble, output_body);
+ writeLaTeXSource(os, original_path,
+ runparams, output_preamble, output_body);
}
catch (EncodingException & e) {
odocstringstream ods;
void Buffer::writeLaTeXSource(otexstream & os,
+ string const & original_path,
OutputParams const & runparams_in,
bool const output_preamble, bool const output_body) const
{
}
LYXERR(Debug::INFO, "lyx document header finished");
- // With respect to nice LaTeX, usual files have \batchmode
+ // There are a few differences between nice LaTeX and usual files:
+ // usual files have \batchmode and special input@path to allow
+ // inclusion of figures specified by an explicitly relative path
+ // (i.e., a path starting with './' or '../') with either \input or
+ // \includegraphics, as the TEXINPUTS method doesn't work in this case.
+ // input@path is set when the actual parameter original_path is set.
+ // This is done for usual tex-file, but not for nice-latex-file.
+ // (Matthias 250696)
+ // Note that input@path is only needed for something the user does
+ // in the preamble, included .tex files or ERT, files included by
+ // LyX work without it.
if (output_preamble) {
if (!runparams.nice) {
// code for usual, NOT nice-latex-file
os << "\\batchmode\n"; // changed from \nonstopmode
}
+ if (!original_path.empty()) {
+ // FIXME UNICODE
+ // We don't know the encoding of inputpath
+ docstring const inputpath = from_utf8(original_path);
+ docstring uncodable_glyphs;
+ Encoding const * const enc = runparams.encoding;
+ if (enc) {
+ for (size_t n = 0; n < inputpath.size(); ++n) {
+ docstring const glyph =
+ docstring(1, inputpath[n]);
+ if (enc->latexChar(inputpath[n], true) != glyph) {
+ LYXERR0("Uncodable character '"
+ << glyph
+ << "' in input path!");
+ uncodable_glyphs += glyph;
+ }
+ }
+ }
+
+ // warn user if we found uncodable glyphs.
+ if (!uncodable_glyphs.empty()) {
+ frontend::Alert::warning(
+ _("Uncodable character in file path"),
+ support::bformat(
+ _("The path of your document\n"
+ "(%1$s)\n"
+ "contains glyphs that are unknown "
+ "in the current document encoding "
+ "(namely %2$s). This may result in "
+ "incomplete output, unless "
+ "TEXINPUTS contains the document "
+ "directory and you don't use "
+ "explicitly relative paths (i.e., "
+ "paths starting with './' or "
+ "'../') in the preamble or in ERT."
+ "\n\nIn case of problems, choose "
+ "an appropriate document encoding\n"
+ "(such as utf8) or change the "
+ "file path name."),
+ inputpath, uncodable_glyphs));
+ } else {
+ string docdir =
+ support::latex_path(original_path);
+ if (contains(docdir, '#')) {
+ docdir = subst(docdir, "#", "\\#");
+ os << "\\catcode`\\#=11"
+ "\\def\\#{#}\\catcode`\\#=6\n";
+ }
+ if (contains(docdir, '%')) {
+ docdir = subst(docdir, "%", "\\%");
+ os << "\\catcode`\\%=11"
+ "\\def\\%{%}\\catcode`\\%=14\n";
+ }
+ os << "\\makeatletter\n"
+ << "\\def\\input@path{{"
+ << docdir << "/}}\n"
+ << "\\makeatother\n";
+ }
+ }
// get parent macros (if this buffer has a parent) which will be
// written at the document begin further down.
}
bool const needfg = params().fontcolor != RGBColor(0, 0, 0);
- bool const needbg = params().backgroundcolor != RGBColor(OxFF, OxFF, OxFF);
+ bool const needbg = params().backgroundcolor != RGBColor(0xFF, 0xFF, 0xFF);
if (needfg || needbg) {
os << "<style type='text/css'>\nbody {\n";
if (needfg)
// get LaTeX-Filename
FileName const path(temppath());
string const name = addName(path.absFileName(), latexName());
+ string const org_path = filePath();
PathChanger p(path); // path to LaTeX file
message(_("Running chktex..."));
runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
runparams.linelen = lyxrc.plaintext_linelen;
- makeLaTeXFile(FileName(name), runparams);
+ makeLaTeXFile(FileName(name), org_path, runparams);
TeXErrors terr;
Chktex chktex(lyxrc.chktex_command, onlyFileName(name), filePath());
break;
case LFUN_BUFFER_EXPORT: {
- bool success = doExport(argument, false, false);
- dr.setError(!success);
- if (!success)
+ ExportStatus const status = doExport(argument, false, false);
+ dr.setError(status != ExportSuccess);
+ if (status != ExportSuccess)
dr.setMessage(bformat(_("Error exporting to format: %1$s."),
func.argument()));
break;
break;
}
- bool const update_unincluded =
- params().maintain_unincluded_children
- && !params().getIncludedChildren().empty();
- if (!doExport("dvi", true, update_unincluded)) {
+ if (!doExport("dvi", true)) {
showPrintError(absFileName());
dr.setMessage(_("Error exporting to DVI."));
break;
else {
// latex or literate
otexstream ots(os, d->texrow);
- writeLaTeXSource(ots, runparams, true, true);
+ writeLaTeXSource(ots, string(), runparams, true, true);
}
} else {
runparams.par_begin = par_begin;
}
-bool Buffer::doExport(string const & target, bool put_in_tempdir,
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir) const
+{
+ bool const update_unincluded =
+ params().maintain_unincluded_children
+ && !params().getIncludedChildren().empty();
+ return doExport(target, put_in_tempdir, update_unincluded);
+}
+
+
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir,
bool includeall, string & result_file) const
{
+ LYXERR(Debug::FILES, "target=" << target);
OutputParams runparams(¶ms().encoding());
string format = target;
- string filename;
+ string dest_filename;
size_t pos = target.find(' ');
if (pos != string::npos) {
- filename = target.substr(pos + 1, target.length() - pos - 1);
+ dest_filename = target.substr(pos + 1, target.length() - pos - 1);
format = target.substr(0, pos);
- runparams.export_folder = FileName(filename).onlyPath().realPath();
- FileName(filename).onlyPath().createPath();
+ runparams.export_folder = FileName(dest_filename).onlyPath().realPath();
+ FileName(dest_filename).onlyPath().createPath();
+ LYXERR(Debug::FILES, "format=" << format << ", dest_filename=" << dest_filename << ", export_folder=" << runparams.export_folder);
}
MarkAsExporting exporting(this);
string backend_format;
_("No information for exporting the format %1$s."),
formats.prettyName(format)));
}
- return false;
+ return ExportNoPathToFormat;
}
runparams.flavor = converters.getFlavor(path);
} else {
backend_format = format;
+ LYXERR(Debug::FILES, "backend_format=" << backend_format);
// FIXME: Don't hardcode format names here, but use a flag
if (backend_format == "pdflatex")
runparams.flavor = OutputParams::PDFLATEX;
runparams.flavor = OutputParams::XETEX;
}
- if (filename.empty()) {
- filename = latexName(false);
- filename = addName(temppath(), filename);
- filename = changeExtension(filename,
- formats.extension(backend_format));
- }
+ string filename = latexName(false);
+ filename = addName(temppath(), filename);
+ filename = changeExtension(filename,
+ formats.extension(backend_format));
+ LYXERR(Debug::FILES, "filename=" << filename);
// Plain text backend
if (backend_format == "text") {
// LaTeX backend
else if (backend_format == format) {
runparams.nice = true;
- if (!makeLaTeXFile(FileName(filename), runparams)) {
+ if (!makeLaTeXFile(FileName(filename), string(), runparams)) {
if (d->cloned_buffer_) {
d->cloned_buffer_->d->errorLists["Export"] =
d->errorLists["Export"];
}
- return false;
+ return ExportError;
}
} else if (!lyxrc.tex_allows_spaces
&& contains(filePath(), ' ')) {
Alert::error(_("File name error"),
_("The directory path to the document cannot contain spaces."));
- return false;
+ return ExportTexPathHasSpaces;
} else {
runparams.nice = false;
- if (!makeLaTeXFile(FileName(filename), runparams)) {
+ if (!makeLaTeXFile(FileName(filename), filePath(), runparams)) {
if (d->cloned_buffer_) {
d->cloned_buffer_->d->errorLists["Export"] =
d->errorLists["Export"];
}
- return false;
+ return ExportError;
}
}
}
if (!success)
- return false;
+ return ExportConverterError;
if (put_in_tempdir) {
result_file = tmp_result_file.absFileName();
- return true;
+ return ExportSuccess;
}
- result_file = changeExtension(d->exportFileName().absFileName(), ext);
+ if (dest_filename.empty())
+ result_file = changeExtension(d->exportFileName().absFileName(), ext);
+ else
+ result_file = dest_filename;
// We need to copy referenced files (e. g. included graphics
// if format == "dvi") to the result dir.
vector<ExportedFile> const files =
formats.prettyName(format)));
}
- return true;
+ return ExportSuccess;
}
-bool Buffer::doExport(string const & target, bool put_in_tempdir,
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir,
bool includeall) const
{
string result_file;
// (1) export with all included children (omit \includeonly)
- if (includeall && !doExport(target, put_in_tempdir, true, result_file))
- return false;
+ if (includeall) {
+ ExportStatus const status =
+ doExport(target, put_in_tempdir, true, result_file);
+ if (status != ExportSuccess)
+ return status;
+ }
// (2) export with included children only
return doExport(target, put_in_tempdir, false, result_file);
}
-bool Buffer::preview(string const & format, bool includeall) const
+Buffer::ExportStatus Buffer::preview(string const & format) const
+{
+ bool const update_unincluded =
+ params().maintain_unincluded_children
+ && !params().getIncludedChildren().empty();
+ return preview(format, update_unincluded);
+}
+
+Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) const
{
MarkAsExporting exporting(this);
string result_file;
// (1) export with all included children (omit \includeonly)
- if (includeall && !doExport(format, true, true))
- return false;
+ if (includeall) {
+ ExportStatus const status = doExport(format, true, true);
+ if (status != ExportSuccess)
+ return status;
+ }
// (2) export with included children only
- if (!doExport(format, true, false, result_file))
- return false;
- return formats.view(*this, FileName(result_file), format);
+ ExportStatus const status = doExport(format, true, false, result_file);
+ if (status != ExportSuccess)
+ return status;
+ if (!formats.view(*this, FileName(result_file), format))
+ return PreviewError;
+ return PreviewSuccess;
}
WordLangTuple wl;
suggestions.clear();
word_lang = WordLangTuple();
+ bool const to_end = to.empty();
+ DocIterator const end = to_end ? doc_iterator_end(this) : to;
// OK, we start from here.
- DocIterator const end = doc_iterator_end(this);
for (; from != end; from.forwardPos()) {
// We are only interested in text so remove the math CursorSlice.
while (from.inMathed()) {
from.pos()++;
}
// If from is at the end of the document (which is possible
- // when leaving the mathed) LyX will crash later.
- if (from == end)
+ // when leaving the mathed) LyX will crash later otherwise.
+ if (from.atEnd() || (!to_end && from >= end))
break;
to = from;
from.paragraph().spellCheck();