\Format luatex tex "LaTeX (LuaTeX)" "" "" "%%" "document,menu=export" ""
\Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document,menu=export" ""
\Format xetex tex "LaTeX (XeTeX)" "" "" "%%" "document,menu=export" ""
+\Format latexclipboard tex "LaTeX (clipboard)" "" "" "%%" "" ""
\Format text txt "Plain text" a "" "%%" "document,menu=export" "text/plain"
\Format text2 txt "Plain text (pstotext)" "" "" "%%" "document" ""
\Format text3 txt "Plain text (ps2ascii)" "" "" "%%" "document" ""
path, t2l = checkProg('a LaTeX/Noweb -> LyX converter', [in_binary_subdir, in_binary_subdir + version_suffix, in_binary_dir, in_binary_dir + version_suffix, 'tex2lyx' + version_suffix, 'tex2lyx'],
rc_entry = [r'''\converter latex lyx "%% -f $$i $$o" ""
+\converter latexclipboard lyx "%% -fixedenc utf8 -f $$i $$o" ""
\converter literate lyx "%% -n -m noweb -f $$i $$o" ""'''], not_found = 'tex2lyx')
if path == '':
logger.warning("Failed to find tex2lyx on your system.")
// Then try TeX and HTML
Clipboard::TextType types[2] = {Clipboard::HtmlTextType, Clipboard::LaTeXTextType};
- string names[2] = {"html", "latex"};
+ string names[2] = {"html", "latexclipboard"};
for (int i = 0; i < 2; ++i) {
if (type != types[i] && type != Clipboard::AnyTextType)
continue;
//
-Parser::Parser(idocstream & is)
- : lineno_(0), pos_(0), iss_(0), is_(is), encoding_iconv_("UTF-8"),
- theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES)
+Parser::Parser(idocstream & is, std::string const & fixedenc)
+ : lineno_(0), pos_(0), iss_(0), is_(is),
+ encoding_iconv_(fixedenc.empty() ? "UTF-8" : fixedenc),
+ theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES),
+ fixed_enc_(!fixedenc.empty())
{
+ if (fixed_enc_)
+ is_.setEncoding(fixedenc);
}
: lineno_(0), pos_(0),
iss_(new idocstringstream(from_utf8(s))), is_(*iss_),
encoding_iconv_("UTF-8"),
- theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES)
+ theCatcodesType_(NORMAL_CATCODES), curr_cat_(UNDECIDED_CATCODES),
+ // An idocstringstream can not change the encoding
+ fixed_enc_(true)
{
}
{
//cerr << "setting encoding to " << e << std::endl;
encoding_iconv_ = e;
- is_.setEncoding(e);
+ // If the encoding is fixed, we must not change the stream encoding
+ // (because the whole input uses that encoding, e.g. if it comes from
+ // the clipboard). We still need to track the original encoding in
+ // encoding_iconv_, so that the generated output is correct.
+ if (!fixed_enc_)
+ is_.setEncoding(e);
return true;
}
Parser & operator=(Parser const & p);
public:
///
- Parser(idocstream & is);
+ Parser(idocstream & is, std::string const & fixedenc);
///
Parser(std::string const & s);
///
std::string encoding_iconv_;
///
CatCode theCatcode_[256];
- //
+ ///
cat_type theCatcodesType_;
- //
+ ///
cat_type curr_cat_;
+ ///
+ bool fixed_enc_;
};
.PP
\fBtex2lyx\fR [ \fB\-userdir\fR \fIuserdir\fR ] [ \fB\-systemdir\fR \fIsystemdir\fR ]
[ \fB\-f\fR ] [ \fB\-n\fR ] [ \fB\-c\fR \fItextclass\fR ]
+[ \fB\-e\fR \fIencoding\fR ]
+[ \fB\-fixedenc\fR \fIencoding\fR ]
[\ \fB\-m\fR \fImodule1\fR[,\fImodule2\fR...]]
[\ \fB\-s\fR\ \fIsfile1\fR[,\fIsfile2\fR...]] [ \fB\-skipchildren\fR ] [
\fB\-roundtrip\fR ] [ \fB\-copyfiles\fR ] \fIinputfile\fR [ \fIoutputfile\fR ]
Force. \fBtex2lyx\fR will not run if the .lyx file it would generate already exists.
Use the \fB\-f\fR option (carefully) to clobber any existing files.
.TP
+.BI \-e
+Specify the default encoding using the LaTeX name as defined in the encodings
+file. \fBtex2lyx\fR will use this encoding, but switch if it finds any encoding
+changing commands in the input.
+.TP
+.BI \-fixedenc
+Specify the encoding using the LaTeX name as defined in the encodings file.
+\fBtex2lyx\fR will ignore any encoding changing commands in the input.
+.TP
.BI \-n
Noweb. Translate a noweb (aka literate programming) file. This should be
(almost?) equivalent to running \*[lq]noweb2lyx foo.tex foo.lyx\*[rq]. This option
User's personal layout files for document classes
.IP "\fI\s-1MY_LYXDIR\s0\fR/syntax.default" 4
User's personal syntax file
+.IP "\fI\s-1MY_LYXDIR\s0\fR/encodings" 4
+User's personal encoding definition file
.IP "\fI\s-1LIBDIR\s0\fR/layouts/*.layout" 4
System-wide layout files for document classes
.IP "\fI\s-1LIBDIR\s0\fR/lib/syntax.default" 4
System-wide LaTeX syntax file
+.IP "\fI\s-1LIBDIR\s0\fR/lib/encodings" 4
+System-wide encoding definition file
.SH "SEE ALSO"
\fIlyx@version_suffix@\fR\|(1), \fIlatex\fR\|(1)
.SH "AUTHORS"
// modeled after TeX.
// Unknown tokens are just silently ignored, this helps us to skip some
// reLyX specific things.
- Parser p(is);
+ Parser p(is, string());
while (p.good()) {
Token const & t = p.get_token();
if (t.cat() == catEscape) {
string documentclass;
string default_encoding;
+bool fixed_encoding = false;
string syntaxfile;
bool copy_files = false;
bool overwrite_files = false;
"\t-m mod1[,mod2...] Load the given modules.\n"
"\t-copyfiles Copy all included files to the directory of outfile.lyx.\n"
"\t-e encoding Set the default encoding (latex name).\n"
+ "\t-fixedenc encoding Like -e, but ignore encoding changing commands while parsing.\n"
"\t-f Force overwrite of .lyx files.\n"
"\t-help Print this message and quit.\n"
"\t-n translate literate programming (noweb, sweave,... ) file.\n"
}
+int parse_fixed_encoding(string const & arg, string const &)
+{
+ if (arg.empty())
+ error_message("Missing encoding string after -fixedenc switch");
+ default_encoding = arg;
+ fixed_encoding = true;
+ return 1;
+}
+
+
int parse_syntaxfile(string const & arg, string const &)
{
if (arg.empty())
cmdmap["-c"] = parse_class;
cmdmap["-m"] = parse_module;
cmdmap["-e"] = parse_encoding;
+ cmdmap["-fixedenc"] = parse_fixed_encoding;
cmdmap["-f"] = parse_force;
cmdmap["-s"] = parse_syntaxfile;
cmdmap["-n"] = parse_noweb;
}
+string fixedEncoding()
+{
+ if (fixed_encoding)
+ return default_encoding;
+ return "";
+}
+
+
namespace {
/*!
}
}
- Parser p(is);
+ Parser p(is, fixed_encoding ? default_encoding : string());
p.setEncoding(encoding);
//p.dump();