mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
tex2lyx: complete minted support (inputminted)
Also fix some whitespace issues in minted inset import.
This commit is contained in:
parent
411f7b38e3
commit
f3c5bcd2be
@ -58,12 +58,6 @@ Format LaTeX feature LyX feature
|
|||||||
\begin{btUnit}...\end{btUnit} \multibib {none|part|chapter|section|subsection}
|
\begin{btUnit}...\end{btUnit} \multibib {none|part|chapter|section|subsection}
|
||||||
(if a part, chapter, section etc.
|
(if a part, chapter, section etc.
|
||||||
follows the \begin...)
|
follows the \begin...)
|
||||||
544 Minted support
|
|
||||||
\usepackage{minted} \use_minted
|
|
||||||
\begin{minted}{lang} \begin_inset listings
|
|
||||||
\end{minted}
|
|
||||||
\lyxmintcaption[]{caption\label{}} add to include inset
|
|
||||||
\inputminted{tex}{Intro.fls} \begin_inset include ...
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1118,7 +1118,7 @@ Inline:
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language={C++},keywordstyle={\color{green}}"
|
lstparams "language={C++},keywordstyle={\color{green}}"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
int a=5;
|
int a=5;
|
||||||
@ -1138,7 +1138,7 @@ int a=5;
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
|
lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
# Example listing float
|
# Example listing float
|
||||||
@ -1222,7 +1222,7 @@ symbol
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
|
lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
def func(param):
|
def func(param):
|
||||||
@ -1270,7 +1270,7 @@ Special cases:
|
|||||||
\begin_inset listings
|
\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"
|
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
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
hello
|
hello
|
||||||
@ -1286,7 +1286,7 @@ hello
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language=TeX"
|
lstparams "language=TeX"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
@ -1178,7 +1178,7 @@ Inline:
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language={C++},keywordstyle={\color{green}}"
|
lstparams "language={C++},keywordstyle={\color{green}}"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
int a=5;
|
int a=5;
|
||||||
@ -1198,7 +1198,7 @@ int a=5;
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
|
lstparams "caption={Example Listing float},label={lst:Example-Listing},language=Python"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
# Example listing float
|
# Example listing float
|
||||||
@ -1282,7 +1282,7 @@ symbol
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
|
lstparams "extendedchars=true,firstline=3,language=Python,lastline=8,numbers=left,showspaces=true,stepnumber=3"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
def func(param):
|
def func(param):
|
||||||
@ -1330,7 +1330,7 @@ Special cases:
|
|||||||
\begin_inset listings
|
\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"
|
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
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
hello
|
hello
|
||||||
@ -1346,7 +1346,7 @@ hello
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language=TeX"
|
lstparams "language=TeX"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ Inline:
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "style=bw,language=C++"
|
lstparams "style=bw,language=C++"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
int a=5;
|
int a=5;
|
||||||
@ -137,7 +137,7 @@ noprefix "false"
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language=Python,float=h"
|
lstparams "language=Python,float=h"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
# Example listing float
|
# Example listing float
|
||||||
@ -216,7 +216,7 @@ symbol
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "firstline=4,numbers=left,showspaces=true,language=Python"
|
lstparams "firstline=4,numbers=left,showspaces=true,language=Python"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
def func(param):
|
def func(param):
|
||||||
@ -252,7 +252,7 @@ A floating one-liner with [h] placement and without caption:
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "fontfamily=tt,fontsize={\large},bgcolor=lightgray,language=ABAP,float=h"
|
lstparams "fontfamily=tt,fontsize={\large},bgcolor=lightgray,language=ABAP,float=h"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
hello
|
hello
|
||||||
@ -269,7 +269,7 @@ Another inline listing:
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "language=TeX"
|
lstparams "language=TeX"
|
||||||
inline true
|
inline true
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
@ -298,11 +298,11 @@ noprefix "false"
|
|||||||
|
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
):
|
):
|
||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "numbers=left,frame=lines,language=C"
|
lstparams "numbers=left,frame=lines,language=C"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
@ -372,7 +372,7 @@ noprefix "false"
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "numbers=left,frame=lines,language=Fortran"
|
lstparams "numbers=left,frame=lines,language=Fortran"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
subroutine incr(i)
|
subroutine incr(i)
|
||||||
@ -417,10 +417,6 @@ A Fortran subroutine
|
|||||||
|
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
A framed floating listing with a caption and a label (Listing
|
A framed floating listing with a caption and a label (Listing
|
||||||
\begin_inset space ~
|
\begin_inset space ~
|
||||||
|
|
||||||
@ -440,7 +436,7 @@ noprefix "false"
|
|||||||
\begin_inset listings
|
\begin_inset listings
|
||||||
lstparams "frame=single,language=Python,float=h"
|
lstparams "frame=single,language=Python,float=h"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
def boring(args = None):
|
def boring(args = None):
|
||||||
@ -495,7 +491,7 @@ noprefix "false"
|
|||||||
): \begin_inset listings
|
): \begin_inset listings
|
||||||
lstparams "frame=single,language=Python,float=h"
|
lstparams "frame=single,language=Python,float=h"
|
||||||
inline false
|
inline false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
def boring(args = None):
|
def boring(args = None):
|
||||||
|
@ -1483,7 +1483,7 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context,
|
|||||||
os << "inline true\n";
|
os << "inline true\n";
|
||||||
else
|
else
|
||||||
os << "inline false\n";
|
os << "inline false\n";
|
||||||
os << "status collapsed\n";
|
os << "status open\n";
|
||||||
Context context(true, parent_context.textclass);
|
Context context(true, parent_context.textclass);
|
||||||
context.layout = &parent_context.textclass.plainLayout();
|
context.layout = &parent_context.textclass.plainLayout();
|
||||||
if (use_minted && prefixIs(minted_nonfloat_caption, "[t]")) {
|
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,
|
parse_text_snippet(p, FLAG_ITEM,
|
||||||
false, parent_context);
|
false, parent_context);
|
||||||
minted_nonfloat_caption = "[b]" + caption;
|
minted_nonfloat_caption = "[b]" + caption;
|
||||||
|
eat_whitespace(p, os, parent_context, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.popPosition();
|
p.popPosition();
|
||||||
@ -4450,6 +4451,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
// so simply skip it.
|
// so simply skip it.
|
||||||
parse_text_snippet(p, FLAG_ITEM, false, context);
|
parse_text_snippet(p, FLAG_ITEM, false, context);
|
||||||
}
|
}
|
||||||
|
eat_whitespace(p, os, context, true);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4784,7 +4786,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
|
|
||||||
if (t.cs() == "input" || t.cs() == "include"
|
if (t.cs() == "input" || t.cs() == "include"
|
||||||
|| t.cs() == "verbatiminput"
|
|| t.cs() == "verbatiminput"
|
||||||
|| t.cs() == "lstinputlisting") {
|
|| t.cs() == "lstinputlisting"
|
||||||
|
|| t.cs() == "inputminted") {
|
||||||
string name = t.cs();
|
string name = t.cs();
|
||||||
if (name == "verbatiminput"
|
if (name == "verbatiminput"
|
||||||
&& p.next_token().asInput() == "*")
|
&& p.next_token().asInput() == "*")
|
||||||
@ -4798,6 +4801,39 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
literal = !oa.first;
|
literal = !oa.first;
|
||||||
if (literal)
|
if (literal)
|
||||||
lstparams = subst(lstparams, "\n", " ");
|
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;
|
||||||
|
pair<bool, string> oa = convert_latexed_command_inset_arg(lstparams);
|
||||||
|
literal = !oa.first;
|
||||||
|
if (literal)
|
||||||
|
lstparams = subst(lstparams, "\n", " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
string lit = literal ? "\"true\"" : "\"false\"";
|
string lit = literal ? "\"true\"" : "\"false\"";
|
||||||
string filename(normalize_filename(p.getArg('{', '}')));
|
string filename(normalize_filename(p.getArg('{', '}')));
|
||||||
|
Loading…
Reference in New Issue
Block a user