mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 06:19:36 +00:00
Add -roundtrip argument to tex2lyx for tex->lyx->tex roundtrip testing.
The reasons for doing this in tex2lyx instead of an external script are: - Correct choice of latex/pdflatex export - Using the correct LyX executable regardless of running inplace or from an installation, or with or without version suffix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37049 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
22d245312a
commit
90f795a29e
@ -125,6 +125,24 @@ Package::Package(string const & command_line_arg0,
|
|||||||
get_system_support_dir(abs_binary,
|
get_system_support_dir(abs_binary,
|
||||||
command_line_system_support_dir);
|
command_line_system_support_dir);
|
||||||
|
|
||||||
|
// The LyX executable is one level above binary_dir_ if we are running
|
||||||
|
// tex2lyx in place. Otherwise it is in binary_dir_.
|
||||||
|
string abs_lyx_dir;
|
||||||
|
if (build_support_dir_.empty() ||
|
||||||
|
top_build_dir_location == top_build_dir_is_one_level_up)
|
||||||
|
abs_lyx_dir = binary_dir_.absFileName();
|
||||||
|
else {
|
||||||
|
FileName fn(addPath(binary_dir_.absFileName(), "../"));
|
||||||
|
abs_lyx_dir = fn.realPath();
|
||||||
|
}
|
||||||
|
// The LyX executable may have a package suffix if we are not running
|
||||||
|
// in place.
|
||||||
|
if (build_support_dir_.empty())
|
||||||
|
lyx_binary_ = FileName(addName(abs_lyx_dir,
|
||||||
|
"lyx" + string(PROGRAM_SUFFIX)));
|
||||||
|
else
|
||||||
|
lyx_binary_ = FileName(addName(abs_lyx_dir, "lyx"));
|
||||||
|
|
||||||
locale_dir_ = get_locale_dir(system_support_dir_);
|
locale_dir_ = get_locale_dir(system_support_dir_);
|
||||||
|
|
||||||
FileName const default_user_support_dir =
|
FileName const default_user_support_dir =
|
||||||
|
@ -70,10 +70,14 @@ public:
|
|||||||
std::string const & command_line_user_support_dir,
|
std::string const & command_line_user_support_dir,
|
||||||
exe_build_dir_to_top_build_dir);
|
exe_build_dir_to_top_build_dir);
|
||||||
|
|
||||||
/** The directory containing the LyX executable.
|
/** The directory containing the main executable (LyX or tex2lyx).
|
||||||
*/
|
*/
|
||||||
FileName const & binary_dir() const { return binary_dir_; }
|
FileName const & binary_dir() const { return binary_dir_; }
|
||||||
|
|
||||||
|
/** The absolute path to the LyX executable.
|
||||||
|
*/
|
||||||
|
FileName const & lyx_binary() const { return lyx_binary_; }
|
||||||
|
|
||||||
/** The top of the LyX source code tree.
|
/** The top of the LyX source code tree.
|
||||||
*/
|
*/
|
||||||
static FileName const & top_srcdir();
|
static FileName const & top_srcdir();
|
||||||
@ -137,6 +141,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
FileName binary_dir_;
|
FileName binary_dir_;
|
||||||
|
FileName lyx_binary_;
|
||||||
FileName system_support_dir_;
|
FileName system_support_dir_;
|
||||||
FileName build_support_dir_;
|
FileName build_support_dir_;
|
||||||
FileName user_support_dir_;
|
FileName user_support_dir_;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "support/Messages.h"
|
#include "support/Messages.h"
|
||||||
#include "support/os.h"
|
#include "support/os.h"
|
||||||
#include "support/Package.h"
|
#include "support/Package.h"
|
||||||
|
#include "support/Systemcall.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -168,6 +169,8 @@ void add_known_command(string const & command, string const & o1,
|
|||||||
|
|
||||||
|
|
||||||
bool noweb_mode = false;
|
bool noweb_mode = false;
|
||||||
|
bool pdflatex = false;
|
||||||
|
bool roundtrip = false;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -288,7 +291,8 @@ int parse_help(string const &, string const &)
|
|||||||
"\t-f Force overwrite of .lyx files.\n"
|
"\t-f Force overwrite of .lyx files.\n"
|
||||||
"\t-help Print this message and quit.\n"
|
"\t-help Print this message and quit.\n"
|
||||||
"\t-n translate a noweb (aka literate programming) file.\n"
|
"\t-n translate a noweb (aka literate programming) file.\n"
|
||||||
"\t-s syntaxfile read additional syntax file.\n"
|
"\t-roundtrip re-export created .lyx file infile.lyx.lyx to infile.lyx.tex.\n"
|
||||||
|
"\t-s syntaxfile read additional syntax file.\n"
|
||||||
"\t-sysdir dir Set system directory to DIR.\n"
|
"\t-sysdir dir Set system directory to DIR.\n"
|
||||||
"\t-userdir DIR Set user directory to DIR."
|
"\t-userdir DIR Set user directory to DIR."
|
||||||
<< endl;
|
<< endl;
|
||||||
@ -369,6 +373,13 @@ int parse_noweb(string const &, string const &)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int parse_roundtrip(string const &, string const &)
|
||||||
|
{
|
||||||
|
roundtrip = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void easyParse(int & argc, char * argv[])
|
void easyParse(int & argc, char * argv[])
|
||||||
{
|
{
|
||||||
map<string, cmd_helper> cmdmap;
|
map<string, cmd_helper> cmdmap;
|
||||||
@ -382,6 +393,7 @@ void easyParse(int & argc, char * argv[])
|
|||||||
cmdmap["-n"] = parse_noweb;
|
cmdmap["-n"] = parse_noweb;
|
||||||
cmdmap["-sysdir"] = parse_sysdir;
|
cmdmap["-sysdir"] = parse_sysdir;
|
||||||
cmdmap["-userdir"] = parse_userdir;
|
cmdmap["-userdir"] = parse_userdir;
|
||||||
|
cmdmap["-roundtrip"] = parse_roundtrip;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
map<string, cmd_helper>::const_iterator it
|
map<string, cmd_helper>::const_iterator it
|
||||||
@ -523,6 +535,29 @@ bool tex2lyx(string const & infilename, FileName const & outfilename,
|
|||||||
return tex2lyx(FileName(infilename), os, encoding);
|
return tex2lyx(FileName(infilename), os, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool tex2tex(string const & infilename, FileName const & outfilename,
|
||||||
|
string const & encoding)
|
||||||
|
{
|
||||||
|
if (!tex2lyx(infilename, outfilename, encoding))
|
||||||
|
return false;
|
||||||
|
string command = quoteName(package().lyx_binary().toFilesystemEncoding());
|
||||||
|
if (overwrite_files)
|
||||||
|
command += " -f main";
|
||||||
|
else
|
||||||
|
command += " -f none";
|
||||||
|
if (pdflatex)
|
||||||
|
command += " -e pdflatex ";
|
||||||
|
else
|
||||||
|
command += " -e latex ";
|
||||||
|
command += quoteName(outfilename.toFilesystemEncoding());
|
||||||
|
Systemcall one;
|
||||||
|
if (one.startscript(Systemcall::Wait, command) == 0)
|
||||||
|
return true;
|
||||||
|
cerr << "Error: Running '" << command << "' failed." << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
|
||||||
|
|
||||||
@ -549,7 +584,7 @@ int main(int argc, char * argv[])
|
|||||||
cerr << to_utf8(message.title_) << ":\n"
|
cerr << to_utf8(message.title_) << ":\n"
|
||||||
<< to_utf8(message.details_) << endl;
|
<< to_utf8(message.details_) << endl;
|
||||||
if (message.type_ == ErrorException)
|
if (message.type_ == ErrorException)
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now every known option is parsed. Look for input and output
|
// Now every known option is parsed. Look for input and output
|
||||||
@ -558,7 +593,17 @@ int main(int argc, char * argv[])
|
|||||||
infilename = makeAbsPath(infilename).absFileName();
|
infilename = makeAbsPath(infilename).absFileName();
|
||||||
|
|
||||||
string outfilename;
|
string outfilename;
|
||||||
if (argc > 2) {
|
if (roundtrip) {
|
||||||
|
if (argc > 2) {
|
||||||
|
// Do not allow a user supplied output filename
|
||||||
|
// (otherwise it could easily happen that LyX would
|
||||||
|
// overwrite the original .tex file)
|
||||||
|
cerr << "Error: output filename must not be given in roundtrip mode."
|
||||||
|
<< endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
outfilename = changeExtension(infilename, ".lyx.lyx");
|
||||||
|
} else if (argc > 2) {
|
||||||
outfilename = internal_path(os::utf8_argv(2));
|
outfilename = internal_path(os::utf8_argv(2));
|
||||||
if (outfilename != "-")
|
if (outfilename != "-")
|
||||||
outfilename = makeAbsPath(outfilename).absFileName();
|
outfilename = makeAbsPath(outfilename).absFileName();
|
||||||
@ -569,7 +614,7 @@ int main(int argc, char * argv[])
|
|||||||
FileName const system_syntaxfile = libFileSearch("", "syntax.default");
|
FileName const system_syntaxfile = libFileSearch("", "syntax.default");
|
||||||
if (system_syntaxfile.empty()) {
|
if (system_syntaxfile.empty()) {
|
||||||
cerr << "Error: Could not find syntax file \"syntax.default\"." << endl;
|
cerr << "Error: Could not find syntax file \"syntax.default\"." << endl;
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
read_syntaxfile(system_syntaxfile);
|
read_syntaxfile(system_syntaxfile);
|
||||||
if (!syntaxfile.empty())
|
if (!syntaxfile.empty())
|
||||||
@ -580,13 +625,13 @@ int main(int argc, char * argv[])
|
|||||||
if (symbols_path.empty()) {
|
if (symbols_path.empty()) {
|
||||||
cerr << "Error: Could not find file \"unicodesymbols\"."
|
cerr << "Error: Could not find file \"unicodesymbols\"."
|
||||||
<< endl;
|
<< endl;
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
FileName const enc_path = libFileSearch(string(), "encodings");
|
FileName const enc_path = libFileSearch(string(), "encodings");
|
||||||
if (enc_path.empty()) {
|
if (enc_path.empty()) {
|
||||||
cerr << "Error: Could not find file \"encodings\"."
|
cerr << "Error: Could not find file \"encodings\"."
|
||||||
<< endl;
|
<< endl;
|
||||||
exit(1);
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
encodings.read(enc_path, symbols_path);
|
encodings.read(enc_path, symbols_path);
|
||||||
if (!default_encoding.empty() && !encodings.fromLaTeXName(default_encoding))
|
if (!default_encoding.empty() && !encodings.fromLaTeXName(default_encoding))
|
||||||
@ -598,14 +643,14 @@ int main(int argc, char * argv[])
|
|||||||
if (outfilename == "-") {
|
if (outfilename == "-") {
|
||||||
if (tex2lyx(FileName(infilename), cout, default_encoding))
|
if (tex2lyx(FileName(infilename), cout, default_encoding))
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
} else if (roundtrip) {
|
||||||
return EXIT_FAILURE;
|
if (tex2tex(infilename, FileName(outfilename), default_encoding))
|
||||||
|
return EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
if (tex2lyx(infilename, FileName(outfilename), default_encoding))
|
if (tex2lyx(infilename, FileName(outfilename), default_encoding))
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
else
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// }])
|
// }])
|
||||||
|
@ -114,6 +114,8 @@ extern CommandMap known_environments;
|
|||||||
extern CommandMap known_math_environments;
|
extern CommandMap known_math_environments;
|
||||||
///
|
///
|
||||||
extern bool noweb_mode;
|
extern bool noweb_mode;
|
||||||
|
/// Did we recognize any pdflatex-only construct?
|
||||||
|
extern bool pdflatex;
|
||||||
/// LyX format that is created by tex2lyx
|
/// LyX format that is created by tex2lyx
|
||||||
int const LYX_FORMAT = 345;
|
int const LYX_FORMAT = 345;
|
||||||
|
|
||||||
|
@ -1811,8 +1811,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
name = dvips_name;
|
name = dvips_name;
|
||||||
} else if (!pdftex_name.empty())
|
} else if (!pdftex_name.empty()) {
|
||||||
name = pdftex_name;
|
name = pdftex_name;
|
||||||
|
pdflatex = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (makeAbsPath(name, path).exists())
|
if (makeAbsPath(name, path).exists())
|
||||||
@ -2641,6 +2643,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
bool const xfigpdf =
|
bool const xfigpdf =
|
||||||
abspdfname.exists() &&
|
abspdfname.exists() &&
|
||||||
(ext == "pdftex_t" || ext == "pdf_t");
|
(ext == "pdftex_t" || ext == "pdf_t");
|
||||||
|
if (xfigpdf)
|
||||||
|
pdflatex = true;
|
||||||
|
|
||||||
// Combined PS/PDF/LaTeX:
|
// Combined PS/PDF/LaTeX:
|
||||||
// x_pspdftex.eps, x_pspdftex.pdf, x.pspdftex
|
// x_pspdftex.eps, x_pspdftex.pdf, x.pspdftex
|
||||||
|
Loading…
Reference in New Issue
Block a user