diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 35bb506283..0ae9a2798d 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -1046,7 +1046,7 @@ void Preamble::handle_if(Parser & p, bool in_lyx_preamble) } -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: @@ -1088,11 +1088,13 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc) // 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()) { diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index ffc9bda03b..71367b1af4 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -93,7 +93,8 @@ public: 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[]; diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx index 6b5186cf5e..3eeccc5a6e 100644 --- a/src/tex2lyx/test/CJK.lyx.lyx +++ b/src/tex2lyx/test/CJK.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble \usepackage{babel} diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx index e398d2399c..0baa3b8b80 100644 --- a/src/tex2lyx/test/CJKutf8.lyx.lyx +++ b/src/tex2lyx/test/CJKutf8.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble \usepackage{babel} diff --git a/src/tex2lyx/test/DummyDocument.lyx.lyx b/src/tex2lyx/test/DummyDocument.lyx.lyx index eb38e2278c..91f33fa139 100644 --- a/src/tex2lyx/test/DummyDocument.lyx.lyx +++ b/src/tex2lyx/test/DummyDocument.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \use_default_options false \maintain_unincluded_children false diff --git a/src/tex2lyx/test/Dummy~Document.lyx.lyx b/src/tex2lyx/test/Dummy~Document.lyx.lyx index b4c7ef1321..0bd5c2982d 100644 --- a/src/tex2lyx/test/Dummy~Document.lyx.lyx +++ b/src/tex2lyx/test/Dummy~Document.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \use_default_options false \maintain_unincluded_children false diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx index 99cc9eb6f9..0e177ac47c 100644 --- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx +++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble diff --git a/src/tex2lyx/test/algo2e.lyx.lyx b/src/tex2lyx/test/algo2e.lyx.lyx index add9e0ebae..9d317ffc9f 100644 --- a/src/tex2lyx/test/algo2e.lyx.lyx +++ b/src/tex2lyx/test/algo2e.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx index 199483de21..4518d8af05 100644 --- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx +++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble diff --git a/src/tex2lyx/test/test-insets.lyx.lyx b/src/tex2lyx/test/test-insets.lyx.lyx index 2a7ccee1df..1395837a69 100644 --- a/src/tex2lyx/test/test-insets.lyx.lyx +++ b/src/tex2lyx/test/test-insets.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble diff --git a/src/tex2lyx/test/test-memoir.lyx.lyx b/src/tex2lyx/test/test-memoir.lyx.lyx index 34c1983616..ee8c8d8bf9 100644 --- a/src/tex2lyx/test/test-memoir.lyx.lyx +++ b/src/tex2lyx/test/test-memoir.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass memoir \begin_preamble diff --git a/src/tex2lyx/test/test-modules.lyx.lyx b/src/tex2lyx/test/test-modules.lyx.lyx index ce2de1093e..b1e2247d58 100644 --- a/src/tex2lyx/test/test-modules.lyx.lyx +++ b/src/tex2lyx/test/test-modules.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass amsart \begin_preamble \usepackage{babel} diff --git a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx index deb69c4799..55b1266046 100644 --- a/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx +++ b/src/tex2lyx/test/test-refstyle-theorems.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass book \begin_preamble \usepackage{babel} diff --git a/src/tex2lyx/test/test-scr.lyx.lyx b/src/tex2lyx/test/test-scr.lyx.lyx index 95723c942a..323dbedd64 100644 --- a/src/tex2lyx/test/test-scr.lyx.lyx +++ b/src/tex2lyx/test/test-scr.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass scrbook \begin_preamble \usepackage{babel} diff --git a/src/tex2lyx/test/test-structure.lyx.lyx b/src/tex2lyx/test/test-structure.lyx.lyx index bfcf8acfab..3c25024d8c 100644 --- a/src/tex2lyx/test/test-structure.lyx.lyx +++ b/src/tex2lyx/test/test-structure.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble %% Special footnote code from the package 'stblftnt.sty' diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx index a8b8240d26..0cc0fb6878 100644 --- a/src/tex2lyx/test/test.lyx.lyx +++ b/src/tex2lyx/test/test.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \begin_preamble % This is a test document for tex2lyx diff --git a/src/tex2lyx/test/verbatim.lyx.lyx b/src/tex2lyx/test/verbatim.lyx.lyx index 3e7c6e5d26..52f71aee10 100644 --- a/src/tex2lyx/test/verbatim.lyx.lyx +++ b/src/tex2lyx/test/verbatim.lyx.lyx @@ -1,7 +1,8 @@ #LyX file created by tex2lyx 2.2 -\lyxformat 489 +\lyxformat 490 \begin_document \begin_header +\origin roundtrip \textclass article \use_default_options false \maintain_unincluded_children false diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 57790ab12b..5001ad0af5 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -839,7 +839,8 @@ namespace { * 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. @@ -905,7 +906,7 @@ bool tex2lyx(idocstream & is, ostream & os, string encoding) 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; } @@ -924,7 +925,8 @@ bool tex2lyx(idocstream & is, ostream & os, string encoding) /// 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 @@ -937,7 +939,7 @@ bool tex2lyx(FileName const & infilename, ostream & os, string const & encoding) } 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; } @@ -970,7 +972,8 @@ bool tex2lyx(string const & infilename, FileName const & outfilename, 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() + '/'); } @@ -1122,7 +1125,7 @@ int TeX2LyXApp::run() 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);