]> git.lyx.org Git - features.git/commitdiff
tex2lyx: complete minted support (inputminted)
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 17 Mar 2018 15:44:09 +0000 (16:44 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 17 Mar 2018 17:16:46 +0000 (18:16 +0100)
Also fix some whitespace issues in minted inset import.

(cherry picked from commit f3c5bcd2be4edc37dec4c78422f31e07b322b298)

src/tex2lyx/test/test-insets-basic.lyx.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-minted.lyx.lyx
src/tex2lyx/text.cpp
status.23x

index 9b2ea80b1f3bd85c8bcf39be2d4bfddaf4097160..540c80c5d6128c06224268e2a4429c57a04119a9 100644 (file)
@@ -1111,7 +1111,7 @@ Inline:
 \begin_inset listings
 lstparams "language={C++},keywordstyle={\color{green}}"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -1131,7 +1131,7 @@ int a=5;
 \begin_inset listings
 lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -1215,7 +1215,7 @@ symbol
 \begin_inset listings
 lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -1263,7 +1263,7 @@ Special cases:
 \begin_inset listings
 lstparams "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"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -1279,7 +1279,7 @@ hello
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
index 8af5bcdbced960f07e0bcdff357ed6df9c80681d..cebb68e2d9d6cf543f655e491065469514b1c00f 100644 (file)
@@ -1170,7 +1170,7 @@ Inline:
 \begin_inset listings
 lstparams "language={C++},keywordstyle={\color{green}}"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -1190,7 +1190,7 @@ int a=5;
 \begin_inset listings
 lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -1274,7 +1274,7 @@ symbol
 \begin_inset listings
 lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -1322,7 +1322,7 @@ Special cases:
 \begin_inset listings
 lstparams "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"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -1338,7 +1338,7 @@ hello
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
index 0af108d2d3c5fbbad7671afc480b91bfd356b681..426902b5bc0afb0c484df1b599201b031c1a3ea9 100644 (file)
@@ -102,7 +102,7 @@ Inline:
 \begin_inset listings
 lstparams "style=bw,language=C++"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 int a=5;
@@ -137,7 +137,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 # Example listing float
@@ -216,7 +216,7 @@ symbol
 \begin_inset listings
 lstparams "firstline=4,numbers=left,showspaces=true,language=Python"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def func(param):
@@ -252,7 +252,7 @@ A floating one-liner with [h] placement and without caption:
 \begin_inset listings
 lstparams "fontfamily=tt,fontsize={\large},bgcolor=lightgray,language=ABAP,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 hello
@@ -269,7 +269,7 @@ Another inline listing:
 \begin_inset listings
 lstparams "language=TeX"
 inline true
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
@@ -298,11 +298,11 @@ noprefix "false"
 
 \end_inset
 
-):  
+): 
 \begin_inset listings
 lstparams "numbers=left,frame=lines,language=C"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 
@@ -372,7 +372,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "numbers=left,frame=lines,language=Fortran"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 subroutine incr(i)
@@ -417,10 +417,6 @@ A Fortran subroutine
 
 \end_inset
 
-
-\end_layout
-
-\begin_layout Standard
 A framed floating listing with a caption and a label (Listing
 \begin_inset space ~
 
@@ -440,7 +436,7 @@ noprefix "false"
 \begin_inset listings
 lstparams "frame=single,language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def boring(args = None):
@@ -495,7 +491,7 @@ noprefix "false"
 ): \begin_inset listings
 lstparams "frame=single,language=Python,float=h"
 inline false
-status collapsed
+status open
 
 \begin_layout Plain Layout
 def boring(args = None):
index 1bee520b0ed8c730d8dc717ef43374f749dc15e5..333bdd61be383768b29438f962c28612ba35b43e 100644 (file)
@@ -1483,7 +1483,7 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context,
                os << "inline true\n";
        else
                os << "inline false\n";
