From: Georg Baum Date: Sat, 22 Oct 2011 20:12:55 +0000 (+0000) Subject: Update tex2lyx to produce the current 2.0.x file format X-Git-Tag: 2.0.2~135 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=13bca637e4d2e806a4ac913a36f5109608152c39;p=features.git Update tex2lyx to produce the current 2.0.x file format git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@39927 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index 267772bd32..cafa32226a 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -51,4 +51,50 @@ Format LaTeX feature LyX feature 332 ? InsetGraphics groupId 336 ? \font_cjk 343 ? \use_default_options +347 tabular valign InsetTabular +348 \phantom, \hphantom, \vphantom InsetPhantom +350 ? \default_output_format +351 ? \backgroundcolor +353 \printsubindex InsetIndex +354 \printindex*, \printsubindex* InsetIndex +355 \sout fonts +356 \uuline, \uwave fonts +358 custom bibtex command \bibtex_command +358 custom makeindex command \index_command +359 set_width InsetCommand nomencl_print +360 width InsetCommand nomencl_print +362 applemac encoding \encoding +363 horizontal longtable alignment InsetTabular +364 branch file name suffix \filename_suffix +366 relative lengths for parskip \defskip +367 relative lengths for h and v space InsetHSpace, InsetVSpace +368 glue lengths InsetHSpace +369 author id \author +370 \date{} \suppress_date +371 automatic mhchem loading \use_mhchem +375 \includeonly \{begin,end}_includeonly +376 update .aux of unincluded children \maintain_unincluded_children +377 multirow.sty InsetTabular +378 revision info InsetInfo +380 ? InsetPreview +381 \xymatrix@!{0,R,C} InsetMathXYMatrix +382 note_fontcolor InsetNote +384 document font color \fontcolor +385 shaded box background color \boxbgcolor +386 LyX version InsetInfo +390 forward/reverse search \forward_search, \forward_macro +391 decimal alignment in tables InsetTabular +392 new beamer format InsetLayout +394 \makebox InsetBox use_makebox +396 nameref.sty InsetRef +399 automatic mathdots loading \use_mathdots +400 other rules than \lyxline InsetLine +401 feyn.sty InsetMathDiagram +402 \addcontentsline InsetBibtex bibtotoc option +404 refstyle.sty InsetRef +405 author hash \author +407 vertical offset for multirows InsetTabular +409 XeTeX \use_non_tex_fonts +411 babel etc. \language_package +412 tabular* InsetTabular diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index df9462dbe9..3a23c57551 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -49,11 +49,12 @@ const char * const modules_placeholder = "\001modules\001"; // needed to handle encodings with babel bool one_language = true; string h_inputencoding = "auto"; +string h_paragraph_separation = "indent"; namespace { //add this to known_languages when updating to lyxformat 266: -// "armenian" +// "armenian" (needs special handling since not supported by standard babel) //add these to known_languages when updating to lyxformat 268: //"chinese-simplified", "chinese-traditional", "japanese", "korean" // Both changes require first that support for non-babel languages (CJK, @@ -61,7 +62,7 @@ namespace { // add turkmen for lyxformat 383 /** * known babel language names (including synonyms) - * not in standard babel: arabic, arabtex, belarusian, serbian-latin, thai + * not in standard babel: arabic, arabtex, armenian, belarusian, serbian-latin, thai * not yet supported by LyX: kurmanji * please keep this in sync with known_coded_languages line by line! */ @@ -77,8 +78,9 @@ const char * const known_languages[] = {"acadian", "afrikaans", "albanian", "ngerman", "ngermanb", "norsk", "nynorsk", "polutonikogreek", "polish", "portuges", "portuguese", "romanian", "russian", "russianb", "samin", "scottish", "serbian", "serbian-latin", "slovak", "slovene", "spanish", -"swedish", "thai", "turkish", "ukraineb", "ukrainian", "uppersorbian", -"UKenglish", "USenglish", "usorbian", "vietnam", "welsh", 0}; +"swedish", "thai", "turkish", "turkmen", "ukraineb", "ukrainian", +"uppersorbian", "UKenglish", "USenglish", "usorbian", "vietnam", "welsh", +0}; /** * the same as known_languages with .lyx names @@ -96,21 +98,21 @@ const char * const known_coded_languages[] = {"french", "afrikaans", "albanian", "ngerman", "ngerman", "norsk", "nynorsk", "polutonikogreek", "polish", "portuguese", "portuguese", "romanian", "russian", "russian", "samin", "scottish", "serbian", "serbian-latin", "slovak", "slovene", "spanish", -"swedish", "thai", "turkish", "ukrainian", "ukrainian", "uppersorbian", -"uppersorbian", "english", "english", "vietnamese", "welsh", 0}; +"swedish", "thai", "turkish", "turkmen", "ukrainian", "ukrainian", +"uppersorbian", "uppersorbian", "english", "english", "vietnamese", "welsh", +0}; /// languages with english quotes (.lyx names) const char * const known_english_quotes_languages[] = {"american", "bahasa", "bahasam", "brazilian", "canadian", "chinese-simplified", "english", "esperanto", "hebrew", "irish", "korean", "portuguese", "scottish", "thai", 0}; -//add this to known_french_quotes_languages when updating to -//lyxformat 383: "turkmen" /// languages with french quotes (.lyx names) const char * const known_french_quotes_languages[] = {"albanian", "arabic_arabi", "arabic_arabtex", "basque", "canadien", "catalan", "french", "galician", "greek", "italian", "norsk", "nynorsk", "polutonikogreek", -"russian", "spanish", "spanish-mexico", "turkish", "ukrainian", "vietnamese", 0}; +"russian", "spanish", "spanish-mexico", "turkish", "turkmen", "ukrainian", +"vietnamese", 0}; /// languages with german quotes (.lyx names) const char * const known_german_quotes_languages[] = {"austrian", "bulgarian", @@ -137,9 +139,11 @@ const char * const known_typewriter_fonts[] = { "beramono", "cmtl", "cmtt", "courier", "lmtt", "luximono", "fourier", "lmodern", "mathpazo", "mathptmx", "newcent", 0}; -const char * const known_paper_sizes[] = { "a3paper", "b3paper", "a4paper", -"b4paper", "a5paper", "b5paper", "executivepaper", "legalpaper", -"letterpaper", 0}; +const char * const known_paper_sizes[] = { "a0paper", "b0paper", "c0paper", +"a1paper", "b1paper", "c1paper", "a2paper", "b2paper", "c2paper", "a3paper", +"b3paper", "c3paper", "a4paper", "b4paper", "c4paper", "a5paper", "b5paper", +"c5paper", "a6paper", "b6paper", "c6paper", "executivepaper", "legalpaper", +"letterpaper", "b0j", "b1j", "b2j", "b3j", "b4j", "b5j", "b6j", 0}; const char * const known_class_paper_sizes[] = { "a4paper", "a5paper", "executivepaper", "legalpaper", "letterpaper", 0}; @@ -166,6 +170,8 @@ string h_textclass = "article"; string h_use_default_options = "false"; string h_options; string h_language = "english"; +string h_language_package = "default"; +string h_fontencoding = "default"; string h_font_roman = "default"; string h_font_sans = "default"; string h_font_typewriter = "default"; @@ -198,13 +204,16 @@ string h_papersize = "default"; string h_use_geometry = "false"; string h_use_amsmath = "1"; string h_use_esint = "1"; +string h_use_mhchem = "0"; +string h_use_mathdots = "0"; string h_cite_engine = "basic"; string h_use_bibtopic = "false"; string h_paperorientation = "portrait"; +string h_suppress_date = "false"; +string h_use_refstyle = "0"; string h_notefontcolor; string h_secnumdepth = "3"; string h_tocdepth = "3"; -string h_paragraph_separation = "indent"; string h_defskip = "medskip"; string h_paragraph_indentation = "default"; string h_quotes_language = "english"; @@ -214,6 +223,9 @@ string h_paperpagestyle = "default"; string h_listings_params; string h_tracking_changes = "false"; string h_output_changes = "false"; +string h_html_math_output = "0"; +string h_html_css_as_file = "0"; +string h_html_be_strict = "false"; string h_margins; @@ -500,6 +512,12 @@ void handle_package(Parser &p, string const & name, string const & opts, else if (name == "esint") h_use_esint = "2"; + else if (name == "mhchem") + h_use_mhchem = "2"; + + else if (name == "mathdots") + h_use_mathdots = "2"; + else if (name == "babel" && !opts.empty()) { // check if more than one option was used - used later for inputenc // in case inputenc is parsed before babel, set the encoding to auto @@ -514,8 +532,15 @@ void handle_package(Parser &p, string const & name, string const & opts, delete_opt(options, known_languages); } - else if (name == "fontenc") - ;// ignore this + else if (name == "fontenc") { + h_fontencoding = getStringFromVector(options, ","); + /* We could do the following for better round trip support, + * but this makes the document less portable, so I skip it: + if (h_fontencoding == lyxrc.fontenc) + h_fontencoding = "global"; + */ + options.clear(); + } else if (name == "inputenc" || name == "luainputenc") { // h_inputencoding is only set when there is not more than one @@ -552,7 +577,7 @@ void handle_package(Parser &p, string const & name, string const & opts, else if (name == "url") ; // ignore this - else if (LYX_FORMAT >= 408 && name == "subscript") + else if (name == "subscript") ; // ignore this else if (name == "color") { @@ -677,7 +702,9 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/) os << "\\use_default_options " << h_use_default_options << "\n" << modules_placeholder << "\\language " << h_language << "\n" + << "\\language_package " << h_language_package << "\n" << "\\inputencoding " << h_inputencoding << "\n" + << "\\fontencoding " << h_fontencoding << "\n" << "\\font_roman " << h_font_roman << "\n" << "\\font_sans " << h_font_sans << "\n" << "\\font_typewriter " << h_font_typewriter << "\n" @@ -719,16 +746,20 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/) << "\\use_geometry " << h_use_geometry << "\n" << "\\use_amsmath " << h_use_amsmath << "\n" << "\\use_esint " << h_use_esint << "\n" + << "\\use_mhchem " << h_use_mhchem << "\n" + << "\\use_mathdots " << h_use_mathdots << "\n" << "\\cite_engine " << h_cite_engine << "\n" << "\\use_bibtopic " << h_use_bibtopic << "\n" - << "\\paperorientation " << h_paperorientation << '\n'; - if (LYX_FORMAT >= 382 && !h_notefontcolor.empty()) + << "\\paperorientation " << h_paperorientation << '\n' + << "\\suppress_date " << h_suppress_date << '\n' + << "\\use_refstyle " << h_use_refstyle << '\n'; + if (!h_notefontcolor.empty()) os << "\\notefontcolor " << h_notefontcolor << '\n'; os << h_margins << "\\secnumdepth " << h_secnumdepth << "\n" << "\\tocdepth " << h_tocdepth << "\n" << "\\paragraph_separation " << h_paragraph_separation << "\n"; - if (LYX_FORMAT < 365 || h_paragraph_separation == "skip") + if (h_paragraph_separation == "skip") os << "\\defskip " << h_defskip << "\n"; else os << "\\paragraph_indentation " << h_paragraph_indentation << "\n"; @@ -740,6 +771,9 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/) os << "\\listings_params " << h_listings_params << "\n"; os << "\\tracking_changes " << h_tracking_changes << "\n" << "\\output_changes " << h_output_changes << "\n" + << "\\html_math_output " << h_html_math_output << "\n" + << "\\html_css_as_file " << h_html_css_as_file << "\n" + << "\\html_be_strict " << h_html_be_strict << "\n" << "\\end_header\n\n" << "\\begin_body\n"; // clear preamble for subdocuments @@ -1018,11 +1052,8 @@ void parse_preamble(Parser & p, ostream & os, if (name == "\\parindent" && content != "") { if (content[0] == '0') h_paragraph_separation = "skip"; - else if (LYX_FORMAT >= 365) - h_paragraph_indentation = translate_len(content); else - h_preamble << "\\setlength{" << name - << "}{" << content << "}"; + h_paragraph_indentation = translate_len(content); } else if (name == "\\parskip") { if (content == "\\smallskipamount") h_defskip = "smallskip"; @@ -1085,8 +1116,7 @@ void parse_preamble(Parser & p, ostream & os, string const color = p.getArg('{', '}'); string const space = p.getArg('{', '}'); string const value = p.getArg('{', '}'); - if (LYX_FORMAT >= 382 && - color == "note_fontcolor" && space == "rgb") { + if (color == "note_fontcolor" && space == "rgb") { RGBColor c(RGBColorFromLaTeX(value)); h_notefontcolor = X11hexname(c); } else { diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 28eba8e722..a6a5cdfe3a 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -25,6 +25,7 @@ \usepackage{graphicx} \usepackage{longtable} \usepackage{xargs} +\usepackage{subscript} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands. \providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@} @@ -35,8 +36,6 @@ \newcommand{\lyxarrow}{\leavevmode\,$\triangleright$\,\allowbreak} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. -\usepackage{subscript} % user specified as long as tex2lyx -% produces a format less than 408 \def\mycommand{\textquestiondown} diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index f2bde2e8cb..83428b2d15 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -53,6 +53,7 @@ extern std::string babel2lyx(std::string const & language); extern std::map > used_packages; extern const char * const modules_placeholder; extern std::string h_inputencoding; +extern std::string h_paragraph_separation; /// in text.cpp std::string translate_len(std::string const &); @@ -165,7 +166,7 @@ extern bool noweb_mode; /// Did we recognize any pdflatex-only construct? extern bool pdflatex; /// LyX format that is created by tex2lyx -int const LYX_FORMAT = 345; +int const LYX_FORMAT = 413; /// path of the master .tex file extern std::string getMasterFilePath(); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 346922fc2c..ff644605df 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -109,6 +109,9 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer, char const * const known_ref_commands[] = { "ref", "pageref", "vref", "vpageref", "prettyref", "eqref", 0 }; +char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref", + "vpageref", "formatted", "eqref", 0 }; + /*! * natbib commands. * The starred forms are also known except for "citefullauthor", @@ -577,7 +580,7 @@ void output_command_layout(ostream & os, Parser & p, bool outer, p.next_token().character() != '[') break; p.get_token(); // eat '[' - begin_inset(os, "OptArg\n"); + begin_inset(os, "Argument\n"); os << "status collapsed\n\n"; parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context); end_inset(os); @@ -585,12 +588,12 @@ void output_command_layout(ostream & os, Parser & p, bool outer, ++optargs; } unsigned int reqargs = 0; - while (LYX_FORMAT >= 392 && reqargs < context.layout->reqargs) { + while (reqargs < context.layout->reqargs) { eat_whitespace(p, os, context, false); if (p.next_token().cat() != catBegin) break; p.get_token(); // eat '{' - begin_inset(os, "OptArg\n"); + begin_inset(os, "Argument\n"); os << "status collapsed\n\n"; parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context); end_inset(os); @@ -683,7 +686,7 @@ void parse_arguments(string const & command, break; case optional: // true because we must not eat whitespace - // if an optional arg follows me must not strip the + // if an optional arg follows we must not strip the // brackets from this one if (i < no_arguments - 1 && template_arguments[i+1] == optional) @@ -866,6 +869,7 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags, os << "has_inner_box " << !inner_type.empty() << "\n"; os << "inner_pos \"" << inner_pos << "\"\n"; os << "use_parbox " << (inner_type == "parbox") << '\n'; + os << "use_makebox 0\n"; os << "width \"" << width_value << width_unit << "\"\n"; os << "special \"none\"\n"; os << "height \"" << height_value << height_unit << "\"\n"; @@ -1201,6 +1205,49 @@ void parse_environment(Parser & p, ostream & os, bool outer, break; } context.check_deeper(os); + // handle known optional and required arguments + // layouts require all optional arguments before the required ones + // Unfortunately LyX can't handle arguments of list arguments (bug 7468): + // It is impossible to place anything after the environment name, + // but before the first \\item. + if (context.layout->latextype == LATEX_ENVIRONMENT) { + bool need_layout = true; + unsigned int optargs = 0; + while (optargs < context.layout->optargs) { + eat_whitespace(p, os, context, false); + if (p.next_token().cat() == catEscape || + p.next_token().character() != '[') + break; + p.get_token(); // eat '[' + if (need_layout) { + context.check_layout(os); + need_layout = false; + } + begin_inset(os, "Argument\n"); + os << "status collapsed\n\n"; + parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context); + end_inset(os); + eat_whitespace(p, os, context, false); + ++optargs; + } + unsigned int reqargs = 0; + while (reqargs < context.layout->reqargs) { + eat_whitespace(p, os, context, false); + if (p.next_token().cat() != catBegin) + break; + p.get_token(); // eat '{' + if (need_layout) { + context.check_layout(os); + need_layout = false; + } + begin_inset(os, "Argument\n"); + os << "status collapsed\n\n"; + parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context); + end_inset(os); + eat_whitespace(p, os, context, false); + ++reqargs; + } + } parse_text(p, os, FLAG_END, outer, context); context.check_end_layout(os); if (parent_context.deeper_paragraph) { @@ -1448,8 +1495,10 @@ void parse_noweb(Parser & p, ostream & os, Context & context) os << subst(t.asInput(), "\\", "\n\\backslash\n"); else { ostringstream oss; - begin_inset(oss, "Newline newline"); - end_inset(oss); + Context tmp(false, context.textclass, + &context.textclass[from_ascii("Scrap")]); + tmp.need_end_layout = true; + tmp.check_layout(oss); os << subst(t.asInput(), "\n", oss.str()); } // The scrap chunk is ended by an @ at the beginning of a line. @@ -2035,7 +2084,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, if (p.next_token().cat() != catEscape && p.next_token().character() == '[') { p.get_token(); // eat '[' - begin_inset(os, "OptArg\n"); + begin_inset(os, "Argument\n"); os << "status collapsed\n"; parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context); end_inset(os); @@ -2361,6 +2410,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (t.cs() == "underbar" || t.cs() == "uline") { + // \underbar is not 100% correct (LyX outputs \uline + // of ulem.sty). The difference is that \ulem allows + // line breaks, and \underbar does not. // Do NOT handle \underline. // \underbar cuts through y, g, q, p etc., // \underline does not. @@ -2380,8 +2432,30 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (t.cs() == "lyxline") { + // swallow size argument (it is not used anyway) + p.getArg('{', '}'); + if (!context.atParagraphStart()) { + // so our line is in the middle of a paragraph + // we need to add a new line, lest this line + // follow the other content on that line and + // run off the side of the page + // FIXME: This may create an empty paragraph, + // but without that it would not be + // possible to set noindent below. + // Fortunately LaTeX does not care + // about the empty paragraph. + context.new_paragraph(os); + } + if (h_paragraph_separation == "indent") { + // we need to unindent, lest the line be too long + context.add_par_extra_stuff("\\noindent\n"); + } context.check_layout(os); - os << "\\lyxline"; + begin_command_inset(os, "line", "rule"); + os << "offset \"0.5ex\"\n" + "width \"100line%\"\n" + "height \"1pt\"\n"; + end_inset(os); } else if (is_known(t.cs(), known_phrases) || @@ -2402,7 +2476,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string const opt = p.getOpt(); if (opt.empty()) { context.check_layout(os); - begin_command_inset(os, "ref", t.cs()); + char const * const * where = is_known(t.cs(), + known_ref_commands); + begin_command_inset(os, "ref", + known_coded_ref_commands[where - known_ref_commands]); os << "reference \"" << convert_command_inset_arg(p.verbatim_item()) << "\"\n"; @@ -2540,7 +2617,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "index") { context.check_layout(os); - begin_inset(os, "Index\n"); + begin_inset(os, "Index idx\n"); os << "status collapsed\n"; parse_text_in_inset(p, os, FLAG_ITEM, false, context, "Index"); end_inset(os); @@ -2572,6 +2649,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "printindex") { context.check_layout(os); begin_command_inset(os, "index_print", "printindex"); + os << "type \"idx\"\n"; end_inset(os); skip_spaces_braces(p); } @@ -2583,8 +2661,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, skip_spaces_braces(p); } - else if (LYX_FORMAT >= 408 && - (t.cs() == "textsuperscript" || t.cs() == "textsubscript")) { + else if ((t.cs() == "textsuperscript" || t.cs() == "textsubscript")) { context.check_layout(os); begin_inset(os, "script "); os << t.cs().substr(4) << '\n'; diff --git a/status.20x b/status.20x index b401b6f015..41b8b67e2e 100644 --- a/status.20x +++ b/status.20x @@ -33,6 +33,8 @@ What's new - XHTML export now respects font color and background color from Document->Settings->Colors. +- tex2lyx produces now the current file format 413. + * USER INTERFACE @@ -155,6 +157,10 @@ What's new - Allow the \nocite LaTeX command when using the basic citation engine. +- tex2lyx does not produce invalid Flex insets anymore (bug 7780) + +- Fix import of required arguments of standard environments (part of bug 7468) + * ADVANCED FIND AND REPLACE