Author: uwestoehr
Date: Mon Mar  5 02:45:14 2012
New Revision: 40856
URL: http://www.lyx.org/trac/changeset/40856

Log:
- text.cpp: full tex2lyx support for lstlisting (support for \lstinline will 
follow soon)
- test/test-insets.tex: add a more advanced examples

Modified:
   lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
   lyx-devel/trunk/src/tex2lyx/text.cpp

Modified: lyx-devel/trunk/src/tex2lyx/test/test-insets.tex
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/test/test-insets.tex    Mon Mar  5 00:54:31 
2012        (r40855)
+++ lyx-devel/trunk/src/tex2lyx/test/test-insets.tex    Mon Mar  5 02:45:14 
2012        (r40856)
@@ -108,7 +108,7 @@
 \citet{gur+04} have demonstrated that authors should not have umlauts
 in their names. It's OK to use them in the man\"{u}script, though.
 \begin{thebibliography}{References}
-\bibitem[{{G\"{u}rkan et~al.}(2004)}]{gur+04} Gürkan, M.~A., Freitag,
+\bibitem[{{G\"{u}rkan et~al.}(2004)}]{gur+04} G�rkan, M.~A., Freitag,
 M., \& Rasio, F.~A. 2004, ApJ, 604, 632\end{thebibliography}
 
 
@@ -168,7 +168,6 @@
     pass
 \end{lstlisting}
 
-
 Here is an example listing with left line numbering, step ``3'',
 language ``Python'', options ``Extended character table'' and
 ``Space~as~symbol'', range lines 3\,-\,8:
@@ -178,7 +177,7 @@
     'this is a python function'
     pass
 def func(param):
-'This is a German word: Tschüß'
+'This is a German word: Tsch��'
 pass
 def func(param):
 'this is a python function'
@@ -186,10 +185,10 @@
 \end{lstlisting}
 
 Special cases:
-\begin{lstlisting}
-\begin{centering}
+\begin{lstlisting}[abovecaptionskip=2em,basicstyle={\large\ttfamily},breaklines=true,extendedchars=true,firstline=2,float=h,language={[R/3
 
3.1]ABAP},lastline=5,numbers=left,numberstyle={\scriptsize},showspaces=true,showstringspaces=false,stepnumber=3,tabsize=4]
 hello
 \end{lstlisting}
+
 \lstinline[language=TeX]!\begin{centering} hello!
 
 

Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp        Mon Mar  5 00:54:31 2012        
(r40855)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp        Mon Mar  5 02:45:14 2012        
(r40856)
@@ -1122,12 +1122,22 @@
 {
        parent_context.check_layout(os);
        begin_inset(os, "listings\n");
+       if (p.hasOpt()) {
+               // there can be a [] pair inside the argument for the language
+               string arg = p.getArg('[', ']');
+               if (arg.find("language={[") != string::npos) {
+                       char start = p.next_token().character();
+                       arg += ']';
+                       arg += start;
+                       arg += p.getArg(start, ']');
+               }
+               os << "lstparams " << '"' << arg << '"' << '\n';
+       }
        os << "inline false\n"
           << "status collapsed\n";
        Context context(true, parent_context.textclass);
        context.layout = &parent_context.textclass.plainLayout();
-       context.check_layout(os);
-       string const s = p.verbatimEnvironment("lstlisting");
+       string const s = p.plainEnvironment("lstlisting");
        for (string::const_iterator it = s.begin(), et = s.end(); it != et; 
++it) {
                if (*it == '\\')
                        os << "\n\\backslash\n";
@@ -1390,11 +1400,7 @@
                // FIXME handle listings with parameters
                //       If this is added, don't forgot to handle the
                //       automatic color package loading
-               if (p.hasOpt())
-                       parse_unknown_environment(p, name, os, FLAG_END,
-                                                 outer, parent_context);
-               else
-                       parse_listings(p, os, parent_context);
+               parse_listings(p, os, parent_context);
                p.skip_spaces();
        }
 

Reply via email to