-       os << "status collapsed\n";
+       os << "status open\n";
        Context context(true, parent_context.textclass);
        context.layout = &parent_context.textclass.plainLayout();
        if (use_minted && prefixIs(minted_nonfloat_caption, "[t]")) {
@@ -2001,6 +2001,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                                                parse_text_snippet(p, FLAG_ITEM,
                                                        false, parent_context);
                                        minted_nonfloat_caption = "[b]" + caption;
+                                       eat_whitespace(p, os, parent_context, true);
                                }
                        }
                        p.popPosition();
@@ -4431,6 +4432,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                // so simply skip it.
                                parse_text_snippet(p, FLAG_ITEM, false, context);
                        }
+                       eat_whitespace(p, os, context, true);
                        continue;
                }
 
@@ -4765,22 +4767,48 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                if (t.cs() == "input" || t.cs() == "include"
                    || t.cs() == "verbatiminput"
-                   || t.cs() == "lstinputlisting") {
+                   || t.cs() == "lstinputlisting"
+                   || t.cs() == "inputminted") {
                        string name = t.cs();
                        if (name == "verbatiminput"
                            && p.next_token().asInput() == "*")
                                name += p.get_token().asInput();
                        context.check_layout(os);
                        string lstparams;
-                       bool literal = false;
                        if (name == "lstinputlisting" && p.hasOpt()) {
                                lstparams = p.getArg('[', ']');
-                               pair<bool, string> oa = convert_latexed_command_inset_arg(lstparams);
-                               literal = !oa.first;
-                               if (literal)
+                               lstparams = subst(lstparams, "\n", " ");
+                       } else if (name == "inputminted") {
+                               name = "lstinputlisting";
+                               string const lang = p.getArg('{', '}');
+                               if (lang != "tex") {
+                                       string cmd = "\\inputminted{" + lang + "}{";
+                                       cmd += p.getArg('{', '}') + "}";
+                                       output_ert_inset(os, cmd, context);
+                                       continue;
+                               }
+                               if (prefixIs(minted_nonfloat_caption, "[t]")) {
+                                       minted_nonfloat_caption.erase(0,3);
+                                       // extract label and caption from the already produced LyX code
+                                       vector<string> nfc = getVectorFromString(minted_nonfloat_caption, "\n");
+                                       string const caption = nfc.front();
+                                       string label;
+                                       vector<string>::iterator it =
+                                               find(nfc.begin(), nfc.end(), "LatexCommand label");
+                                       if (it != nfc.end()) {
+                                               ++it;
+                                               if (it != nfc.end())
+                                                       label = *it;
+                                               label = support::split(label, '"');
+                                               label.pop_back();
+                                       }
+                                       minted_nonfloat_caption.clear();
+                                       lstparams = "caption=" + caption;
+                                       if (!label.empty())
+                                               lstparams += ",label=" + label;
                                        lstparams = subst(lstparams, "\n", " ");
+                               }
                        }
-                       string lit = literal ? "\"true\"" : "\"false\"";
                        string filename(normalize_filename(p.getArg('{', '}')));
                        string const path = getMasterFilePath(true);
                        // We want to preserve relative / absolute filenames,
@@ -4890,7 +4918,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                      "filename \"" << outname << "\"\n";
                                if (!lstparams.empty())
                                        os << "lstparams \"" << lstparams << "\"\n";
-                               os << "literal " << lit << "\n";
                                if (t.cs() == "verbatiminput")
                                        preamble.registerAutomaticallyLoadedPackage("verbatim");
                        }
index b0fa2fdf587cda6e833610e9438673de9cb62ef5..59ef0bf92157c1c40c706499e9b3df298dfeeba1 100644 (file)
@@ -39,6 +39,8 @@ What's new
 
 - Add support for URW Classico, MinionPro and the new Libertine fonts.
 
+- Add support for \lstinputlisting and \inputminted.
+
 - Add support for the \t*{} (bottomtiebar) macro of TIPA.
 
 - Implement better parsing of some command options (via "literate"