Changeset 27596

Show
Ignore:
Timestamp:
11/17/08 00:24:56 (2 months ago)
Author:
lasgouttes
Message:

Now tex2lyx is able to parse stuff that is in unicodesymbols file, as well
as accents. Time will tell how robust this is.

All support for InsetLatexAccent? has been removed.

I did not do the support for \inputencoding yet, because it is more difficult
to get right...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lyx-devel/trunk/src/tex2lyx/test/test.ltx

    r27442 r27596  
    7676\end{tabular} 
    7777 
     78Let's try a few unicode characters: the (R) symbol \textregistered 
     79(and the same one with braces \textregistered{} and a space after) or 
     80maybe an accented a \'{a} or this one \'a or this \^\i. 
     81 
     82Watch out: \textregistered should be glued to its successor here. 
     83 
    7884Final Text. 
    7985\end{document} 
  • lyx-devel/trunk/src/tex2lyx/text.cpp

    r27592 r27596  
    1818 
    1919#include "Context.h" 
     20#include "Encoding.h" 
    2021#include "FloatList.h" 
    2122#include "Layout.h" 
     
    22402241                } 
    22412242 
    2242 #if 0 
    2243 //FIXME: rewrite this 
    2244                 else if (t.cs() == "\"") { 
    2245                         context.check_layout(os); 
    2246                         string const name = p.verbatim_item(); 
    2247                              if (name == "a") os << '\xe4'; 
    2248                         else if (name == "o") os << '\xf6'; 
    2249                         else if (name == "u") os << '\xfc'; 
    2250                         else if (name == "A") os << '\xc4'; 
    2251                         else if (name == "O") os << '\xd6'; 
    2252                         else if (name == "U") os << '\xdc'; 
    2253                         else handle_ert(os, "\"{" + name + "}", context); 
    2254                 } 
    2255 #endif 
    2256  
    22572243                // Problem: \= creates a tabstop inside the tabbing environment 
    22582244                // and else an accent. In the latter case we really would want 
     
    22652251                         || t.cs() == "~" || t.cs() == "." || t.cs() == "=") { 
    22662252                        // we need the trim as the LyX parser chokes on such spaces 
    2267                         // The argument of InsetLatexAccent is parsed as a 
    2268                         // subset of LaTeX, so don't parse anything here, 
    2269                         // but use the raw argument. 
    2270                         // Otherwise we would convert \~{\i} wrongly. 
    2271                         // This will of course not translate \~{\ss} to \~{ß}, 
    2272                         // but that does at least compile and does only look 
    2273                         // strange on screen. 
    2274                         context.check_layout(os); 
    2275                         os << "\\i \\" << t.cs() << "{" 
    2276                            << trim(p.verbatim_item(), " ") 
    2277                            << "}\n"; 
    2278                 } 
    2279  
    2280 #if 0 
    2281 //FIXME: rewrite this 
    2282                 else if (t.cs() == "ss") { 
    2283                         context.check_layout(os); 
    2284                         os << "\xdf"; 
    2285                         skip_braces(p); // eat {} 
    2286                 } 
    2287 #endif 
    2288  
    2289                 else if (t.cs() == "i" || t.cs() == "j" || t.cs() == "l" || 
    2290                          t.cs() == "L") { 
    2291                         context.check_layout(os); 
    2292                         os << "\\i \\" << t.cs() << "{}\n"; 
    2293                         skip_braces(p); // eat {} 
     2253                        context.check_layout(os); 
     2254                        // try to see whether the string is in unicodesymbols 
     2255                        docstring rem; 
     2256                        string command = t.asInput() + "{"  
     2257                                + trim(p.verbatim_item()) 
     2258                                + "}"; 
     2259                        docstring s = encodings.fromLaTeXCommand(from_utf8(command), rem); 
     2260                        if (!s.empty()) { 
     2261                                if (!rem.empty()) 
     2262                                        cerr << "When parsing " << command  
     2263                                             << ", result is " << to_utf8(s) 
     2264                                             << "+" << to_utf8(rem) << endl; 
     2265                                os << to_utf8(s); 
     2266                        } else 
     2267                                // we did not find a non-ert version 
     2268                                handle_ert(os, command, context); 
    22942269                } 
    22952270 
     
    25452520 
    25462521                else { 
     2522                        // try to see whether the string is in unicodesymbols 
     2523                        docstring rem; 
     2524                        docstring s = encodings.fromLaTeXCommand(from_utf8(t.asInput()), rem); 
     2525                        if (!s.empty()) { 
     2526                                if (!rem.empty()) 
     2527                                        cerr << "When parsing " << t.cs()  
     2528                                             << ", result is " << to_utf8(s) 
     2529                                             << "+" << to_utf8(rem) << endl; 
     2530                                context.check_layout(os); 
     2531                                os << to_utf8(s); 
     2532                                skip_braces(p); // eat {} 
     2533                        } 
    25472534                        //cerr << "#: " << t << " mode: " << mode << endl; 
    25482535                        // heuristic: read up to next non-nested space 
     
    25582545                        handle_ert(os, s + ' ', context); 
    25592546                        */ 
    2560                         string name = t.asInput(); 
    2561                         if (p.next_token().asInput() == "*") { 
    2562                                 // Starred commands like \vspace*{} 
    2563                                 p.get_token();                          // Eat '*' 
    2564                                 name += '*'; 
    2565                         } 
    2566                         if (! parse_command(name, p, os, outer, context)) 
    2567                                 handle_ert(os, name, context); 
     2547                        else { 
     2548                                string name = t.asInput(); 
     2549                                if (p.next_token().asInput() == "*") { 
     2550                                        // Starred commands like \vspace*{} 
     2551                                        p.get_token();  // Eat '*' 
     2552                                        name += '*'; 
     2553                                } 
     2554                                if (!parse_command(name, p, os, outer, context)) 
     2555                                        handle_ert(os, name, context); 
     2556                        } 
    25682557                } 
    25692558