tex2lyx: complete minted support (inputminted)

Also fix some whitespace issues in minted inset import.

(cherry picked from commit f3c5bcd2be)
This commit is contained in:
Juergen Spitzmueller 2018-03-17 16:44:09 +01:00
parent ded23e1f9a
commit f711e44bcf
5 changed files with 57 additions and 32 deletions

View 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

View 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

View 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
@ -302,7 +302,7 @@ noprefix "false"
\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):

View 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");
}

View 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"