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.
(cherry picked from commit f3c5bcd2be
)
This commit is contained in:
parent
ded23e1f9a
commit
f711e44bcf
@ -1111,7 +1111,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;
|
||||||
@ -1131,7 +1131,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
|
||||||
@ -1215,7 +1215,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):
|
||||||
@ -1263,7 +1263,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
|
||||||
@ -1279,7 +1279,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
|
||||||
|
|
||||||
|
@ -1170,7 +1170,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;
|
||||||
@ -1190,7 +1190,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
|
||||||
@ -1274,7 +1274,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):
|
||||||
@ -1322,7 +1322,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
|
||||||
@ -1338,7 +1338,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();
|
||||||
@ -4431,6 +4432,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4765,22 +4767,48 @@ 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() == "*")
|
||||||
name += p.get_token().asInput();
|
name += p.get_token().asInput();
|
||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
string lstparams;
|
string lstparams;
|
||||||
bool literal = false;
|
|
||||||
if (name == "lstinputlisting" && p.hasOpt()) {
|
if (name == "lstinputlisting" && p.hasOpt()) {
|
||||||
lstparams = p.getArg('[', ']');
|
lstparams = p.getArg('[', ']');
|
||||||
pair<bool, string> oa = convert_latexed_command_inset_arg(lstparams);
|
lstparams = subst(lstparams, "\n", " ");
|
||||||
literal = !oa.first;
|
} else if (name == "inputminted") {
|
||||||
if (literal)
|
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", " ");
|
lstparams = subst(lstparams, "\n", " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
string lit = literal ? "\"true\"" : "\"false\"";
|
|
||||||
string filename(normalize_filename(p.getArg('{', '}')));
|
string filename(normalize_filename(p.getArg('{', '}')));
|
||||||
string const path = getMasterFilePath(true);
|
string const path = getMasterFilePath(true);
|
||||||
// We want to preserve relative / absolute filenames,
|
// 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";
|
"filename \"" << outname << "\"\n";
|
||||||
if (!lstparams.empty())
|
if (!lstparams.empty())
|
||||||
os << "lstparams \"" << lstparams << "\"\n";
|
os << "lstparams \"" << lstparams << "\"\n";
|
||||||
os << "literal " << lit << "\n";
|
|
||||||
if (t.cs() == "verbatiminput")
|
if (t.cs() == "verbatiminput")
|
||||||
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ What's new
|
|||||||
|
|
||||||
- Add support for URW Classico, MinionPro and the new Libertine fonts.
|
- 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.
|
- Add support for the \t*{} (bottomtiebar) macro of TIPA.
|
||||||
|
|
||||||
- Implement better parsing of some command options (via "literate"
|
- Implement better parsing of some command options (via "literate"
|
||||||
|
Loading…
Reference in New Issue
Block a user