}
-bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
+bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiledir)
{
// set the quote language
// LyX only knows the following quotes languages:
// output the LyX file settings
// Important: Keep the version formatting in sync with LyX and
// lyx2lyx (bug 7951)
+ string const origin = roundtripMode() ? "roundtrip" : outfiledir;
os << "#LyX file created by tex2lyx " << lyx_version_major << '.'
<< lyx_version_minor << '\n'
<< "\\lyxformat " << LYX_FORMAT << '\n'
<< "\\begin_document\n"
<< "\\begin_header\n"
+ << "\\origin " << origin << "\n"
<< "\\textclass " << h_textclass << "\n";
string const raw = subdoc ? empty_string() : h_preamble.str();
if (!raw.empty()) {
void parse(Parser & p, std::string const & forceclass,
TeX2LyXDocClass & tc);
/// Writes the LyX file header from internal data
- bool writeLyXHeader(std::ostream & os, bool subdoc);
+ bool writeLyXHeader(std::ostream & os, bool subdoc,
+ std::string const & outfiledir);
/// known polyglossia language names (including variants)
static const char * const polyglossia_languages[];
* You must ensure that \p parentFilePathTeX is properly set before calling
* this function!
*/
-bool tex2lyx(idocstream & is, ostream & os, string encoding)
+bool tex2lyx(idocstream & is, ostream & os, string encoding,
+ string const & outfiledir)
{
// Set a sensible default encoding.
// This is used until an encoding command is found.
for (; it != end; ++it)
preamble.addModule(*it);
}
- if (!preamble.writeLyXHeader(os, !active_environments.empty())) {
+ if (!preamble.writeLyXHeader(os, !active_environments.empty(), outfiledir)) {
cerr << "Could not write LyX file header." << endl;
return false;
}
/// convert TeX from \p infilename to LyX and write it to \p os
-bool tex2lyx(FileName const & infilename, ostream & os, string const & encoding)
+bool tex2lyx(FileName const & infilename, ostream & os, string const & encoding,
+ string const & outfiledir)
{
ifdocstream is;
// forbid buffering on this stream
}
string const oldParentFilePath = parentFilePathTeX;
parentFilePathTeX = onlyPath(infilename.absFileName());
- bool retval = tex2lyx(is, os, encoding);
+ bool retval = tex2lyx(is, os, encoding, outfiledir);
parentFilePathTeX = oldParentFilePath;
return retval;
}
cerr << "Input file: " << infilename << "\n";
cerr << "Output file: " << outfilename << "\n";
#endif
- return tex2lyx(FileName(infilename), os, encoding);
+ return tex2lyx(FileName(infilename), os, encoding,
+ outfilename.onlyPath().absFileName() + '/');
}
if (outfilename == "-") {
// assume same directory as input file
masterFilePathLyX = masterFilePathTeX;
- if (tex2lyx(FileName(infilename), cout, default_encoding))
+ if (tex2lyx(FileName(infilename), cout, default_encoding, masterFilePathLyX))
return EXIT_SUCCESS;
} else {
masterFilePathLyX = onlyPath(outfilename);